Python Forum
Interpreter does not consider PYTHONPATH environment variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interpreter does not consider PYTHONPATH environment variable
#1
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.
Reply
#2
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.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PythonPath file JohnRLaw 7 21,837 Jul-04-2025, 10:56 PM
Last Post: Pedroski55
  How to set PYTHONPATH in Visual Studio Code? aupres 5 20,426 Aug-15-2023, 03:51 PM
Last Post: snippsat
  the exe file by generated by pyinstaller ,can't get the PYTHONPATH roger2020 11 12,095 Jan-14-2020, 11:07 AM
Last Post: roger2020
  TESSDATA_PREFIX environment variable is set to your "tessdata" directory. rajeev1729 1 6,344 Jun-10-2019, 04:47 PM
Last Post: Gribouillis
  setting pythonpath variable in environment variables saisankalpj 3 5,197 Dec-05-2018, 10:33 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020