【发布时间】:2018-01-27 07:02:47
【问题描述】:
这是 pip3 freeze 的输出:
Chases-MBP:/ chasehippen$ pip3 freeze
certifi==2018.1.18
chardet==3.0.4
flake8==3.5.0
get==0.0.39
idna==2.6
mccabe==0.6.1
pew==1.1.2
pipenv==9.0.3
post==0.0.26
public==0.0.65
pycodestyle==2.3.1
pyflakes==1.6.0
query-string==0.0.28
request==0.0.26
requests==2.18.4
six==1.11.0
urllib3==1.22
virtualenv==15.1.0
virtualenv-clone==0.2.6
当我尝试导入请求或 urllib3 时会发生以下情况:
Chases-MBP:/ chasehippen$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'requests'
>>> import urllib3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'urllib3'
我通过 homebrew 重新安装了 python 3 两次,我不明白为什么它不会让我导入模块?
如果我运行 python import urllib2,效果很好,但只有 urllib3 失败。
这是 where 的输出
Chases-MBP:~ chasehippen$ which pip3
/Library/Frameworks/Python.framework/Versions/3.6/bin/pip3
Chases-MBP:~ chasehippen$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
【问题讨论】:
-
which pip3和which python3的输出是什么? -
通过编辑添加到主帖
-
嗯,好吧,再来一个:
echo $PYTHONPATH呢? -
那是空的...我应该在哪里以及如何设置 python 路径?我还没有找到任何好的文档。
-
嘿,我想通了。我看到的所有资源都说我需要将路径添加到 .profile 或 .bashrc,但在 mac 上,或者至少是我的,它是 .bash_profile。我必须在该文件中添加“export PYTHONPATH="${PYTHONPATH}/Library/Frameworks/Python.framework/Versions/3.6/bin/":/usr/local/lib/python3.6/site-packages”,然后现在导入就像一个魅力。非常感谢您引导我找到答案!
标签: python-3.x terminal homebrew urllib3