Set CLASSPATH for python
I use PYTHONPATH:
PYTHONPATH=/user_name/pythonEx
export PYTHONPATH
python -m ex1
CLASSPATH is, as far as I know, a Java path. PATH is a bash path. So, you can also make ex1.py executable, then you can run
PATH=/user_name/pythonEx:$PATH
ex1.py
Related videos on Youtube
user160446
Updated on September 18, 2022Comments
-
user160446 over 1 year
I want to execute a python file called
ex1.py
. The execution works fine, the program does, what it ought to do.The problem is the following: This file is stored in the folder
/user_name/pythonEx
. So, everytime I want to execute this file I have to writecd pythonEX
and thenpython ex1.py
. I'm wondering whether it's possible to just writepython ex1.py
, meaning skipping thecd pythonEx
line.I tried to write to open the ".bashrc" file and write
export CLASSPATH=/user_name/pythonEx
and save it. I restart the terminal yet an error message appears saying
python: can't open file 'ex1.py': [Error 2] No such file or directory
Could someone please tell me how to execute a file by just typing in the terminal
python [file-name].py
?Thanks in advance.
Best regards