可以同时安装 Python 2.7 和 3.5 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32811713/
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
Is it ok to install both Python 2.7 and 3.5?
提问by jarombra
Supposedly Python 2.7 is included native to OSX 10.8 and above (if I remember correctly), but I recently installed Python 3.5 to use for projects while I work through UDacity. Lo and behold, the UDacity courses seem to use 2.7 - wups! So instead of trying to uninstall 3.5 (this procedure seemed to scary for neophytes such as myself), I simply installed 2.7 in addition to the recently installed 3.5 and just run the 2.7 IDLE and Shell. Is this ok, or will I run into problems down the road?
据说 Python 2.7 包含在 OSX 10.8 及更高版本中(如果我没记错的话),但我最近安装了 Python 3.5 以在我通过 UDacity 工作时用于项目。瞧,UDacity 课程似乎使用 2.7 - wups!因此,我没有尝试卸载 3.5(这个过程对于像我这样的新手来说似乎很可怕),我只是在最近安装的 3.5 之外安装了 2.7,然后运行了 2.7 IDLE 和 Shell。这可以吗,或者我会在路上遇到问题吗?
采纳答案by Pavol Li?ka
I have installed two versions, 2.7, 3.4 and I do not have any problem by now. 3.4 I am using for my work project in eclipse environment, 2.7 for udacity course, like You ;).
我已经安装了 2.7、3.4 两个版本,现在没有任何问题。3.4 我在 eclipse 环境中用于我的工作项目,2.7 用于 udacity 课程,就像你一样;)。
回答by Andrew Lalis
As long as you keep your installation folders organized, you should have no issues having both on your computer, besides one thing. The path environment variable for python will determine which version is used by default, so I would say stick to one version, or make sure to make your programs as backwards compatible as possible. I have run into this issue on Windows, since I installed Python 3.4 before 2.7, and therefore to run older code, I have to manually select the python executable. In terms of libraries, I believe that for each python version, the libraries are completely separate, so you should be good there.
只要您保持安装文件夹井井有条,除了一件事之外,您的计算机上应该没有问题。python的路径环境变量将决定默认使用哪个版本,所以我会说坚持一个版本,或者确保你的程序尽可能向后兼容。我在 Windows 上遇到过这个问题,因为我在 2.7 之前安装了 Python 3.4,因此要运行旧代码,我必须手动选择 python 可执行文件。在库方面,我相信对于每个 python 版本,库是完全独立的,所以你应该很好。
回答by Kingsley Zhong
I have the same problem and it is not necessary to uninstall on version of python. Please take care to not mix them up - When you search them up on the start menu. You can make a desktop shortcut saying 2.6 and 3.5.
我有同样的问题,没有必要在 python 版本上卸载。请注意不要混淆它们 - 当您在开始菜单上搜索它们时。您可以制作一个桌面快捷方式,上面写着 2.6 和 3.5。
回答by Joshua
It should be fine. Its actually pretty common to have multiple Python environments. It helps to prevent dependency conflicts between your projects. That is what is happening when you are using tools like pyenv and virtualenv.
应该没问题。拥有多个 Python 环境实际上很常见。它有助于防止项目之间的依赖冲突。当您使用 pyenv 和 virtualenv 等工具时,就会发生这种情况。
Using tools like pyenv and virtualenv may also help you with the path problems that others mentioned. They have commands to set up the path so that their version of pip, python, etc are used.
使用 pyenv 和 virtualenv 等工具也可以帮助您解决其他人提到的路径问题。他们有设置路径的命令,以便使用他们的 pip、python 等版本。
回答by ThomasRones
Im not sure about OSX, but with windows 10 my environment variables for 2.7 were overwritten with the 3.5 path. Not a tough fix, but a little confusing, since it was months later when I needed 2.7 again.
我不确定 OSX,但在 Windows 10 中,我 2.7 的环境变量被 3.5 路径覆盖。不是一个艰难的修复,但有点令人困惑,因为几个月后我再次需要 2.7。
回答by Logan
As others have said, if the installation directory is different it should be no problem at all.
正如其他人所说,如果安装目录不同,则应该没有问题。
One thing that'll make your life easier for switching between the two is to use an IDE such as PyCharm, you just have to change a drop down to switch between the two versions.
让您更轻松地在两者之间切换的一件事是使用 PyCharm 等 IDE,您只需更改下拉列表即可在两个版本之间切换。
回答by Paras jain
You can also use Anaconda for maintaining two versions of Python:
您还可以使用 Anaconda 来维护两个版本的 Python:
Download Anaconda for both Python versions
Open
.bashrc
Add the path to new Anaconda you have installed for, e.g.:
export PATH="/home/paras/anaconda3/bin:$PATH"
Now there will be 2 export paths: one for Python 2 and one for Python 3. Comment the one which you don't want.
为两个 Python 版本下载 Anaconda
打开
.bashrc
添加您已安装的新 Anaconda 的路径,例如:
export PATH="/home/paras/anaconda3/bin:$PATH"
现在将有 2 个导出路径:一个用于 Python 2,一个用于 Python 3。注释您不想要的那个。