Can I set a proxy variable specific to a virtual environment?

Viewed 2028

I am on a Windows 10 machine running Python 3.7. I have a proxy variable from my company that has been set on the system level. Now that I am working from home, I can only run (conda, pip) install commands when I am on the company VPN. Is there a way that I can configure a virtual environment to use pip when I'm not on the company network?

When I run the command, conda install pandas , and I am not on the vpn I get this error:

Collecting package metadata (current_repodata.json): ...working... failed`

ProxyError: Conda cannot proceed due to an error in your proxy configuration.
Check for typos and other configuration errors in any '.netrc' file in your home directory,
any environment variables ending in '_PROXY', and any other system-wide proxy
configuration settings.

When I run the command, pip install pandas , and I am not on the vpn I get this error:

WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000numbersAnumbers>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))': /simple/pandas/
ERROR: Could not find a version that satisfies the requirement pandas (from versions: none)

Ideas 1. Can I edit a certain script within a venv conda file that will supersede the system settings?

#workingfromhome

1 Answers

You could use a pip.conf inside your virtual environment:

python3 -m venv venv
cd venv
touch pip.conf

Content of the pip.conf

[global]
proxy = http://proxy.domain:8000

After this use your virtual environment your proxy settings. This works only if your VPN is activated.

If you want to disable the proxy, you could use environment-variable no_proxy:

$Env:no_proxy = 1
Related