简体   繁体   English

一台计算机上的多个Python版本(Windows 7)

[英]Multiple Python versions in one computer (windows 7)

I have two versions of Python installed in my computer, Python 3.4 and Python 2.7, and I use both of these installations. 我的计算机上安装了两个版本的Python,Python 3.4和Python 2.7,并且我都使用了这两个安装。 When I run a script, how do I choose which versions I want to use? 运行脚本时,如何选择要使用的版本? May I rename the names of the executables for that (Python.exe -> Python27.exe)? 我可以重命名该可执行文件的名称(Python.exe-> Python27.exe)吗?

Thanks. 谢谢。

Both python 2.7 and python 3 coexist on one machine happily. python 2.7和python 3可以愉快地共存于一台计算机上。

If you name the scripts .py for those you would like to run with python 2.3 and .py3 for those that you would like to run with python3 then you can just invoke the scripts by typing their names or by double clicking. 如果为要与python 2.3一起运行的脚本命名为.py为要与python3一起运行的脚本.py3.py3 ,则可以通过键入脚本名称或双击来调用脚本。 These associations are set up by default by the installer. 这些关联由安装程序默认设置。

You can force the python version on the command line, assuming both are on the path by typing python or python3 for any script file regardless of the extension. 您可以在命令行上强制使用python版本,假设两者都在路径上,可以通过为任何脚本文件键入pythonpython3而不考虑扩展名。

It is also worth looking at virtualenv for your testing. 值得一看的是virtualenv来进行测试。

NB For installing from pypi you can use pip or pip3 and the install for the appropriate version will be done. 注意 :要从pypi安装,您可以使用pippip3并且将完成相应版本的安装。

I am using a 32-bit and a 64-bit version of Python 2.7.6 on the same Windows machine, and the solution to that was to use Winpython for the 64-bit version, which is portable. 我在同一台Windows计算机上使用32位和64位版本的Python 2.7.6,解决方案是将Winpython用于可移植的64位版本。 The downside is that doubleclicking in the file manager will attempt to run a Python script with the 32-bit version (which is a non-portable installation), but I'm mostly writing and running scripts inside Spyder, and there's one version of it with each Python installation. 缺点是双击文件管理器会尝试运行32位版本的Python脚本(这是非便携式安装),但是我主要是在Spyder中编写和运行脚本,并且有一个版本每个Python安装。 Both have independent Pythonpaths, and have never had any problems with each other. 两者都有独立的Pythonpath,彼此之间从未有任何问题。 Winpython is aimed at scientific use, though, so it may not come with all the libraries you may need. 不过,Winpython的用途是科学用途,因此它可能未附带您可能需要的所有库。

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

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