How can I use a Python script in the command line without cd-ing to its directory? Is it the PYTHONPATH?

后端 未结 5 1350
后悔当初
后悔当初 2020-11-22 11:20

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 go

5条回答
  •  庸人自扰
    2020-11-22 11:51

    With PYTHONPATH set as in your example, you should be able to do

    python -m gmbx
    

    -m option will make Python search for your module in paths Python usually searches modules in, including what you added to PYTHONPATH. When you run interpreter like python gmbx.py, it looks for particular file and PYTHONPATH does not apply.

提交回复
热议问题