New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'module' object has no attribute 'packaging' #2679

Closed
brnrc opened this Issue Apr 13, 2015 · 13 comments

Comments

Projects
None yet
@brnrc

brnrc commented Apr 13, 2015

# pip --version
pip 6.1.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
# pip install supervisor --pre
Collecting supervisor
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading supervisor-3.1.3.tar.gz (391kB)
    100% |████████████████████████████████| 393kB 950kB/s 
  Exception:
  Traceback (most recent call last):
    File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 246, in main
      status = self.run(options, args)
    File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 342, in run
      requirement_set.prepare_files(finder)
    File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 345, in prepare_files
      functools.partial(self._prepare_file, finder))
    File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 290, in _walk_req_to_install
      more_reqs = handler(req_to_install)
    File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 502, in _prepare_file
      abstract_dist.prep_for_dist()
    File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 123, in prep_for_dist
      self.req_to_install.run_egg_info()
    File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 363, in run_egg_info
      self.setup_py, self.name,
    File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 334, in setup_py
      import setuptools  # noqa
    File "/usr/local/lib/python2.7/dist-packages/setuptools/__init__.py", line 11, in <module>
      from setuptools.extension import Extension
    File "/usr/local/lib/python2.7/dist-packages/setuptools/extension.py", line 8, in <module>
      from .dist import _get_unpatched
    File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 21, in <module>
      packaging = pkg_resources.packaging
  AttributeError: 'module' object has no attribute 'packaging'
@dstufft

This comment has been minimized.

Show comment
Hide comment
@dstufft

dstufft Apr 13, 2015

Member

I think this might be because of the patching that Debian does, maye @warsaw can give some insight?

Member

dstufft commented Apr 13, 2015

I think this might be because of the patching that Debian does, maye @warsaw can give some insight?

@rbtcollins

This comment has been minimized.

Show comment
Hide comment
@rbtcollins

rbtcollins Apr 17, 2015

Contributor

I could have a look - what OS is this on, and what version of python-pkg-resources do you have installed?

I see you've installed a local setuptools - what version is that ('pip list' should show it).

Contributor

rbtcollins commented Apr 17, 2015

I could have a look - what OS is this on, and what version of python-pkg-resources do you have installed?

I see you've installed a local setuptools - what version is that ('pip list' should show it).

@geremih

This comment has been minimized.

Show comment
Hide comment
@geremih

geremih May 4, 2015

I was facing a similar problem. It appeared to be because of a stale compiled file (pkg_resources.pyc).
I did

import pkg_resources
print pkg_resources.__file__ 

I deleted the compiled file and everything was fine.

geremih commented May 4, 2015

I was facing a similar problem. It appeared to be because of a stale compiled file (pkg_resources.pyc).
I did

import pkg_resources
print pkg_resources.__file__ 

I deleted the compiled file and everything was fine.

@keith24

This comment has been minimized.

Show comment
Hide comment
@keith24

keith24 May 5, 2015

I got this error and tried un- and reinstalling pip. To my surprise... pip wasn't installed.

sudo apt-get install python-pip

I felt so stupid I almost couldn't post this. Hope it helps anyone as dim as me!

keith24 commented May 5, 2015

I got this error and tried un- and reinstalling pip. To my surprise... pip wasn't installed.

sudo apt-get install python-pip

I felt so stupid I almost couldn't post this. Hope it helps anyone as dim as me!

@jdejoode

This comment has been minimized.

Show comment
Hide comment
@jdejoode

jdejoode May 7, 2015

"I deleted the compiled file and everything was fine."

Had the same issue in a completely different package on Ubuntu and deleting the .pyc files also did the trick. Google brought me here.

jdejoode commented May 7, 2015

"I deleted the compiled file and everything was fine."

Had the same issue in a completely different package on Ubuntu and deleting the .pyc files also did the trick. Google brought me here.

@chrisidefix

This comment has been minimized.

Show comment
Hide comment
@chrisidefix

chrisidefix May 18, 2015

I also stumbled across this thread from Google and I solved it by running:

sudo pip install PACKAGENAME

My target directory requires elevated user rights to install python packages there, which I knew, but I usually got a different (permission) error, when running pip without sudo, so I thought it was still worth sharing.

chrisidefix commented May 18, 2015

I also stumbled across this thread from Google and I solved it by running:

sudo pip install PACKAGENAME

My target directory requires elevated user rights to install python packages there, which I knew, but I usually got a different (permission) error, when running pip without sudo, so I thought it was still worth sharing.

@Bluehorn

This comment has been minimized.

Show comment
Hide comment
@Bluehorn

Bluehorn Aug 24, 2015

geremih commented on May 4

print pkg_resources.file
I deleted the compiled file and everything was fine.

Thanks, this just worked for me as well. Actually that file was from an old distribute installation, which I removed by

$ pip uninstall distribute
Uninstalling distribute-0.6.49:
  /opt/dynasdk/loco2-rhel6/bin/easy_install
  /opt/dynasdk/loco2-rhel6/bin/easy_install-2.7
  /opt/dynasdk/loco2-rhel6/lib/python2.7/site-packages/distribute-0.6.49-py2.7.egg
Proceed (y/n)? y
  Successfully uninstalled distribute-0.6.49

I wonder if pip could detect this case.

Bluehorn commented Aug 24, 2015

geremih commented on May 4

print pkg_resources.file
I deleted the compiled file and everything was fine.

Thanks, this just worked for me as well. Actually that file was from an old distribute installation, which I removed by

$ pip uninstall distribute
Uninstalling distribute-0.6.49:
  /opt/dynasdk/loco2-rhel6/bin/easy_install
  /opt/dynasdk/loco2-rhel6/bin/easy_install-2.7
  /opt/dynasdk/loco2-rhel6/lib/python2.7/site-packages/distribute-0.6.49-py2.7.egg
Proceed (y/n)? y
  Successfully uninstalled distribute-0.6.49

I wonder if pip could detect this case.

@kynan

This comment has been minimized.

Show comment
Hide comment
@kynan

kynan Nov 21, 2015

Note that on a Debian or Ubuntu system (e.g. Ubuntu 14.04 LTS, which comes with setuptools 3.3) you're messing with files supposedly controlled by apt when removing the stale pkg_resources module. This means if the python-pkg-resources package is ever upgraded or reinstalled, the stale module is reinstated!

This issue is discussed in more detail on Stack Overflow and ask ubuntu.

kynan commented Nov 21, 2015

Note that on a Debian or Ubuntu system (e.g. Ubuntu 14.04 LTS, which comes with setuptools 3.3) you're messing with files supposedly controlled by apt when removing the stale pkg_resources module. This means if the python-pkg-resources package is ever upgraded or reinstalled, the stale module is reinstated!

This issue is discussed in more detail on Stack Overflow and ask ubuntu.

@rbtcollins

This comment has been minimized.

Show comment
Hide comment
@rbtcollins

rbtcollins Nov 25, 2015

Contributor

@DSLituiev thats a problem with easy-install, nothing to do with pip, sorry, even though the error is similar.

Contributor

rbtcollins commented Nov 25, 2015

@DSLituiev thats a problem with easy-install, nothing to do with pip, sorry, even though the error is similar.

@atlas0fd00m

This comment has been minimized.

Show comment
Hide comment
@atlas0fd00m

atlas0fd00m Jan 5, 2016

my own experience, i had both local installation of setuptools and the deb from ubuntu. not sure how that got there. i ended up removing the local install and all was well:

the error message:
$ sudo pip install gsync
Downloading/unpacking gsync
Downloading gsync-0.1.14.tar.gz (44kB): 44kB downloaded
Cleaning up...
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 304, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1230, in prepare_files
req_to_install.run_egg_info()
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 293, in run_egg_info
logger.notify('Running setup.py (path:%s) egg_info for package %s' % (self.setup_py, self.name))
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 266, in setup_py
import setuptools
File "/usr/lib/python2.7/dist-packages/setuptools/init.py", line 11, in
from setuptools.extension import Extension
File "/usr/lib/python2.7/dist-packages/setuptools/extension.py", line 8, in
from .dist import _get_unpatched
File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 21, in
packaging = pkg_resources.packaging
AttributeError: 'module' object has no attribute 'packaging'

troubleshooting:
$ dpkg -l setuptools

ii python-setuptools 12.2-1 all Python Distutils Enhancements
un python2.7-setuptools (no description available)
un python3-setuptools (no description available)
un python3.4-setuptools (no description available)

