macos Python - Virtualenv ,python 3?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1416005/
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
Python - Virtualenv , python 3?
提问by mk12
Seems everyone recommends virtualenv for multiple python versions (on osx), but does it even work with python 3.0? I downloaded it, and it doesn't seem to.. And I don't really understand how it works, Can you 'turn on' on env at a time or something? What I want is to leave the system python 2.5 (obviously), and to have python 3.1.1 with subversion pygame to write my own stuff, and python 2.6 with normal stable pygame to use to run other things, like pygame games downloaded from pygame.org. Any help on how to accomplish that? Thanks.
似乎每个人都推荐 virtualenv 用于多个 python 版本(在 osx 上),但它甚至适用于 python 3.0 吗?我下载了它,它似乎没有......而且我真的不明白它是如何工作的,你能一次“打开”env吗?我想要的是离开系统python 2.5(显然),并使用带有subversion pygame的python 3.1.1来编写我自己的东西,使用带有正常稳定pygame的python 2.6来运行其他东西,例如从pygame下载的pygame游戏.org 关于如何实现这一点的任何帮助?谢谢。
OK I realized virtualenv is not what I'm looking for.
好的,我意识到 virtualenv 不是我想要的。
采纳答案by Lennart Regebro
Your use case doesn't actually need virtualenv. You just need to install several different Python versions.
您的用例实际上并不需要 virtualenv。您只需要安装几个不同的 Python 版本。
回答by henrikstroem
It's an old question by now, but I found it myself on top of google search for the answer, and I don't think the answers provided are what people are looking for.
现在这是一个老问题,但我自己在谷歌搜索上找到了答案,我认为所提供的答案不是人们正在寻找的。
As I understand it you want to create different virtual environments with different Python versions?
据我了解,您想使用不同的 Python 版本创建不同的虚拟环境?
This is very easy, and you only need virtualenv itself.
这很容易,您只需要 virtualenv 本身。
For, say, a Python 3:
例如,对于 Python 3:
$ virtualenv -p python3 p34env
(...)
New python executable in p34env/bin/python3.4
Also creating executable in p34env/bin/python
Installing setuptools, pip...done.
$ source p34env/bin/activate
(p34env)$ python -V
Python 3.4.2
(p34env)$ deactivate
$
You use the source
command to activate the venv, and deactivate
to - you guessed it - deactivate it. Notice the prompt changes to indicate the env.
您使用该source
命令激活 venv,然后deactivate
- 您猜对了 - 停用它。请注意提示更改以指示 env。
For your system's standard version of Python you just skip the -p python3
argument, and you can use the argument to point to any version you want given a path.
对于您系统的标准 Python 版本,您只需跳过该-p python3
参数,您可以使用该参数指向您想要给定路径的任何版本。
The last argument is the name (p34env
) and you can make as many as you like, just give them different names.
最后一个参数是名称 ( p34env
),您可以创建任意数量的名称,只需为它们指定不同的名称即可。
回答by Alien8
For me virtualenv3works very well. I also have pypi.python.org/pypi/distribute installed. That also works with the mentioned www.doughellmann.com/docs/virtualenvwrapper/ . I've only tested that on Linux though.
对我来说,virtualenv3工作得很好。我也安装了 pypi.python.org/pypi/distribute。这也适用于提到的 www.doughellmann.com/docs/virtualenvwrapper/ 。不过我只在 Linux 上测试过。
回答by Ned Deily
virtualenv
is designed to create isolated environments of a Python environment. The trick to using it with multiple Python instances is to either install virtualenv
into each of the Python versions you want to use it with, for example:
virtualenv
旨在创建 Python 环境的隔离环境。将它与多个 Python 实例一起使用的技巧是安装virtualenv
到您要使用它的每个 Python 版本中,例如:
/usr/bin/easy_install-2.6 virtualenv
/usr/local/bin/easy_install virtualenv
sudo port install py26-virtualenv
or to invoke it with the intended Python version, for example:
或者使用预期的 Python 版本调用它,例如:
/usr/bin/python2.6 virtualenv.py ENV
/usr/local/bin/python2.6 virtualenv.py ENV
/opt/local/bin/python2.5 virtualenv.py ENV
So, as such, it doesn't directly solve the problem (particularly acute on OS X) of which Python you want to work with. There are various ways to deal with that issue: use absolute paths to the intended Python (as in the above examples), define shell aliases, carefully manage the $PATH
search order, among others.
因此,因此,它并不能直接解决您想要使用哪种 Python 的问题(在 OS X 上尤其严重)。有多种方法可以解决这个问题:使用目标 Python 的绝对路径(如上面的示例)、定义 shell 别名、仔细管理$PATH
搜索顺序等。
At the moment, AFAIK, virtualenv
is not supported with Python 3 because, among other things, setuptools(the magic behind easy_install) is not yet supported on Python 3, although there is work in progresstowards a solution for that.
目前,virtualenv
Python 3 不支持AFAIK,因为除其他外,Python 3 尚不支持setuptools(easy_install 背后的魔法),尽管正在努力寻找解决方案。
BTW, many people use Doug Hellman's virtualenvwrapperto simplify use of virtualenv.
顺便说一句,许多人使用 Doug Hellman 的virtualenvwrapper来简化 virtualenv 的使用。
回答by l3dx
Not sure if I understood you correctly, but here goes :)
不确定我是否正确理解你,但这里是:)
I don't know about OS X, but in Linux you can install both 2.6 and 3. Then you can either specify to use python25 or python3, or change the /usr/bin/python symlink to the version you want to use by default.
我不知道 OS X,但在 Linux 中你可以安装 2.6 和 3。然后你可以指定使用 python25 或 python3,或者将 /usr/bin/python 符号链接更改为默认情况下要使用的版本.