I am struggling with the setup of the python3 environment to be able to run python programs located in different locations (working directories). I want to be able to do two things:
I’d like to be able to run python programs located in /home/klaus/Programme/pythonfiles without typing the entire path all the time like: python3 /home/klaus/Programme/pythonfiles/test1.py
I set the PYTHONPATH using: export PYTHONPATH=“/home/klaus/Programme/pythonfiles”
and echo $PYTHONPATH shows:
But I am not able to run a python program located in this directory?! The additional working directory is not recognized.
python3: can’t open file ‘/home/klaus/test1.py’: [Errno 2] No such file or directory
I installed the IDLE 3 programming environment but again, I am not able to add a working directory to the path - nothing new shows up in the path browser
How can I add a python working directory to the python environment?
What is PYTHONPATH environment variable in Python writes:
In Python, PYTHONPATH is an environment variable that specifies a list of directories to search for Python modules when importing them. When you import a module in Python, Python looks for the module in the directories specified in sys.path, which is a list of directories that includes the current working directory and directories specified in PYTHONPATH.
So no, the python does not seek files from PYTHONPATH.
If the current working directory (the thing returned by
/home/klaus/Programme/pythonfiles, then you can use either of:
You could create an environment variable (that is quicker to type):
If you append the location to PATH, make the test1.py executable, and have the shebang
#!/usr/bin/env python3 as its first line, then you can simply:
I don’t use programming environments (unless you count GNU Emacs).