Python 3.7: Applying the proxy to all parts of pip installation, failing to maintain the proxy variable
Question:
I have the below problem, I am using command
pip install pyinstaller --proxy=http://webdefence.global.blackspider.com:80 --trusted-host=pypi.python.org
The problem I have is the proxy variable is not maintained through the installation process. It no longers has the proxy address when trying to install setuptools. I have tried using HTTP_PROXY
and HTTPS_PROXY
in my environment variables with no luck. Are there any other ways to set a proxy which will maintain through the pip install?
I have used -vvv to produce more error detail – pasted in at gist.github.com/blaggrob/19e7afcae2b4f1d36139fbf0a88a6651
Collecting pyinstaller
Using cached https://files.pythonhosted.org/packages/03/32/0e0de593f129bf1d1e77eed562496d154ef4460fd5cecfd78612ef39a0cc/PyInstaller-3.4.tar.gz
Installing build dependencies ... error
Complete output from command c:usersblaggrappdatalocalprogramspythonpython37-32scriptspython.exe -m pip install --ignore-installed --no-user --prefix C:UsersblaggrAppDataLocalTemppip-build-env-vd3w15r1 --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple --trusted-host pypi.python.org -- setuptools wheel:
Collecting setuptools
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/setuptools/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/setuptools/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/setuptools/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/setuptools/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/setuptools/
Could not find a version that satisfies the requirement setuptools (from versions: )
No matching distribution found for setuptools
Answers:
You may have run into a bug with the new PEP 518 support implementation, where the isolated build environment created to install build-time dependencies is lacking the necessary proxy configuration.
You can bypass the new feature by using --no-build-isolation
on the command line, by setting no-build-isolation=no
in your configuration file or by setting the PIP_NO_BUILD_ISOLATION=no
environment variable (yes, these last two options are counter-intuitive).
This does require that setuptools
and wheels
then are already installed before you can install pyinstaller
.
I’ve filed a new issue with the pip
project to track this, I don’t believe it has been reported before.
The bug is still present 4 years later but there’s a reasonable workaround! Credit and thanks to q0w from the Pypa project who posted to the issue that @MartijnPieters linked in his answer.
Set the environment variable PIP_PROXY
instead of using the --proxy
command-line argument. The pip subprocess finds and uses the env var just fine. Here’s an example of pip 22.3.1 installing a source tarball with a pyproject.toml
file and its dependencies via a corporate proxy server:
% export PIP_PROXY=http://the.proxy.mybigcompany.com:8080
% pip install --trusted-host=pypi.org --trusted-host=files.pythonhosted.org https://files.pythonhosted.org/packages/a3/50/c4d2727b99052780aad92c7297465af5fe6eec2dbae490aa9763273ffdc1/pip-22.3.1.tar.gz
Collecting https://files.pythonhosted.org/packages/a3/50/c4d2727b99052780aad92c7297465af5fe6eec2dbae490aa9763273ffdc1/pip-22.3.1.tar.gz
Downloading pip-22.3.1.tar.gz (2.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 851.7 kB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
I have the below problem, I am using command
pip install pyinstaller --proxy=http://webdefence.global.blackspider.com:80 --trusted-host=pypi.python.org
The problem I have is the proxy variable is not maintained through the installation process. It no longers has the proxy address when trying to install setuptools. I have tried using HTTP_PROXY
and HTTPS_PROXY
in my environment variables with no luck. Are there any other ways to set a proxy which will maintain through the pip install?
I have used -vvv to produce more error detail – pasted in at gist.github.com/blaggrob/19e7afcae2b4f1d36139fbf0a88a6651
Collecting pyinstaller
Using cached https://files.pythonhosted.org/packages/03/32/0e0de593f129bf1d1e77eed562496d154ef4460fd5cecfd78612ef39a0cc/PyInstaller-3.4.tar.gz
Installing build dependencies ... error
Complete output from command c:usersblaggrappdatalocalprogramspythonpython37-32scriptspython.exe -m pip install --ignore-installed --no-user --prefix C:UsersblaggrAppDataLocalTemppip-build-env-vd3w15r1 --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple --trusted-host pypi.python.org -- setuptools wheel:
Collecting setuptools
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/setuptools/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/setuptools/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/setuptools/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/setuptools/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/setuptools/
Could not find a version that satisfies the requirement setuptools (from versions: )
No matching distribution found for setuptools
You may have run into a bug with the new PEP 518 support implementation, where the isolated build environment created to install build-time dependencies is lacking the necessary proxy configuration.
You can bypass the new feature by using --no-build-isolation
on the command line, by setting no-build-isolation=no
in your configuration file or by setting the PIP_NO_BUILD_ISOLATION=no
environment variable (yes, these last two options are counter-intuitive).
This does require that setuptools
and wheels
then are already installed before you can install pyinstaller
.
I’ve filed a new issue with the pip
project to track this, I don’t believe it has been reported before.
The bug is still present 4 years later but there’s a reasonable workaround! Credit and thanks to q0w from the Pypa project who posted to the issue that @MartijnPieters linked in his answer.
Set the environment variable PIP_PROXY
instead of using the --proxy
command-line argument. The pip subprocess finds and uses the env var just fine. Here’s an example of pip 22.3.1 installing a source tarball with a pyproject.toml
file and its dependencies via a corporate proxy server:
% export PIP_PROXY=http://the.proxy.mybigcompany.com:8080
% pip install --trusted-host=pypi.org --trusted-host=files.pythonhosted.org https://files.pythonhosted.org/packages/a3/50/c4d2727b99052780aad92c7297465af5fe6eec2dbae490aa9763273ffdc1/pip-22.3.1.tar.gz
Collecting https://files.pythonhosted.org/packages/a3/50/c4d2727b99052780aad92c7297465af5fe6eec2dbae490aa9763273ffdc1/pip-22.3.1.tar.gz
Downloading pip-22.3.1.tar.gz (2.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 851.7 kB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done