Mitchell van Zuylen Mitchell van Zuylen - 8 months ago 52
Python Question is added to PYTHONPATH, but can't be found

In my, apparently faulty, understanding of PYTHONPATH, calling

returns the contents of PYTHONPATH. Using the windows GUI, I added a script, from Django- to it.

>>> import sys
>>> sys.path
['', 'C:\\programming\\django_testing\\tango_with_django_project\\', 'C:\\Users\\mjpvanzuijlen\\AppData\\Local\\Programs\\Python\\Python36', ]

I though this would allow me to call it in CMD from whatever directory using:


Yet, this returns an error:

python: can't open file '': [Errno 2] No such file or directory.

Clearly my understanding of PYTHONPATH is wrong. How would I be able to call a file, in this case
from any location in CMD?

I changed the path from
to the directory. It still returns the same error.

>>> import sys
>>> sys.path
['', 'C:\\programming\\django_testing\\tango_with_django_project',

Answer Source

How would I be able to call [..] from any location in CMD?

You can't. needs to be called from the directory where it's located. It wouldn't make sense otherwise, as files exist for each django project, which would easily go wrong.

This is also true in the general case: You can't call a .py file from outside the directory. Only modules can be called this way.

Information mostly from Klaus D. in the comments.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download