Python pip install module is not found. How to link python to pip location?

后端 未结 10 1254
青春惊慌失措
青春惊慌失措 2020-11-27 15:37

I\'m a newbie and I needed the pySerial and feedparser module for my projects. I\'m running Mountain lion.

I followed the following tutorial so that I could upgrade

相关标签:
10条回答
  • 2020-11-27 15:41

    how did you install easy_install/pip? make sure that you installed it for the upgraded version of python. what could have happened here is that the old (default) python install might be linked to your pip install. you might wanna try running the default version and importing the newly installed modules.

    0 讨论(0)
  • 2020-11-27 15:43

    For the sake of anyone also using visual studio from a windows environment:

    I realized that I could see my module installed when i ran pip install

    py pip install [moduleName] 
    py pip list
    

    However debugging in visual studio was getting "module not found". Oddly, i was successfully running import [moduleName] when i ran the interpreter in powershell.

    Reason:

    visual studio was using the wrong interpreter at: C:\Users\[username]\AppData\Local\Programs\Python\Python37\

    What I REALLY wanted was visual studio to use the virtualenv that i setup for my project. To do this, right click Python Environments in "solution explorer", select Add Virtual Environment..., and then select the folder where you created your virtual environment. Then, under project settings, under the General tab, select your virtual environment in the dropdown.

    Now visual studio should be using the same interpreter and everything should play nice!

    0 讨论(0)
  • 2020-11-27 15:50

    No other solutions were working for me, so I tried:

    pip uninstall <module> && pip install <module>
    

    And that resolved it for me. Your mileage may vary.

    0 讨论(0)
  • 2020-11-27 15:52

    For me the problem was that I had weird configuration settings in file pydistutils.cfg

    Try running rm ~/.pydistutils.cfg

    0 讨论(0)
  • 2020-11-27 15:56

    As a quick workaround, and assuming that you are on a bash-like terminal (Linux/OSX), you can try to export the PYTHONPATH environment variable:

    export PYTHONPATH="${PYTHONPATH}:/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages"
    

    For Python 2.7

    0 讨论(0)
  • 2020-11-27 15:56

    If your python and pip binaries are from different versions, modules installed using pip will not be available to python.

    Steps to resolve:

    1. Open up a fresh terminal with a default environment and locate the binaries for pip and python.
    readlink $(which pip)
    ../Cellar/python@2/2.7.15_1/bin/pip
    
    readlink $(which python)
    /usr/local/bin/python3      <-- another symlink
    
    readlink /usr/local/bin/python3
    ../Cellar/python/3.7.2/bin/python3
    

    Here you can see an obvious mismatch between the versions 2.7.15_1 and 3.7.2 in my case.

    1. Replace the pip symlink with the pip binary which matches your current version of python. Use your python version in the following command.
    ln -is /usr/local/Cellar/python/3.7.2/bin/pip3 $(which pip)
    

    The -i flag promts you to overwrite if the target exists.

    That should do the trick.

    0 讨论(0)
提交回复
热议问题