在机器上使用virtualenv而无需访问pypi

时间:2013-11-28 12:44:39

标签: python virtualenv

我正在尝试在Ubuntu Server 10.04上安装带有一些软件包的虚拟环境,但是当我尝试创建虚拟环境时,我收到一条错误消息,说它无法访问pypi来安装分发。

机器可以访问apt,但不是很多,我想将全局包的数量保持在最低限度。我也可以手动引入Python包,这是我有虚拟环境后的计划。

该机器安装了python-setuptools,python-pip,python-virtualenv。

如何在离线或靠近它的机器上使用virtualenv?

2 个答案:

答案 0 :(得分:3)

通过virtualenv.py源代码,我们可以看到它在创建venv时使用pip来安装setuptools / pip / wheel。因此,我们可以使用pip中提供的离线安装选项,通过:

# --extra-search-dir can be set multiple times, then it produces a list
virtualenv --extra-search-dir path/to/setuptoolsPackages --no-download venv

一个完整的例子

# Download pip, setuptools and wheel package to current dir.
ls
# argparse-1.4.0-py2.py3-none-any.whl  pip-8.1.1-py2.py3-none-any.whl  setuptools-20.7.0-py2.py3-none-any.whl  wheel-0.29.0-py2.py3-none-any.whl

# Offline version.
# Set extra-search-dir to current dir.
time virtualenv --extra-search-dir ${PWD} --no-download venv
# New python executable in /home/me/wcftest/venv/bin/python3.5
# Also creating executable in /home/me/wcftest/venv/bin/python
# Installing setuptools, pip, wheel...done.
# 
# real  0m3.670s
# user  0m1.350s
# sys   0m0.161s

# On-line.
time virtualenv venv2
# New python executable in /home/me/wcftest/venv2/bin/python3.5
# Also creating executable in /home/me/wcftest/venv2/bin/python
# Installing setuptools, pip, wheel...done.
# 
# real  0m8.419s
# user  0m1.624s
# sys   0m0.179s

有关详细说明,请参阅this blog

答案 1 :(得分:0)

在此SO问题中找到答案:What's the proper way to install pip, virtualenv, and distribute for Python?

我按照Walker Hale IV的建议,它工作正常。请关闭重复。