Virtualenv: How can i create a new virtualenv using proxy?

Created on 3 Apr 2018  ·  1Comment  ·  Source: pypa/virtualenv

Hi all,
my machine is under a network with proxy.
I've install a package system wide by using pip with this command pip install --proxy http://<ip:port> <package> but when i create a virtual environment by command virtualenv -p python3 venv it raise error requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f7979f0b978>: Failed to establish a new connection: [Errno -5] No address associated with hostname I think this error is caused by proxy, this issued solved when i remove proxy config. I'd like to create a new virtualenv with a --proxy option or something similar like above pip? How can i do it?
Thanks.

Most helpful comment

If you just want to use a proxy, you can use HTTP_PROXY=, and HTTPS_PROXY= settings.

HTTP_PROXY=http://proxy:3128 HTTPS_PROXY=http://proxy:3128 virtualenv virtualenv

But if you want to guarantee the use of your WHLs, then I'd do this.

mkdir -p /opt/pypi/downloads
pushd /opt/pypi/downloads
pip download --no-cache --proxy http://proxy:3128 setuptools wheel pip
popd
virtualenv --no-download --extra-search-dir /opt/pypi/downloads virtualenv

Should take care of it.

If you are using an index URL (like Nexus3), you should try a similar approach.

mkdir -p /opt/pypi/downloads
pushd /opt/pypi/downloads
pip download --no-cache -i http://nexus3:8081/repository/pypi/simple --trusted-host nexus3 setuptools wheel pip
popd
virtualenv --no-download --extra-search-dir /opt/pypi/downloads virtualenv

Hope that helps.

>All comments

If you just want to use a proxy, you can use HTTP_PROXY=, and HTTPS_PROXY= settings.

HTTP_PROXY=http://proxy:3128 HTTPS_PROXY=http://proxy:3128 virtualenv virtualenv

But if you want to guarantee the use of your WHLs, then I'd do this.

mkdir -p /opt/pypi/downloads
pushd /opt/pypi/downloads
pip download --no-cache --proxy http://proxy:3128 setuptools wheel pip
popd
virtualenv --no-download --extra-search-dir /opt/pypi/downloads virtualenv

Should take care of it.

If you are using an index URL (like Nexus3), you should try a similar approach.

mkdir -p /opt/pypi/downloads
pushd /opt/pypi/downloads
pip download --no-cache -i http://nexus3:8081/repository/pypi/simple --trusted-host nexus3 setuptools wheel pip
popd
virtualenv --no-download --extra-search-dir /opt/pypi/downloads virtualenv

Hope that helps.

Was this page helpful?
0 / 5 - 0 ratings