12

I'm trying to install tweepy (and by extension oauthlib), and I'm getting the following error when attempting to install:

Collecting requests-oauthlib>=0.4.1 (from tweepy)
Using cached requests_oauthlib-0.7.0-py2.py3-none-any.whl
Collecting oauthlib>=0.6.2 (from requests-oauthlib>=0.4.1->tweepy)
  Using cached oauthlib-2.0.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/var/folders/t7/751h0y1102z99ysr6659yjcr0000gn/T/pip-build-aoklhwtw/oauthlib/setup.py", line 70, in <module>
    'Topic :: Software Development :: Libraries :: Python Modules',
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/core.py", line 108, in setup
    _setup_distribution = dist = klass(attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/setuptools/dist.py", line 263, in __init__
    self.patch_missing_pkg_info(attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/setuptools/dist.py", line 246, in patch_missing_pkg_info
    key = pkg_resources.safe_name(str(attrs['name'])).lower()
AttributeError: module 'pkg_resources' has no attribute 'safe_name'

Interestingly, the /private/var/folders/t7/751h0y1102z99ysr6659yjcr0000gn/T/pip-build-aoklhwtw/oauthlib/ folder does not exist, so I can t even delete that/look at it closer.

Any ideas what might cause this?

cjor
  • 569
  • 1
  • 4
  • 10

3 Answers3

21

Found the solution. I had to upgrade setuptools, so:

$ sudo pip3 install --upgrade setuptools
cjor
  • 569
  • 1
  • 4
  • 10
6

I ran into the same error while running pip inside a virtualenv environment, however setuptools were already up-to-date in my case.

What fixed it for me

# exit the virtualenv
deactivate

# re-initialize your virtual environment (your command may differ)
virtualenv --python=python3.7 env

# activate the virtualenv again
source env/bin/activate

# re-install your dependencies
pip install -r requirements.txt

Root cause

The root cause in my case was that I had accidentally deleted the pkg-resources pip package that virtualenv creates in ubuntu. Since pip install pkg-resouces fails (pkg-resources is not a real pypi package), reinitializing virtualenv is the only way to get that package back.

plowman
  • 13,335
  • 8
  • 53
  • 53
  • This helped to me also, however I needed to delete .venv folder before re-initialization. – Jan Tancibok Jul 08 '20 at 15:31
  • Alternatively, `pip install setuptools --force` worked for me to restore the pkg-resources I had uninstalled. For reference, [stackoverflow: No module named pkg_resources](https://stackoverflow.com/questions/7446187/no-module-named-pkg-resources) – MichaelShimniok May 29 '21 at 18:35
0

I had to use

pipenv --rm

Then I just reinstalled Django and it worked fine.

Blind Rabit
  • 105
  • 8