bash:python:.py:找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47443988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:37:26  来源:igfitidea点击:

bash: python: .py: command not found

pythonbashqiime

提问by Muhammad Arslan

I am trying to run the following command in QIIME2 virtual machine, installed on macbook but the code is not working

我正在尝试QIIME2 virtual machine在 macbook 上运行以下命令,但代码不起作用

validate_mapping_file.py -m Fasting_Map.txt -o mapping_output

Here is the link: http://qiime.org/tutorials/tutorial.html

这是链接:http: //qiime.org/tutorials/tutorial.html

I get the following message

我收到以下消息

bash: validate_mapping_file.py: command not found

bash:validate_mapping_file.py:找不到命令

I am new to unix/linuxas well as on qiime. I would be very thankful for the help...

unix/linuxqiime. 我将非常感谢您的帮助...

回答by Florian Rhiem

To execute a Python script in this way, you need three things:

要以这种方式执行 Python 脚本,您需要三样东西:

  1. The file needs to have the executable bit set for you. To do this, try using: chmod u+x validate_mapping_file.py

  2. The file needs to begin with a shebang, for example #!/usr/bin/env python3which will tell the system to run the script using the python3 executable according to your environment

  3. The file needs to be in one of the directories in your PATHenvironment variable. You can add the current directory using export PATH=$PWD:$PATHor use ./validate_mapping_file.pyinstead of just validate_mapping_file.py(thanks @Grisha)

  1. 该文件需要为您设置可执行位。为此,请尝试使用:chmod u+x validate_mapping_file.py

  2. 该文件需要以shebang开头,例如#!/usr/bin/env python3,它会告诉系统根据您的环境使用python3可执行文件运行脚本

  3. 该文件需要位于您的PATH环境变量中的目录之一中。您可以使用 exportPATH=$PWD:$PATH或 use./validate_mapping_file.py而不是添加当前目录validate_mapping_file.py(感谢@Grisha)

Afterwards you should be able to execute the script the way you tried before.

之后,您应该能够按照之前尝试的方式执行脚本。