我是 python(和 Linux)新手,我正在尝试运行 setup.py,但是它无法正常工作,因为有一个公司代理阻止了对 pypi 的请求。
我检查this link to properly use the setup.py并检查 this和 this stackoverflow 中的解决方案,但我无法使它们工作(或者我应用它们的方式是错误的)。
我正在使用:
- 虚拟环境
- 虚拟环境包装器
- Python 2.7
- Ubuntu 14
我已经在 .profile
和 .bashrc
中添加了 http_proxy 和 https_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/