每次我使用 pip 时都会出现“AttributeError:'NoneType'”
Posted
技术标签:
【中文标题】每次我使用 pip 时都会出现“AttributeError:\'NoneType\'”【英文标题】:"AttributeError: 'NoneType'" shows up everytime I use pip每次我使用 pip 时都会出现“AttributeError:'NoneType'” 【发布时间】:2017-09-11 14:30:57 【问题描述】:我可以安装***但不能使用“pip install 'module'”,就像我不能从互联网上安装那些模块一样。
错误
AttributeError: 'NoneType' 对象没有属性 'startswith'
尽管有 tensorflow,但 pip 无法安装“requests”或“numpy”等常用模块。
C:\Users\Think>pip install tensorflow
Collecting tensorflow
Exception:
Traceback (most recent call last):
File "D:\Anaconda3\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "D:\Anaconda3\lib\site-packages\pip\commands\install.py", line 335, in
run
wb.build(autobuilding=True)
File "D:\Anaconda3\lib\site-packages\pip\wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "D:\Anaconda3\lib\site-packages\pip\req\req_set.py", line 380, in
prepare_files
ignore_dependencies=self.ignore_dependencies))
File "D:\Anaconda3\lib\site-packages\pip\req\req_set.py", line 554, in
_prepare_file
require_hashes
File "D:\Anaconda3\lib\site-packages\pip\req\req_install.py", line 278, in
populate_link
self.link = finder.find_requirement(self, upgrade)
File "D:\Anaconda3\lib\site-packages\pip\index.py", line 465, in
find_requirement
all_candidates = self.find_all_candidates(req.name)
File "D:\Anaconda3\lib\site-packages\pip\index.py", line 423, in
find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "D:\Anaconda3\lib\site-packages\pip\index.py", line 568, in _get_pages
page = self._get_page(location)
File "D:\Anaconda3\lib\site-packages\pip\index.py", line 683, in _get_page
return htmlPage.get_page(link, session=self.session)
File "D:\Anaconda3\lib\site-packages\pip\index.py", line 792, in get_page
"Cache-Control": "max-age=600",
File "D:\Anaconda3\lib\site-packages\pip\_vendor\requests\sessions.py", line
488, in get
return self.request('GET', url, **kwargs)
File "D:\Anaconda3\lib\site-packages\pip\download.py", line 386, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "D:\Anaconda3\lib\site-packages\pip\_vendor\requests\sessions.py", line
475, in request
resp = self.send(prep, **send_kwargs)
File "D:\Anaconda3\lib\site-packages\pip\_vendor\requests\sessions.py", line
596, in send
r = adapter.send(request, **kwargs)
File "D:\Anaconda3\lib\site-packages\pip\_vendor\cachecontrol\adapter.py",
line 47, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "D:\Anaconda3\lib\site-packages\pip\_vendor\requests\adapters.py",
line 423, in send
timeout=timeout
File "D:\Anaconda3\lib\site-
packages\pip\_vendor\requests\packages\urllib3\connectionpool.py", line
589, in urlopen
self._prepare_proxy(conn)
File "D:\Anaconda3\lib\site-
packages\pip\_vendor\requests\packages\urllib3\connectionpool.py", line
797, in _prepare_proxy
conn.connect()
File "D:\Anaconda3\lib\site-
packages\pip\_vendor\requests\packages\urllib3\connection.py", line
254, in connect
conn = self._new_conn()
File "D:\Anaconda3\lib\site-
packages\pip\_vendor\requests\packages\urllib3\connection.py", line
142, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "D:\Anaconda3\lib\site-
packages\pip\_vendor\requests\packages\urllib3\util\connection.py",
line 66, in create_connection
if host.startswith('['):
AttributeError: 'NoneType' object has no attribute 'startswith'
如果您能看到图片,我将不胜感激:
【问题讨论】:
将错误堆栈添加为格式化文本 那张图片很糟糕,请提供一个更好的 抱歉,我已经更新了。 这是代理设置问题。请检查 $HTTP_PROXY 和 $HTTPS_PROXY 环境变量。 @danger89 是的,我认为你是对的! 【参考方案1】:您是否按照 Anaconda 通过 pip 安装 tensorflow 所需的步骤进行操作。好像只是pip install tensorflow
:
https://www.tensorflow.org/versions/r0.12/get_started/os_setup#anaconda_installation
【讨论】:
不,不只是tensorflow,我就是不能在网上pip,而且报错都是一样的。 那么你的 pip 坏了,试试 --upgrade of pip,重新安装 pip 和 python 等。 那么您很可能面临此处描述的问题:github.com/pypa/pip/issues/3440#issuecomment-177458060【参考方案2】:对于它可能关心的人,有这个重复的帖子,OP 评论了这个问题的解决方案: Resolved duplicate
看起来,您的 python 路径“D:\Anaconda3”可能与使用 pip install 时出错有关。尝试在“C:\”上安装python。
【讨论】:
【参考方案3】:pip
也有同样的问题。结果是我的代理的 url 格式不正确,我错误地只使用了一个正斜杠:
http:/myproxy...
将上述内容更正为有效的网址后,一切正常。
【讨论】:
以上是关于每次我使用 pip 时都会出现“AttributeError:'NoneType'”的主要内容,如果未能解决你的问题,请参考以下文章
【急!】每次刚打开MyEclipse时都会出现问题 导致无法使用【在线等答案】