简体   繁体   English

如何使用特定的解释器运行 python 脚本?

[英]How do I run a python script using a specific interpreter?

I'm having problems with pygame as documented here: PyGame bogging down linux?我在使用pygame时遇到问题,如此处所述:

After a bit of searching around and brainstorming I realized it may be because I'm using python2.7 instead of 2.6 which PyGame was designed for.经过一番搜索和头脑风暴,我意识到这可能是因为我使用的是 python2.7 而不是 PyGame 设计的 2.6。

How do I run my script using the 2.6 interpreter instead of 2.7 (which seems to be the default).如何使用 2.6 解释器而不是 2.7(这似乎是默认值)运行我的脚本。

Thanks谢谢

OS - Ubuntu操作系统 - Ubuntu

Python installs different binaries (and links to binaries): Python 安装不同的二进制文件(和二进制文件的链接):

  • python links to the system's standard Python (2) version python链接到系统的标准 Python (2) 版本
  • python3 links to the system's standard Python 3 version python3链接系统标准Python 3版本
  • python2 links to the system's standard Python 2 version python2链接系统标准Python 2版本
  • python2.7 is the Python 2.7 interpreter python2.7是Python 2.7解释器
  • python2.6 is the Python 2.6 interpreter python2.6是Python 2.6解释器

So just use it like this:所以只需像这样使用它:

python2.6 file.py

Note that you need to have Python 2.6 installed of course.请注意,您当然需要安装 Python 2.6。

First install the alternative Python using apt-get and second, run with full path to the interpreter.首先使用apt-get安装替代 Python,然后使用解释器的完整路径运行。

Also, on ubuntu you should be able to use something like python2.6 script.py .此外,在 ubuntu 上,您应该能够使用类似python2.6 script.py的东西。

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

相关问题 如何在 Emacs 中运行 python 解释器? - How do I run a python interpreter in Emacs? 如何在较新的Python解释器中运行Python脚本? - How do you run a Python script in a newer Python interpreter? 如何让linux在Python解释器中自动运行我的python脚本? - How do I get linux to automatically run my python script in the Python interpreter? 在使用Python解释器运行脚本之前,如何执行一堆Python命令? - How can I execute a bunch of Python commands before a script is run when using the Python interpreter? 如何知道python脚本是否使用解释器的-m选项运行? - How to know if python script was run using interpreter's -m option? 如何将 arguments 传递给通过管道传输到标准输入上的 Python 解释器的脚本? - How do I pass arguments to a script piped to the Python interpreter on stdin? 如何在仍在执行脚本的同时清除 python 解释器? - how do I clear the python interpreter while still executing script? 如何在特定文件夹上运行 python 脚本 - How do I run python script on specific folder 尝试通过解释器运行Python脚本时,为什么会出现“ ImportError:未命名模块”的提示? - Why do I get “ImportError: No module named” when I try to run my Python script via the Interpreter? 我如何知道我使用的是哪个 Python 解释器? - How do I tell which Python interpreter I'm using?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM