No module named pkg_resources

后端 未结 30 2469
一向
一向 2020-11-22 07:22

I\'m deploying a Django app to a dev server and am hitting this error when I run pip install -r requirements.txt:

Traceback (most recent call la         


        
相关标签:
30条回答
  • 2020-11-22 07:57

    July 2018 Update

    Most people should now use pip install setuptools (possibly with sudo).

    Some may need to (re)install the python-setuptools package via their package manager (apt-get install, yum install, etc.).

    This issue can be highly dependent on your OS and dev environment. See the legacy/other answers below if the above isn't working for you.

    Explanation

    This error message is caused by a missing/broken Python setuptools package. Per Matt M.'s comment and setuptools issue #581, the bootstrap script referred to below is no longer the recommended installation method.

    The bootstrap script instructions will remain below, in case it's still helpful to anyone.

    Legacy Answer

    I encountered the same ImportError today while trying to use pip. Somehow the setuptools package had been deleted in my Python environment.

    To fix the issue, run the setup script for setuptools:

    wget https://bootstrap.pypa.io/ez_setup.py -O - | python
    

    (or if you don't have wget installed (e.g. OS X), try

    curl https://bootstrap.pypa.io/ez_setup.py | python
    

    possibly with sudo prepended.)

    If you have any version of distribute, or any setuptools below 0.6, you will have to uninstall it first.*

    See Installation Instructions for further details.


    * If you already have a working distribute, upgrading it to the "compatibility wrapper" that switches you over to setuptools is easier. But if things are already broken, don't try that.

    0 讨论(0)
  • 2020-11-22 07:58

    For me, this error was being caused because I had a subdirectory called "site"! I don't know if this is a pip bug or not, but I started with:

    /some/dir/requirements.txt /some/dir/site/

    pip install -r requirements.txt wouldn't work, giving me the above error!

    renaming the subfolder from "site" to "src" fixed the problem! Maybe pip is looking for "site-packages"? Crazy.

    0 讨论(0)
  • 2020-11-22 07:59

    Apparently you're missing setuptools. Some virtualenv versions use distribute instead of setuptools by default. Use the --setuptools option when creating the virtualenv or set the VIRTUALENV_SETUPTOOLS=1 in your environment.

    0 讨论(0)
  • 2020-11-22 07:59

    ImportError: No module named pkg_resources: the solution is to reinstall python pip using the following Command are under.

    Step: 1 Login in root user.

    sudo su root
    

    Step: 2 Uninstall python-pip package if existing.

    apt-get purge -y python-pip
    

    Step: 3 Download files using wget command(File download in pwd )

    wget https://bootstrap.pypa.io/get-pip.py
    

    Step: 4 Run python file.

    python ./get-pip.py
    

    Step: 5 Finaly exicute installation command.

    apt-get install python-pip
    

    Note: User must be root.

    0 讨论(0)
  • 2020-11-22 08:00

    I fixed the error with virtualenv by doing this:

    Copied pkg_resources.py from

    /Library/Python/2.7/site-packages/setuptools

    to

    /Library/Python/2.7/site-packages/

    This may be a cheap workaround, but it worked for me.

    .

    If setup tools doesn't exist, you can try installing system-site-packages by typing virtualenv --system-site-packages /DESTINATION DIRECTORY, changing the last part to be the directory you want to install to. pkg_rousources.py will be under that directory in lib/python2.7/site-packages

    0 讨论(0)
  • 2020-11-22 08:01

    Needed a little bit more sudo. Then used easy_install to install pip. Works.

    sudo wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
    sudo easy_install pip
    
    0 讨论(0)
提交回复
热议问题