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

后端 未结 10 1259
青春惊慌失措
青春惊慌失措 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:57

    Here is something I learnt after a long time of having issues with pip when I had several versions of Python installed (valid especially for OS X users which are probably using brew to install python blends.)

    I assume that most python developers do have at the beginning of their scripts:

    #!/bin/env python
    

    You may be surprised to find out that this is not necessarily the same python as the one you run from the command line >python

    To be sure you install the package using the correct pip instance for your python interpreter you need to run something like:

    >/bin/env python -m pip install --upgrade mymodule
    
    0 讨论(0)
  • 2020-11-27 16:04

    I also had this problem. I noticed that all of the subdirectories and files under /usr/local/lib/python2.7/dist-packages/ had no read or write permission for group and other, and they were owned by root. This means that only the root user could access them, and so any user that tried to run a Python script that used any of these modules got an import error:

    $ python
    Python 2.7.3 (default, Apr 10 2013, 06:20:15) 
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import selenium
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named selenium
    >>> 
    

    I granted read permission on the files and search permission on the subdirectories for group and other like so:

    $ sudo chmod -R go+rX /usr/local/lib/python2.7/dist-packages
    

    And that resolved the problem for me:

    $ python
    Python 2.7.3 (default, Apr 10 2013, 06:20:15) 
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import selenium
    >>> 
    

    I installed these packages with pip (run as root with sudo). I am not sure why it installed them without granting read/search permissions. This seems like a bug in pip to me, or possibly in the package configuration, but I am not very familiar with Python and its module packaging, so I don't know for sure. FWIW, all packages under dist-packages had this issue. Anyhow, hope that helps.

    Regards.

    0 讨论(0)
  • 2020-11-27 16:05

    Below steps helped me fix this.

    • upgrade pip version
    • remove the created environment by using command rm -rf env-name
    • create environment using command python3 -m venv env-aide
    • now install the package and check
    0 讨论(0)
  • 2020-11-27 16:06

    Make sure to check the python version you are working on if it is 2 then only pip install works If it is 3. something then make sure to use pip3 install

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