简体   繁体   中英

Python can't find script in directory added to path [Cygwin]

I'm trying to run a Python script from the command line, but I'm getting the error

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

However, I also have

$ which pscan2.py
/usr/bin/pscan2.py

and

$ echo $PATH
/usr/lib/:/usr/local/bin:/usr/bin:/cygdrive/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/MinGW64/bin:/cygdrive/c/Dwimperl/perl/bin:/cygdrive/c/Dwimperl/perl/site/bin:/cygdrive/c/Dwimperl/c/bin:/cygdrive/c/python27: C:/python25:/usr/lib/lapack:/usr/openwin/bin

I can import it within Python, since I've added the directory to the PYTHONPATH, and that works fine, but I have to specify the directory to get it to run at the command line, even though which can find it.

EDIT: emacs can't find it either...

I don't think you need to say python in the command line. If you chmod +x it and it is in your path, You should be able to just call it like

$ pscan2.py

and it should work. I don't know the specifics of cygwin but if you have the shebang line, it will automatically run it as a python script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM