[英]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脚本,但我收到了错误
$ 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. 我可以在Python的导入它,因为我已经添加了目录到PYTHONPATH,并且工作正常,但我必须指定目录得到它在命令行中运行,即使which
可以找到它。
EDIT: emacs can't find it either... 编辑:emacs找不到它...
I don't think you need to say python in the command line. 我不认为你需要在命令行中说python。 If you chmod +x it and it is in your path, You should be able to just call it like 如果你chmod + x它并且它在你的路径中,你应该能够像它一样调用它
$ pscan2.py $ 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. 我不知道cygwin的细节,但是如果你有shebang行,它会自动将它作为python脚本运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.