我使用 pip 安装的库,打开 Python 解释器后均出现 import error。
其中 pip 和 Python 路径和版本一致:
➜ ~ which pip
/usr/local/bin/pip
➜ ~ which python
/usr/local/bin/python
➜ ~ pip --version
pip 9.0.1 from /Library/Python/2.7/site-packages (python 2.7)
➜ ~ python
Python 2.7.13 (default, Dec 18 2016, 07:03:39)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages', '/usr/local/Cellar/protobuf/3.2.0_1/libexec/lib/python2.7/site-packages']
导入sys
库,输出sys.path
后发现不太对,感觉是 Python 环境不对导致的。小弟刚用 mac ox 不太会用,求问这个问题怎么解决。
1
MarcoQin 2017-05-05 09:55:46 +08:00
可能是你的 pip 是 mac 自带 Python 的,而不是后来你用 brew 装 Python 的吧
|
2
kinghui 2017-05-05 10:25:33 +08:00
python -m pip --version
|
3
tttty OP @kinghui
``` ⋊> ~ python -m pip --version 11:10:37 pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7) ⋊> ~ pip --version 11:10:49 pip 9.0.1 from /Library/Python/2.7/site-packages (python 2.7) ``` 是这个问题.. |
4
ziyo12580 2017-05-05 11:39:00 +08:00
你用的啥解释器?一般解释器都是可以修改 python 环境的,我用的 pycharm 就是可以直接切换环境的
|
5
yakumo17 2017-05-05 12:33:41 +08:00
我现在基本只用 virtualenv 了,用的时候 source,不用了直接 rm。
|