如何强制virtualenv从pypi安装最新的setuptools和pip?

18

如何强制virtualenv使用来自pypi的最新setuptools和pip?我要找的是--never-download标志的相反操作

目前,当我创建一个新的virtualenv时,它会使用与virtualenv捆绑的本地(旧)版本。

$ v.mk testvenv
New python executable in testvenv/bin/python
Installing setuptools............done.
Installing pip...............done.
$ pip show setuptools
---
Name: setuptools
Version: 0.6c11
Location: /Users/cwilson/.virtualenvs/testvenv/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Requires: 
$ pip search setuptools
[...]
setuptools                - Easily download, build, install, upgrade, and
                            uninstall Python packages
INSTALLED: 0.6c11
LATEST:    0.7.2
[...]
6个回答

11

出于安全原因,不再支持将virtualenv.py用作孤立脚本(即没有关联的virtualenv_support目录),这将导致错误。同时,--never-download现在始终被固定为True,并且仅出于向后兼容性而被短期维护(Pull #412)。

我也无法使用--extra-search-dir选项,因为它目前已经损坏https://github.com/pypa/virtualenv/issues/327

看起来唯一的选择就是等待virtualenv维护者更新捆绑的软件包?


9

安装虚拟环境后,您可以使用pip install -U pip来升级pip。

我相信您可以编写一个引导脚本来自动化此步骤。


4

我需要最新的setuptools库,但--extra-search-dir标志对我不起作用(尽管它似乎已经被解决了)。

然而,如果创建一个没有setuptools的虚拟环境,然后直接从PyPi安装,效果很好。 例如,要设置名为test的虚拟环境:

virtualenv --no-setuptools test
source test/bin/activate
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
easy_install pip

测试中

python -c 'import setuptools; print setuptools.__version__'

显示正确版本。

1
非常好的解决方案! - pymarco

2

我遇到了同样的问题,通过升级setuptools来解决了它。

如果env是您的虚拟环境,请运行以下命令:

$ env/bin/pip install --upgrade setuptools


0

在ematsen 优秀的回答 的基础上,我编写了一个与virtualenvwrapper配合使用的bash脚本。

#!/bin/bash
source `which virtualenvwrapper.sh`
mkvirtualenv --no-setuptools $1
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
rm setuptools-*.zip
easy_install pip

# for python version < 2.7.9
# https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
pip install urllib3[secure]

0
你可以这样做。
virtualenv -p python3 --download my-env

然后virtualenv会安装最新的软件包。
my-env/bin/pip list

出:

Package    Version
---------- -------
pip        23.2.1
setuptools 68.2.2
wheel      0.41.2

信息:

------download    pass to enable download of the latest pip/setuptools/wheel from PyPI (default: False)

更多信息:
virtualenv --help

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接