Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Python by (47.6k points)

How can I make any use of PYTHONPATH? When I try to run a script in the path the file is not found. When I cd to the directory holding the script the script runs. So what good is the PYTHONPATH?

$ echo $PYTHONPATH 

:/home/randy/lib/python 

$ tree -L 1 '/home/randy/lib/python' 

/home/randy/lib/python 

├── gbmx_html.py 

├── gbmx.py 

├── __init__.py 

├── __pycache__ 

├── scripts 

└── yesno.py 

$ python gbmx.py -h 

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

$ cd '/home/randy/lib/python'

After cd to the file directory, it runs.

$ python gbmx.py -h 

usage: gbmx.py [-h] [-b]

Why can I not make any use of the PYTHONPATH?

1 Answer

0 votes
by (106k points)

You're confusing PATH and PYTHONPATH. You need to run the following commands:-

export PATH=$PATH:/home/randy/lib/python

PYTHONPATH is used by the python interpreter to determine which modules to load.

PATH is used by the shell to determine which executables to run.

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
0 votes
1 answer
asked Oct 18, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...