在虚拟环境中升级Python

3
我在 Mac OS X 上安装了 Python 2.6.1。我想体验一下 Python 3.2,所以我使用以下命令创建了一个虚拟环境:
virtualenv python3.0
然后激活虚拟环境:
source python3.0/bin/activate 如果我更新虚拟环境中的 Python,它会保持系统中的 Python 不受影响吗? 如果是的话,我只需要使用 pip install 安装 Python 3 吗?
2个回答

4

当你通过

virtualenv python3.0

它在虚拟环境文件夹的bin目录中创建一个符号链接:
lrwxr-xr-x   1 ---  ---     6 Aug 23 13:28 python2.6 -> python

因此,你不能仅通过pip install来升级Python。

在Mac OS X上,你可以安装多个版本的Python。在你的情况下,安装Python 3.0,然后使用该版本调用virtualenv。

Python安装在/usr/bin中。

-rwxr-xr-x  2 root  heel  86000 Feb 11  2010 python
-rwxr-xr-x  5 root  heel    925 Feb 11  2010 python-config
lrwxr-xr-x  1 root  heel     75 Aug 23 10:01 python2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
lrwxr-xr-x  1 root  heel     82 Aug 23 10:01 python2.5-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5-config
lrwxr-xr-x  1 root  heel     75 Aug 23 10:01 python2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
lrwxr-xr-x  1 root  heel     82 Aug 23 10:01 python2.6-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python

/usr/bin/python3.0 virtualenv yourenv.

这个环境将会有一个指向Python 3.0版本的符号链接。


那我应该先使用 sudo pip install python 3.2 或者使用 .dmg 安装程序,让 Mac OS X 将其与 2.6 并存安装?然后按照你说的创建虚拟环境? - Ali
使用DMG安装程序安装Python。使用PIP安装程序安装软件包。这就是我所做的。 - pyfunc

1

使用pythonbrew在一个系统上尝试不同版本的Python:

pythonbrew是一个程序,用于自动构建和安装Python到用户的$HOME目录。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接