Python OSX $ which Python gives /Library/Frameworks/Python.framework/Versions/2.7/bin/python

前端 未结 4 510
春和景丽
春和景丽 2021-01-12 06:02

Hello I\'m trying to run twisted along with python but python cannot find twisted.

I did run $pip install twisted

4条回答
  •  花落未央
    2021-01-12 06:55

    It is just fine. Python may be installed in multiple places in your computer. When you get a new Mac, the default python directory may be

     'usr/bin/python2.7'
    

    You may also have a directory

    'System/Library/Frameworks/Python.framework/Versions/2.7/bin/python'
    

    The first one is the symlink of the second one.

    If you use HomeBrew to install python, you may get a directory in

    'usr/local/bin/python2.7'
    

    You may also have a directory as

    'Library/Frameworks/Python.framework/Versions/2.7/bin/python'
    

    which is exactly where my directory is.

    The difference between the second one and the fourth one, you may find it here Installing Your Framework

    In your question, as you mentioned pip install is successful, but the installed packages still not available. I may guess your pip directory is not in your default python directory, and the packages are installed where your pip directory is. (Please use 'which pip' to check it out)

    For example, in my computer, the default pip directory is

    /Library/Frameworks/Python.framework/Versions/2.7/bin/pip
    

    though, I have also pip in usr/local/bin.

    So, all my packages installed via 'pip install' are stored in

    /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
    

    Hope that resolves your doubt. Similar things have happened to me, and it took me a whole night to figure out.

    Here is the solution: Use PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH" to modify your python directory, or modify your pip directory. However, I would recommend a better way, use virtualenv. This can isolates Python environments, and can help you easily set up packages for each project.

提交回复
热议问题