python-2.7 - 无法在代理后面运行 setup.py

标签 python-2.7 proxy ubuntu-14.04

我是 python(和 Linux)新手,我正在尝试运行 setup.py,但是它无法正常工作,因为有一个公司代理阻止了对 pypi 的请求。

我检查this link to properly use the setup.py并检查 thisthis stackoverflow 中的解决方案,但我无法使它们工作(或者我应用它们的方式是错误的)。

我正在使用:

  • 虚拟环境
  • 虚拟环境包装器
  • Python 2.7
  • Ubuntu 14

我已经在 .profile.bashrc 中添加了 http_proxyhttps_proxy

当我使用 pip install --proxy the.proxy:port some_module 时,它工作正常(我也知道环境变量做了一些事情,因为在此之前我什至无法访问 stackoverflow.com ,所以我假设它们工作得很好)。

我已经尝试过的是:

  • 尝试在 python 上使用 --proxy
  • 在 python 中查找类似 --proxy 的内容
  • 尝试添加我的 setup.py 中前面提到的解决方案之一中描述的代理配置(添加到此问题的描述中)
  • 尝试并成功使用 pip --proxy 下载了几个模块(这是我当前不太好的解决方案)
  • 弄乱 virtualenv 中的 python 配置文件,希望找到一些代理配置

我的 setup.py 文件如下所示:

from setuptools import setup, find_packages
import requests

with open('development.txt') as file:
    install_requires = file.readlines()

with open('development_test.txt') as file_test:
    test_requires = file_test.readlines()

setup(
    name="my_project",
    version="1.0.0-SNAPSHOT",
    packages=find_packages(),
    install_requires=install_requires,
    test_suite="nose.collector",
    tests_require=test_requires,
)


proxies = {
  "http": "http://proxy.myproxy.com:3333",
  "https": "http://proxy.myproxy.com:3333",
}

# not sure what goes here... tried a few things but nothing happend

requests.get("https://pypi.python.org", proxies=proxies)

我会尝试任何建议,任何帮助表示赞赏。 谢谢

最佳答案

在深入研究 python 的工作原理但无法找到问题之后,我开始研究 bash 命令的工作原理。 事实证明,您必须使用 sudo -E导出 http_proxy 变量

一个重大错误。

关于python-2.7 - 无法在代理后面运行 setup.py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37504492/

相关文章:

postgresql - 如何升级 Cloudera Manager Postgres 数据库

java - 如何一直运行 Java 控制台应用程序?

python - 何时使用静态方法和类方法

python - 从 Bash 或 Python 检查邮件主题

WCF 客户端代理异常 - "Type cannot be added to list of known types"

android - Genymotion 和 Charles 的 SSL 代理?

python - 尝试通过源代码开始跟踪 Python 特性和行为

在线法官中来自 stdin 的 Python 输入

c# - 如何编写我自己的代理、匿名器并托管它以在网站在工作中被阻止时提供帮助

linux - 使用 Rstudio-server 验证 Windows 域用户