V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
tttty
V2EX  ›  Python

mac os 下 Python 库的路径问题

  •  
  •   tttty · 2017-05-05 09:34:22 +08:00 · 3346 次点击
    这是一个创建于 2519 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我使用 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 不太会用,求问这个问题怎么解决。

    6 条回复    2017-05-05 16:55:28 +08:00
    MarcoQin
        1
    MarcoQin  
       2017-05-05 09:55:46 +08:00
    可能是你的 pip 是 mac 自带 Python 的,而不是后来你用 brew 装 Python 的吧
    kinghui
        2
    kinghui  
       2017-05-05 10:25:33 +08:00
    python -m pip --version
    tttty
        3
    tttty  
    OP
       2017-05-05 11:11:41 +08:00
    @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)
    ```

    是这个问题..
    ziyo12580
        4
    ziyo12580  
       2017-05-05 11:39:00 +08:00
    你用的啥解释器?一般解释器都是可以修改 python 环境的,我用的 pycharm 就是可以直接切换环境的
    yakumo17
        5
    yakumo17  
       2017-05-05 12:33:41 +08:00
    我现在基本只用 virtualenv 了,用的时候 source,不用了直接 rm。
    tttty
        6
    tttty  
    OP
       2017-05-05 16:55:28 +08:00
    @ziyo12580 我用 IDE 没问题,就是习惯性开个 shell 打开 Python 测试一些东西的时候用不了 很尴尬

    @yakumo17 我写项目的时候用虚拟环境,但是平时随手跑个什么都习惯用全局环境
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5513 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:18 · PVG 16:18 · LAX 01:18 · JFK 04:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.