Error when trying to setup Python pip installation behind corporate firewall

随声附和 提交于 2019-12-24 00:56:02

问题


I am trying to configure global proxy options for python pip installer so that it works behind corporate firewall.

The command I tried: pip config --global set proxy "http://user:pass@host:port"

The above command gives error with below trace:

Traceback (most recent call last):
  File "c:\users\username\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\basecommand.py", line 228, in main
    status = self.run(options, args)
  File "c:\users\username\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\commands\configuration.py", line 122, in run
    handlers[action](options, args[1:])
  File "c:\users\username\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\commands\configuration.py", line 167, in set_name_value
    self.configuration.set_value(key, value)
  File "c:\users\username\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\configuration.py", line 153, in set_value
    section, name = _disassemble_key(key)
ValueError: not enough values to unpack (expected 2, got 1)

Any ideas on what I am doing wrong? Also, I tried creating the pip.ini file in %AppData% (windows) as suggested in many posts. Didn't work for me.


回答1:


You have to use section name:

pip config --global set global.proxy "http://user:pass@host:port"

This sets

[global]
proxy = http://user:pass@host:port



回答2:


If you are using ubuntu then I think this commad will do..

sudo pip --proxy http://web-proxy.mydomain.com install somepackage

then exporting the https_proxy environment variable (note its https_proxy not http_proxy):

export https_proxy=http://web-proxy.mydomain.com

then

sudo -E pip install somepackage



回答3:


For windows Try this... use --proxy http://user:pass@proxyAddress:proxyPort

If it still having trouble... Run this command in CMD...

set http_proxy=http://username:password@proxyAddress:port

set https_proxy=https://username:password@proxyAddress:port

Your pip command..

pip install PackageName


来源:https://stackoverflow.com/questions/51813278/error-when-trying-to-setup-python-pip-installation-behind-corporate-firewall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!