简体   繁体   English

Python无法在添加到路径[Cygwin]的目录中找到脚本

[英]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.

相关问题 python 虽然添加到路径中,但在环境变量路径中找不到? - Can't find python in Environment variables path although it is added to path? Python脚本找不到路径 - Python script can't find path Bash 脚本 - Python 找不到路径 - Bash Script - Python can't find a path 我将脚本路径添加到 python 和 Pycharm 说目录中没有 python - I added script path to python and Pycharm says there is no python at the directory 我的 Python 脚本在同一目录下找不到 JSON 文件 - My Python Script can't find a JSON file in the same directory 系统找不到 python.exe,即使它已添加到路径 - System can't find python.exe even though it's added to path Bash在脚本中找不到正确的目录 - Bash can't find right directory in script 即使目录包含在 PATH 中,也无法在不更改目录的情况下从终端运行 Python 脚本 - Can't run Python script from Terminal without changing directories even though directory is included in PATH 当父目录位于 sys.path 中时,Python 无法始终找到模块 - Python can't consistently find a module while the parent directory is in sys.path 将目录添加到 Python 脚本内的 PATH 中,以便第三方模块可以使用 ctypes find_library 找到 DLL - Add directory to PATH inside a Python script such that a third-party module can find a DLL with ctypes find_library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM