简体   繁体   English

执行python文件-没有这样的文件或目录

[英]execute python file- No such file or directory

I try to execute python file through the terminal with ssh (the file itself is not in my computer). 我尝试通过ssh通过终端执行python文件(文件本身不在我的计算机中)。

I do the following: 我执行以下操作:

./playg.py

and I get: ": No such file or directory" 我得到:“:没有这样的文件或目录”

I am in the right directory for sure (when I write cat playg.py I can see the content of the file| 我肯定在正确的目录中(当我写cat playg.py我可以看到文件的内容|

The file has the r/w/x properties: -r-xr-xr-x 该文件具有r / w / x属性:-r-xr-xr-x

First go to playg.py existing folder. 首先转到playg.py现有文件夹。

Then type python playg.py 然后输入python playg.py

You can execute it with python playg.py. 您可以使用python playg.py执行它。

The reason you might not be able to execute it with ./playg.py is the first line of the script. 您可能无法使用./playg.py执行它的原因是脚本的第一行。

#!/usr/bin/python 

or similar in the first line might not be appropriate for the system. 第一行中的类似内容可能不适用于该系统。

#!/usr/bin/env python

would look for the python executable in the current environment and is more flexible. 会在当前环境中查找python可执行文件,并且更加灵活。

check for endline characters encoding. 检查终端字符编码。 if you have cr-lf encoding instead of lf it gives that error... 如果您使用cr-lf编码而不是lf,则会出现该错误...

转到包含文件的目录并运行:

python play.py

尝试执行时,请尝试在文件名之前添加python

    python playg.py

python /path/to/file/playg.py应该可以工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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