[英]How to execute a Python3 script from Bash, in the shorthand fashion?
I'm converting all my Python2 scripts to work with Python3. 我正在将所有Python2脚本转换为可与Python3一起使用。
From within a bash wrapper, scripts can be executed with Python3 with: 在bash包装器中,可以使用Python3使用以下命令执行脚本:
python3 myScript.py
However, I have an old wrapper which called a Python2 script via the shorthand, ie 但是,我有一个旧的包装器,该包装器通过速记方式称为Python2脚本,即
./myScript.py
How do I ensure that this shorthand will run the script with Python3 by default? 如何确保该速记默认情况下将使用Python3运行脚本?
The server these scripts are running on is Ubuntu 14.04. 这些脚本在其上运行的服务器是Ubuntu 14.04。
您可以使用“ hash-bang” #!/usr/bin/python3
more information regarding your operating system would be helpful. 有关您的操作系统的更多信息将很有帮助。 If you are on linux or mac you can add the following to the first line of your script: 如果您使用的是Linux或Mac,则可以将以下内容添加到脚本的第一行:
#!/usr/local/bin/python #!/ usr / local / bin / python
adjusting for the location of your python3. 调整python3的位置。 Then you could change the file to executable using: 然后您可以使用以下命令将文件更改为可执行文件:
chmod u+x script chmod u + x脚本
After this you would be able to run your script with just 在此之后,您将可以使用以下命令运行脚本
script 脚本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.