5

I use windows 7 without admin rights and i would like to use python3. Even if i set PYTHONPATH, environment variable is ignored. However PYTHONPATH is valid when printed.

>>> print(sys.path)
['c:\\Python365\\python36.zip', 'c:\\Python365']
>>> print(os.environ["PYTHONPATH"])
d:\libs

any idea ?

thank you very much

Gil

Gilles
  • 49
  • 7
  • How did you install? It looks like you may be using the embedded distribution, with the standard library in a zip file. Make sure Python is installed correctly using the executable installer, e.g. [python-3.6.5-amd64.exe](https://www.python.org/ftp/python/3.6.5/python-3.6.5-amd64.exe). – Eryk Sun May 02 '18 at 06:11
  • yes you right, but why this version does not care for PYTHONPATH ? I'll try to use executable installer. – Gilles May 03 '18 at 06:40
  • The embedded distribution is meant for Python applications or applications that include scripting support via Python. `PYTHONPATH` is meant for a system Python or development installations, but it should not affect applications that embed Python, which need independent control of Python's search path. – Eryk Sun May 03 '18 at 11:27
  • Ok that works with executable installer. Thank you eryksun – Gilles May 11 '18 at 07:07

2 Answers2

2

When using the embedded distribution (.zip file), then the PYTHONPATH environment variable is not respected. If this behavior is needed, then one needs to add some Python code that load the setting it from os.environ.get('PYTHONPATH', '') split the directories and add them to sys.path.

Also note that pip is not supported with the embedded distribution, but can be made to work.

Alternatively one uses the installers instead of the embedded distribution.

Jon Nordby
  • 5,494
  • 1
  • 21
  • 50
0

Add the contents of PYTHONPATH to python._pth in the root folder one entry per line.

Konstantin Glukhov
  • 1,898
  • 3
  • 18
  • 25