分别安装Python 2和3

时间:2022-09-18 23:41:15

Is there a way to install python 2 and python 3 on Mac OSX together and be able to switch back and forth? I use Python 2 and 3 for development and I used to be able to do this virtualenv thing where I do source deactivate the development environment. But I wasn't sure how I set that up and it started to get very confusing for the compiler because I apparently installed some modules in one place and it works on python 2 but not 3 (or vice versa) and things are just all over the place. So I am wiping out my whole laptop and this time I want to do this installation business right. Is there any way I can switch back and forth python 2 and 3 with the compiler detecting just one set of library?

有没有办法在Mac OSX上一起安装python 2和python 3并且能够来回切换?我使用Python 2和3进行开发,我曾经能够做这个virtualenv事情,我做源我停用开发环境。但我不确定我是如何设置的,它开始变得非常混乱编译器,因为我显然在一个地方安装了一些模块,它可以在python 2上工作,但不能在3上工作(反之亦然),事情就是全部这个地方。所以我正在擦掉我的整个笔记本电脑,这次我想做这个安装业务。有没有什么办法可以在编译器只检测一组库的情况下来回切换python 2和3?

2 个解决方案

#1


3  

Firstly, install homebrew - it's the fundamental tool for managing installation on your Mac.

首先,安装自制软件 - 它是管理Mac上安装的基本工具。

Now, using homebrew, install separate versions of Python and and Python 3:

现在,使用自制程序,安装Python和Python 3的单独版本:

$ brew install python
...
$ brew install python3

This should automatically install the relevant versions of pip for each version of Python as well as virtualenv. So you can now create a virtual environment for a Python 2 project:

这应该为每个版本的Python以及virtualenv自动安装相关的pip版本。因此,您现在可以为Python 2项目创建虚拟环境:

$ virtualenv --python=python2.7 my_project

and for a Python 3 one:

对于Python 3:

$ virtualenv --python=python3 my_py3_project

and activate/deactivate them as you need.

并根据需要激活/停用它们。

#2


4  

Virtualenv is the default answer to that and it's explained well throughout their pages and across the web. An alternative, which does not depend on the shell, is its "reincarnation" as a Python module, pew, the Python Env Wrapper.

Virtualenv是默认答案,它在整个页面和网络上得到了很好的解释。另一种不依赖于shell的替代方案是它的“转世”作为Python模块,pew,Python Env Wrapper。

Both will allow you to have separate interpreters, even for entirely different version numbers.

两者都允许您拥有单独的口译员,即使是完全不同的版本号。

#1


3  

Firstly, install homebrew - it's the fundamental tool for managing installation on your Mac.

首先,安装自制软件 - 它是管理Mac上安装的基本工具。

Now, using homebrew, install separate versions of Python and and Python 3:

现在,使用自制程序,安装Python和Python 3的单独版本:

$ brew install python
...
$ brew install python3

This should automatically install the relevant versions of pip for each version of Python as well as virtualenv. So you can now create a virtual environment for a Python 2 project:

这应该为每个版本的Python以及virtualenv自动安装相关的pip版本。因此,您现在可以为Python 2项目创建虚拟环境:

$ virtualenv --python=python2.7 my_project

and for a Python 3 one:

对于Python 3:

$ virtualenv --python=python3 my_py3_project

and activate/deactivate them as you need.

并根据需要激活/停用它们。

#2


4  

Virtualenv is the default answer to that and it's explained well throughout their pages and across the web. An alternative, which does not depend on the shell, is its "reincarnation" as a Python module, pew, the Python Env Wrapper.

Virtualenv是默认答案,它在整个页面和网络上得到了很好的解释。另一种不依赖于shell的替代方案是它的“转世”作为Python模块,pew,Python Env Wrapper。

Both will allow you to have separate interpreters, even for entirely different version numbers.

两者都允许您拥有单独的口译员,即使是完全不同的版本号。