How to force virtualenv to install latest setuptools and pip from pypi?
Asked Answered
A

6

18

Is it possible to force virtualenv to use the latest setuptools and pip available from pypi? Essentially, I'm looking for the opposite of the --never-download flag.

Currently, when I make a new virtualenv, it uses the local (old) versions that come bundled with 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
[...]
Athey answered 17/6, 2013 at 21:7 Comment(0)
A
11

It's not supported for security reasons.

Using virtualenv.py as an isolated script (i.e. without an associated virtualenv_support directory) is no longer supported for security reasons and will fail with an error. Along with this, --never-download is now always pinned to True, and is only being maintained in the short term for backward compatibility (Pull #412).

I can't use the --extra-search-dir option either because it's currently broken https://github.com/pypa/virtualenv/issues/327

Looks like the only option is to simply wait for the virtualenv maintainers to update the bundled packages?

Athey answered 17/6, 2013 at 21:37 Comment(0)
F
9

You can upgrade pip after installing your virtualenv by using pip install -U pip.

I'm sure you could write a bootstrap-script to automate this step.

Foumart answered 5/7, 2013 at 18:40 Comment(0)
U
4

I needed the latest setuptools library, and the --extra-search-dir flag wasn't working for me (even though it's been fixed apparently).

However, making a virtualenv without setuptools and then installing directly from PyPi worked great. E.g. to set up a virtualenv called test:

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

Testing with

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

shows the right version.

Uprear answered 9/1, 2016 at 17:46 Comment(1)
very nice solution!Grog
C
2

I ran into the same problem, and I fixed it by upgrading setuptools.

If env is your virtual env, run the following:

$ env/bin/pip install --upgrade setuptools

Callas answered 25/5, 2017 at 0:51 Comment(0)
G
0

Building on ematsen's excellent answer I made a bash script that works with virtualenvwrapper

#!/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]
Grog answered 13/11, 2016 at 4:16 Comment(0)
N
0

You can do that.

virtualenv -p python3 --download my-env

Then virtualenv puts the latest packages.

my-env/bin/pip list

Out:

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

Info:

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

More info:

virtualenv --help
Nellenelli answered 22/9, 2023 at 6:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.