Set CLASSPATH for python

16,491

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
Share:
16,491

Related videos on Youtube

user160446
Author by

user160446

Updated on September 18, 2022

Comments

  • user160446
    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 write cd pythonEX and then python ex1.py. I'm wondering whether it's possible to just write python ex1.py, meaning skipping the cd 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