温馨提示×

pip install的代理设置方法

小樊
454
2024-08-30 19:43:08
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在无法直接访问外部网络的情况下,可以通过配置代理服务器来使用pip install命令。以下是几种常见的代理设置方法:

临时设置代理

  • Windows系统

    set HTTP_PROXY=http://[user:password@]proxy_server:port
    set HTTPS_PROXY=http://[user:password@]proxy_server:port
    
  • Linux/Unix系统

    export HTTP_PROXY=http://[user:password@]proxy_server:port
    export HTTPS_PROXY=http://[user:password@]proxy_server:port
    

永久设置代理

  • Windows系统

    %APPDATA%\pip\pip.ini文件中添加以下内容:

    [global]
    index-url=https://mirrors.aliyun.com/pypi/simple/
    proxy=http://[user:password@]proxy_server:port
    
    [install]
    trusted-host=mirrors.aliyun.com
    
  • Linux/Unix系统

    ~/.pip/pip.conf文件中添加以下内容:

    [global]
    index-url=https://mirrors.aliyun.com/pypi/simple/
    proxy=http://[user:password@]proxy_server:port
    
    [install]
    trusted-host=mirrors.aliyun.com
    

使用环境变量设置代理

  • Windows系统

    在命令行中输入以下命令:

    set HTTP_PROXY=http://[user:password@]proxy_server:port
    set HTTPS_PROXY=http://[user:password@]proxy_server:port
    
  • Linux/Unix系统

    在命令行中输入以下命令:

    export HTTP_PROXY=http://[user:password@]proxy_server:port
    export HTTPS_PROXY=http://[user:password@]proxy_server:port
    

使用Fiddler代理

  • 在Fiddler中设置代理账号密码,并将其加密后添加到Fiddler的OnBeforeRequest函数中。

使用第三方库

  • 使用pproxy等第三方库来搭建本地代理。

使用pip配置文件

  • pip.conf文件中设置代理,该文件的位置因操作系统而异。

希望这些方法能帮助您解决pip install时的代理设置问题。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:python运行pip报错怎么解决

0