$ locate pkg_resources.pyc
/usr/lib/python2.7/dist-packages/pkg_resources/tests/test_pkg_resources.pyc
/usr/local/lib/python2.7/dist-packages/pip-6.1.1-py2.7.egg/pip/_vendor/pkg_resources/tests/test_pkg_resources.pyc

$ ipython

In [1]: import pkg_resources
In [2]: print pkg_resources.file
/usr/local/lib/python2.7/dist-packages/setuptools-6.0.1-py2.7.egg/pkg_resources.pyc

fix:
$ sudo mv /usr/local/lib/python2.7/dist-packages/setuptools-6.0.1-py2.7.egg ~/
$ sudo pip install gsync
Downloading/unpacking gsync
Downloading gsync-0.1.14.tar.gz (44kB): 44kB downloaded
Running setup.py (path:/tmp/pip-build-FUAtVy/gsync/setup.py) egg_info for package gsync
...

atlas0fd00m commented Jan 5, 2016

my own experience, i had both local installation of setuptools and the deb from ubuntu. not sure how that got there. i ended up removing the local install and all was well:

the error message:
$ sudo pip install gsync
Downloading/unpacking gsync
Downloading gsync-0.1.14.tar.gz (44kB): 44kB downloaded
Cleaning up...
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 304, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1230, in prepare_files
req_to_install.run_egg_info()
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 293, in run_egg_info
logger.notify('Running setup.py (path:%s) egg_info for package %s' % (self.setup_py, self.name))
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 266, in setup_py
import setuptools
File "/usr/lib/python2.7/dist-packages/setuptools/init.py", line 11, in
from setuptools.extension import Extension
File "/usr/lib/python2.7/dist-packages/setuptools/extension.py", line 8, in
from .dist import _get_unpatched
File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 21, in
packaging = pkg_resources.packaging
AttributeError: 'module' object has no attribute 'packaging'

troubleshooting:
$ dpkg -l setuptools

ii python-setuptools 12.2-1 all Python Distutils Enhancements
un python2.7-setuptools (no description available)
un python3-setuptools (no description available)
un python3.4-setuptools (no description available)

$ locate pkg_resources.pyc
/usr/lib/python2.7/dist-packages/pkg_resources/tests/test_pkg_resources.pyc
/usr/local/lib/python2.7/dist-packages/pip-6.1.1-py2.7.egg/pip/_vendor/pkg_resources/tests/test_pkg_resources.pyc

$ ipython

In [1]: import pkg_resources
In [2]: print pkg_resources.file
/usr/local/lib/python2.7/dist-packages/setuptools-6.0.1-py2.7.egg/pkg_resources.pyc

fix:
$ sudo mv /usr/local/lib/python2.7/dist-packages/setuptools-6.0.1-py2.7.egg ~/
$ sudo pip install gsync
Downloading/unpacking gsync
Downloading gsync-0.1.14.tar.gz (44kB): 44kB downloaded
Running setup.py (path:/tmp/pip-build-FUAtVy/gsync/setup.py) egg_info for package gsync
...

@hectord

This comment has been minimized.

Show comment
Hide comment
@hectord

hectord Apr 16, 2016

I had the same issue. After upgrading "distribute" from 0.6.24 to 0.7.3, it works. (pip install --upgrade distribute)

hectord commented Apr 16, 2016

I had the same issue. After upgrading "distribute" from 0.6.24 to 0.7.3, it works. (pip install --upgrade distribute)

@RonnyPfannschmidt

This comment has been minimized.

Show comment
Hide comment
@RonnyPfannschmidt

RonnyPfannschmidt Apr 17, 2016

Contributor

@hectord note that distribute is deprecated and abandoned after the project was merged back into setuptools

Contributor

RonnyPfannschmidt commented Apr 17, 2016

@hectord note that distribute is deprecated and abandoned after the project was merged back into setuptools

@xavfernandez

This comment has been minimized.

Show comment
Hide comment
@xavfernandez

xavfernandez Apr 24, 2016

Contributor

It looks like an issue with a debundled version of pip combined with an upgrade of setuptools.
Nothing much pip could do.

Contributor

xavfernandez commented Apr 24, 2016

It looks like an issue with a debundled version of pip combined with an upgrade of setuptools.
Nothing much pip could do.

bocekm added a commit to upgrades-migrations/preupgrade-assistant that referenced this issue Oct 10, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment