当我也有 Python2.7 (OS X) 时,virtualenv 仅创建 /lib/Python2.6
在我做任何其他事情之前,我在我的新 MacBook Pro(第一次使用 Mac 用户)上安装了 virtualenv(可能是个坏主意)。当我创建一个环境时,它内部包含 /lib/Python2.6
。后来我安装了Python2.7,但它仍然只在lib
中包含一个Python2.6
文件夹,所以我认为有些东西搞砸了。
注意:如果我进入终端并输入 python
,我会正确获取 Python2.7。
我尝试通过以下方式重新安装 virtualenv:
pip install virtualenv --upgrade
并且
easy_install virtualenv
两者都有相同的结果。它们工作得很好,没有任何问题,但我在新环境的 lib
中仍然没有 Python2.7
文件夹(注意:每次升级为安全)...
顺便说一句,我也尝试过:
brew install virtualenv
但出现以下错误:
Error: No available formula for virtualenv
I installed virtualenv on my new MacBook Pro (first time Mac user) before I did anything else (probably a bad idea). When I create an env it contains /lib/Python2.6
inside of it. Afterward I installed Python2.7, but it still only includes a Python2.6
folder in lib
, so I assume something is messed up.
Note: If I go to terminal and type python
, I correctly get Python2.7.
I've tried to reinstall virtualenv via:
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)...
On a side note, I also tried:
brew install virtualenv
but got the following error:
Error: No available formula for virtualenv
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您传递
python
参数时,它会为该版本设置bin
和lib
(当然,假设您安装了该版本)。When you pass the
python
argument, it sets up thebin
andlib
for that version (assuming you have that version installed, of course).这并不能回答你的问题,但我发现在 OS X 上启动和运行多个版本的 Python 的最简单方法是使用 macports。对于 PIP 和 VirtualEnv 等主要工具,macports 往往拥有最新版本,并且它可以很好地管理所有内容。
然后,您可以安装特定于每个已安装版本的 PIP,以及 virtualenv。对于不需要 virtualenv,但只需要针对不同版本进行测试的更一般情况,您也可以使用 macports 中的 python_select。
一旦你有了 macports 就可以通过
编辑来安装它们:看来我对这个提倡使用 MacPorts 而不是 Homebrew 的回应感到不满。这个答案背后的原因是我被特别告知不要依赖 OS X 的 python 版本。这就是为什么我安装了冗余的 Macports Python 2.6,然后安装了所有工具来补充它。如果您觉得这个答案很差,请留下具体评论,说明原因以及如何改进。
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. For major tools like PIP and VirtualEnv, macports tends to have the latest versions and it manages everything fairly well.
Then you can install a PIP specific to each version installed, as well as 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.
Once you have macports can install them with
EDIT: It seems I'm getting downvoted for this response for advocating the use of MacPorts over Homebrew. The reasoning behind this answer was that I was told specifically not to depend on the version of OS X's python. This is why I have a redundant Macports Python 2.6 install and then all of the tools to complement it. If you feel this answer is poor, please leave a specific comment as to why, and how to improve it.