setuptools: setuptools-34.0 fails with 'ImportError: No module named packaging.version'

Upgrading to setuptools-34.0 fails with ImportError: No module named packaging.version:

pip --version
pip 1.4.1 from /usr/lib/python2.6/site-packages (python 2.6)
---- Begin output of /usr/bin/pip install  --upgrade setuptools ----
STDOUT: Downloading/unpacking setuptools from https://pypi.python.org/packages/4f/5d/77ab299135d7a882fff2970b45c6a77d7d79db0363c395081770632e6f1d/setuptools-34.0.0.zip#md5=927ea526582deefbf98779b2c302dd3d
  Running setup.py egg_info for package setuptools
    Traceback (most recent call last):
      File "<string>", line 3, in <module>
      File "setuptools/__init__.py", line 12, in <module>
        import setuptools.version
      File "setuptools/version.py", line 1, in <module>
        import pkg_resources
      File "pkg_resources/__init__.py", line 70, in <module>
        import packaging.version
    ImportError: No module named packaging.version
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 3, in <module>

  File "setuptools/__init__.py", line 12, in <module>

    import setuptools.version

  File "setuptools/version.py", line 1, in <module>

    import pkg_resources

  File "pkg_resources/__init__.py", line 70, in <module>

    import packaging.version

ImportError: No module named packaging.version

CentOS 6 in AWS.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 38 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@rampageservices referenced method worked for me, for a clean debian-8 (jessie) install in a Vagrant VM. For those like me at python2.7:

sudo -i
apt-get purge -y python-pip
wget https://bootstrap.pypa.io/get-pip.py
python ./get-pip.py
apt-get install python-pip

It was the only one of all suggestions I could find that actually did the job. Thanks!

I’m unable to pip anything now because of this error. It occurred when I updated my Ubuntu trusty: Not pip --version

vagrant@vagrant-ubuntu-trusty-32:~/$ pip --version
Traceback (most recent call last):
  File "/usr/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 70, in <module>
    import packaging.version
ImportError: No module named packaging.version

And of course not pip install:

vagrant@vagrant-ubuntu-trusty-32:~/$ pip install packaging
Traceback (most recent call last):
  File "/usr/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 70, in <module>
    import packaging.version
ImportError: No module named packaging.version

easy_install doesn’t work either with the same error. what should I do?

I’m unable to pip anything now

You can reinstall pip using get-pip.py as @lambda-conjecture suggested. You may also be able to reinstall it with python -m pip install -U pip.

Just ran into this - fixed pip by re-installing pip via the get-pip.py method described here: https://packaging.python.org/installing/#install-pip-setuptools-and-wheel

still, something seems wrong to me when I’m blindly running into this. without warning, dependency fail or similar. I think it might be good for users to be aware and informed about the need to upgrade to latest pip as a dependency for v34

+1 under ubuntu14.04

On my side i checked for the issues using following command

pip check

it showed the following errors

setuptools 34.3.0 requires appdirs, which is not installed. setuptools 34.3.0 requires packaging, which is not installed.

then i fixed the said error by installing the dependicies using following command

pip install appdirs packaging

and this fixes my problem. Hope it will help.

Upgrading PIP seems to have fixed it:

pip --version
pip 9.0.1 from /usr/lib/python2.6/site-packages (python 2.6)

I had the same same issue when I was trying to do a sudo pip install cryptography

Error Message:

Could not import setuptools which is required to install from a source distribution. Traceback (most recent call last): File “/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py”, line 387, in setup_py import setuptools # noqa File “/usr/local/lib/python2.7/dist-packages/setuptools/init.py”, line 12, in <module> import setuptools.version File “/usr/local/lib/python2.7/dist-packages/setuptools/version.py”, line 1, in <module> import pkg_resources File “/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py”, line 70, in <module> import packaging.version ImportError: No module named packaging.version

Running sudo pip install -U setuptools and then sudo pip install cryptography solved my issue.

Hope this helps !

Thanks @jaraco. I’m using 14.04, I wonder if that just doesn’t have the updated packages.

Since I am using ansible, I was able to solve my problem by adding a task before my virtualenv installation which is to first pip install setuptools==33.1.1. Then all my other pip install tasks seem to work.

And this is even when I get it to install six! But I wonder if the current install of “six” doesn’t take effect because the whole pip install is cancelled because of the error?

edit: Progress! Installing “six” beforehand on its own actually solves the issue, strangely enough. It looks like initially it downloads the wheel file, but then for some reason it falls back to the setup.py install route, which then fails because six isn’t there. I wonder why it does that?