为Python安装pip,virtualenv和分发的正确方法是什么? [英] What's the proper way to install pip, virtualenv, and distribute for Python?

查看:152
本文介绍了为Python安装pip,virtualenv和分发的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的答案中. com/questions/4314376/python-egg-file> SO问题4314376 ,我建议使用ez_setup,这样您就可以如下安装pipvirtualenv了:

In my answer to SO question 4314376, I recommended using ez_setup so that you could then install pip and virtualenv as follows:

curl -O http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py
sudo easy_install pip
sudo pip install virtualenv

我最初是从Jesse Noller的博客文章> c6> distribute . (由于 distribute .pixane.com/pip_distribute.png"rel =" noreferrer>此Python公共服务公告.要安装这两个软件包,我使用了:

I originally pulled these instructions from Jesse Noller's blog post So you want to use Python on the Mac?. I like the idea of keeping a clean global site-packages directory, so the only other packages I install there are virtualenvwrapper and distribute. (I recently added distribute to my toolbox because of this Python public service announcement. To install these two packages, I used:

sudo pip install virtualenvwrapper
curl -O http://python-distribute.org/distribute_setup.py
sudo python distribute_setup.py

没有更多的设置工具和easy_install

要真正遵循该Python公共服务声明,请在全新安装Python时做以下:

No more setuptools and easy_install

To really follow that Python public service announcement, on a fresh Python install, I would do the following:

curl -O http://python-distribute.org/distribute_setup.py
sudo python distribute_setup.py
sudo easy_install pip
sudo pip install virtualenv
sudo pip install virtualenvwrapper

雕文的斥责

在对我的答案的评论中/stackoverflow.com/questions/4314376/python-egg-file">SO问题4314376 ,SO用户字形声明:

Glyph's Rebuke

In a comment to my answer to SO question 4314376, SO user Glyph stated:

否.永远不要做sudo python setup.py install任何事情.编写〜/.pydistutils.cfg,将您的pip安装放入〜/.local或其他内容.特别是名为ez_setup.py的文件往往会吸收诸如setuptools和easy_install之类的较新版本,这可能会破坏操作系统上的其他内容.

NO. NEVER EVER do sudo python setup.py install whatever. Write a ~/.pydistutils.cfg that puts your pip installation into ~/.local or something. Especially files named ez_setup.py tend to suck down newer versions of things like setuptools and easy_install, which can potentially break other things on your operating system.

回到简短的问题

所以字形的响应使我想到了最初的问题:

Back to the short question

So Glyph's response leads me to my original question:

推荐答案

您可以执行此操作,而无需在Python本身中安装任何内容.

You can do this without installing anything into python itself.

您不需要sudo或任何特权.

You don't need sudo or any privileges.

您不需要编辑任何文件.

You don't need to edit any files.

将virtualenv安装到引导虚拟环境中.使用该虚拟环境创建更多内容.由于virtualenv附带了pip并进行分发,因此您一次安装即可获得所有内容.

Install virtualenv into a bootstrap virtual environment. Use the that virtual environment to create more. Since virtualenv ships with pip and distribute, you get everything from one install.

  1. 下载virtualenv:
  1. Download virtualenv:
    • http://pypi.python.org/pypi/virtualenv
    • https://pypi.python.org/packages/source/v/virtualenv/virtualenv-12.0.7.tar.gz (or whatever is the latest version!)

以下是bash中的一个示例:

Here is an example in bash:

# Select current version of virtualenv:
VERSION=12.0.7
# Name your first "bootstrap" environment:
INITIAL_ENV=bootstrap
# Set to whatever python interpreter you want for your first environment:
PYTHON=$(which python)
URL_BASE=https://pypi.python.org/packages/source/v/virtualenv

# --- Real work starts here ---
curl -O $URL_BASE/virtualenv-$VERSION.tar.gz
tar xzf virtualenv-$VERSION.tar.gz
# Create the first "bootstrap" environment.
$PYTHON virtualenv-$VERSION/virtualenv.py $INITIAL_ENV
# Don't need this anymore.
rm -rf virtualenv-$VERSION
# Install virtualenv into the environment.
$INITIAL_ENV/bin/pip install virtualenv-$VERSION.tar.gz

现在,您可以使用引导"环境创建更多内容:

Now you can use your "bootstrap" environment to create more:

# Create a second environment from the first:
$INITIAL_ENV/bin/virtualenv py-env1
# Create more:
$INITIAL_ENV/bin/virtualenv py-env2

发疯!

这假设您没有使用过旧的virtualenv版本. 旧版本需要标记--no-site-packges(并取决于Python版本--distribute).现在,您可以仅使用python virtualenv.py path-to-bootstrappython3 virtualenv.py path-to-bootstrap创建引导环境.

This assumes you are not using a really old version of virtualenv. Old versions required the flags --no-site-packges (and depending on the version of Python, --distribute). Now you can create your bootstrap environment with just python virtualenv.py path-to-bootstrap or python3 virtualenv.py path-to-bootstrap.

这篇关于为Python安装pip,virtualenv和分发的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