Python Forum

Full Version: Interpreter does not consider PYTHONPATH environment variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I have a problem executing scripts because the environment variable PYTHONPATH is not recognized.
I have downloaded the minimal python x64 embeddable zip and extracted it into a directory. This is the output of sys.path without set PYTHONPATH in the shell.
C:\Development\python-3.6.2-embed-amd64>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
>>> import sys
>>> print(sys.path)
['C:\\Development\\python-3.6.2-embed-amd64\\python36.zip', 'C:\\Development\\python-3.6.2-embed-amd64']
>>> sys.exit()
Then I set the variable PYTHONPATH
C:\Development\python-3.6.2-embed-amd64>SET PYTHONPATH=C:\Development\test

C:\Development\python-3.6.2-embed-amd64>echo %PYTHONPATH%
C:\Development\test
Now the output of sys.path should contain the directory C:\Development\test but...
C:\Development\python-3.6.2-embed-amd64>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
>>> import sys
>>> print(sys.path)
['C:\\Development\\python-3.6.2-embed-amd64\\python36.zip', 'C:\\Development\\python-3.6.2-embed-amd64']
Why PYTHONPATH is not recognized by the interpreter?

Thank you.
I'm also on windows, and PYTHONPATH isn't even set by the installer.
E:\>echo %PYTHONPATH%
%PYTHONPATH%
However, when I import sys; print(sys.path), I get a massive list of things (dlls, site-packages, the current directory, etc).  But if I echo %PATH%, there's even more things (java nonsense, asp.net, visual studio, etc), most of which are not included from python's import sys; print(sys.path).

When I do as you did, and set PYTHONPATH, then start the interpreter and print the path, I see what I set the pythonpath to prepended to everything else.  Did you set the pythonpath in the same console window?  set PYTHONPATH = {some value} won't set it for all sessions, only for that particular window.
Hi nilamo,
thank you for the answer.
What I wrote has been made obviously in the same console window. Did you make the test with the package python amd64 embedded?

I did not use the installer, so the PYTHONPATH variable is not set at system level (by the installer), but I set the variable with the set command before launch the python interpreter.