简体   繁体   English

当我也有Python2.7(OS X)时,virtualenv仅创建/lib/Python2.6

[英]virtualenv only creates /lib/Python2.6 when I also have Python2.7 (OS X)

I installed virtualenv on my new MacBook Pro (first time Mac user) before I did anything else (probably a bad idea). 在执行其他任何操作之前(可能是一个坏主意),我在新的MacBook Pro(Mac首次使用)上安装了virtualenv。 When I create an env it contains /lib/Python2.6 inside of it. 当我创建一个env时,其中包含/lib/Python2.6 Afterward I installed Python2.7, but it still only includes a Python2.6 folder in lib , so I assume something is messed up. 之后,我安装了Python2.7,但它在lib仍然只包含一个Python2.6文件夹,因此我认为有些事情搞砸了。

Note: If I go to terminal and type python , I correctly get Python2.7. 注意:如果我进入终端并输入python ,则可以正确获取Python2.7。

I've tried to reinstall virtualenv via: 我尝试通过以下方式重新安装virtualenv:

pip install virtualenv --upgrade

and, also 并且

easy_install virtualenv

Both had the same result. 两者都有相同的结果。 They worked fine with no problems, but I still get no Python2.7 folder in lib on new envs (note: I closed and reopened the terminal each time I upgraded to be safe)... 它们工作正常,没有问题,但是在新环境中的lib我仍然没有Python2.7文件夹(注意:每次升级到安全后,我都会关闭并重新打开终端)...

On a side note, I also tried: 另外,我还尝试了:

brew install virtualenv

but got the following error: 但出现以下错误:

Error: No available formula for virtualenv
virtualenv foo_env --python=Python2.7

当您传递python参数时,它将设置该版本的binlib (当然,假设您安装了该版本)。

This does not answer your question, but I have found the easiest way to get multiple versions of Python up and running on OS X is to use macports . 这不能回答您的问题,但是我发现在OS X上启动并运行多个版本的Python的最简单方法是使用macports For major tools like PIP and VirtualEnv, macports tends to have the latest versions and it manages everything fairly well. 对于PIP和VirtualEnv等主要工具,macports倾向于具有最新版本,并且可以很好地管理所有内容。

Then you can install a PIP specific to each version installed, as well as virtualenv. 然后,您可以安装特定于所安装的每个版本的PIP以及virtualenv。 For more general cases where you don't need virtualenv, but just need to test against different vesions, you can use python_select from macports as well. 对于不需要virtualenv而是只需要针对不同版本进行测试的更一般的情况,也可以从macports中使用python_select。

Once you have macports can install them with 一旦有了macport,就可以使用

sudo port install python26 py26-pip py26-virtualenv python_select

EDIT: It seems I'm getting downvoted for this response for advocating the use of MacPorts over Homebrew. 编辑:看来我因提倡在Homebrew上使用MacPorts而对此表示不满。 The reasoning behind this answer was that I was told specifically not to depend on the version of OS X's python. 这个答案背后的原因是,我被明确告知不要依赖OS X的python版本。 This is why I have a redundant Macports Python 2.6 install and then all of the tools to complement it. 这就是为什么我要冗余安装Macports Python 2.6,然后使用所有工具对其进行补充的原因。 If you feel this answer is poor, please leave a specific comment as to why, and how to improve it. 如果您认为此答案很差,请留下具体评论,说明原因以及改进方法。

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

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