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

Created on 23 Jan 2017  路  38Comments  路  Source: pypa/setuptools

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.

Most helpful comment

@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!

All 38 comments

+1 under ubuntu14.04

Upgrading PIP seems to have fixed it:

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

Indeed. This outcome is expected. In particular, it's at this line where things go wrong:

Running setup.py egg_info for package setuptools

That's pip asking setuptools to build itself (from source dist), which is no longer supported.

The reason that happened on an old pip is because that pip version didn't yet support installation from wheels, which bypasses the unsupported installation.

If you had wanted to install from sdist, you would have to manually install packaging, appdirs, and six first.

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

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?

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

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.

@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!

reinstall get-pip.py can not work to my debian jessie

python ./get-pip.py report error!
Exception:

Traceback (most recent call last):
  File "/tmp/tmpl9axz8dk/pip.zip/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/tmp/tmpl9axz8dk/pip.zip/pip/commands/install.py", line 272, in run
    with self._build_session(options) as session:
  File "/tmp/tmpl9axz8dk/pip.zip/pip/basecommand.py", line 72, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/tmp/tmpl9axz8dk/pip.zip/pip/download.py", line 329, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/tmp/tmpl9axz8dk/pip.zip/pip/download.py", line 93, in user_agent
    from pip._vendor import distro
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "/tmp/tmpl9axz8dk/pip.zip/pip/_vendor/distro.py", line 1050, in <module>
    _distro = LinuxDistribution()
  File "/tmp/tmpl9axz8dk/pip.zip/pip/_vendor/distro.py", line 594, in __init__
    if include_lsb else {}
  File "/tmp/tmpl9axz8dk/pip.zip/pip/_vendor/distro.py", line 933, in _get_lsb_release_info
    raise subprocess.CalledProcessError(code, cmd, stdout)
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1
Traceback (most recent call last):
  File "get-pip.py", line 20061, in <module>
    main()
  File "get-pip.py", line 194, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 172, in bootstrap
    sys.exit(pip.main(["install", "--upgrade"] + args))
  File "/tmp/tmpl9axz8dk/pip.zip/pip/__init__.py", line 233, in main
  File "/tmp/tmpl9axz8dk/pip.zip/pip/basecommand.py", line 251, in main
  File "/tmp/tmpl9axz8dk/pip.zip/pip/basecommand.py", line 72, in _build_session
  File "/tmp/tmpl9axz8dk/pip.zip/pip/download.py", line 329, in __init__
  File "/tmp/tmpl9axz8dk/pip.zip/pip/download.py", line 93, in user_agent
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "/tmp/tmpl9axz8dk/pip.zip/pip/_vendor/distro.py", line 1050, in <module>
  File "/tmp/tmpl9axz8dk/pip.zip/pip/_vendor/distro.py", line 594, in __init__
  File "/tmp/tmpl9axz8dk/pip.zip/pip/_vendor/distro.py", line 933, in _get_lsb_release_info
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1

so, it make me cry!

@segatecm: Python is complaining that lsb_release -a is failing. What do you get if you run that command by itself?

this is what you get when it works:

root@vagrant-ubuntu-trusty-64:~# which lsb_release
/usr/bin/lsb_release
root@vagrant-ubuntu-trusty-64:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:    14.04
Codename:   trusty
root@vagrant-ubuntu-trusty-64:~#

@danielpizarro Thanks. The output seems pretty normal. Can you also echo $? after running that command to show what the exit code is?

oh. That's what you get when it works, so that's probably not what @segatecm would be getting.

@jaraco
Traceback (most recent call last):
File "/usr/bin/lsb_release", line 28, in
import lsb_release
ImportError: No module named 'lsb_release'

@jaraco I installed python3.4 and use update-alternatvies to make it default python.

Interestingly I'm getting the same error on Travis CI with python 3.4, which is surprising.

https://travis-ci.org/cid-harvard/atlas_core/builds/205981903#L299

Though perhaps this is more similar in etiology to #938 ?

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?

Maybe also related: #986

All my pip installs have been failing for weeks now. Can someone please explain why installing...

- python
- python-dev
- build-essential
- libffi-dev
- libssl-dev
- python-setuptools
- python-virtualenv

...followed by easy_install pip is not good enough to avoid this error?

@pixelrebel It works fine for me. Of course, it all depends on your OS and other factors.

There is a known issue that's already fixed in late versions of pip (pypa/pip#4253).

I recommend installing python through your system package manager, install pip using ensurepip or get-pip.py and install other packages (virtualenv, setuptools) using pip.

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.

Hit me, too.

Hi,

I have also a problem with lsb_release :

>

which lsb_release
/usr/bin/lsb_release
lsb_release -a
Traceback (most recent call last):
File "/usr/bin/lsb_release", line 28, in
import lsb_release
ImportError: No module named lsb_release

I try without success a lot of solutions on internet :

  • Trying to remove and install it again
    >

    apt-get remove lsb-release
    apt-get install lsb-release

  • Trying to force python2.7 as default
    >

    update-alternatives --all
    update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1

  • Trying to test different python version
    Link : http://askubuntu.com/questions/767292/importerror-no-module-named-lsb-release
    >

    python2.7 /usr/bin/lsb_release
    Traceback (most recent call last):
    File "/usr/bin/lsb_release", line 28, in
    import lsb_release
    ImportError: No module named lsb_release

    python3.4 /usr/bin/lsb_release
    Traceback (most recent call last):
    File "/usr/bin/lsb_release", line 28, in
    import lsb_release
    ImportError: No module named lsb_release

  • Trying to test different python version
    >

    apt-get remove python3
    apt-get autoremove
    apt-get clean

But still not working, so I hope you will be able to help me. =)
I just need absolutely need the python 2.7 (2.7.12 exactly) for my programs, so I can't remvoe or other thing on this version. =)

Thanks in advance,
Very cordially.

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.

It is still not working, I have the same issue.
/usr/bin/lsb_release
lsb_release -a
Traceback (most recent call last):
File "/usr/bin/lsb_release", line 28, in

Thanks to @kbhagchandani for the "pip check" command - it was a pain but working thru that helped. Surprised it doesn't do that automatically.....

I've somehow ended up getting the same issue with pip on both Vagrant and an Ubuntu server instance. The solution provided by @davidavdav worked perfectly on Vagrant, but on the server, running apt-get purge -y python-pip elicits the following mess:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libexpat1-dev libpython-all-dev libpython-dev libpython2.7-dev python-all python-all-dev
  python-dev python-pip-whl python-wheel python2.7-dev snap-confine
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  python-pip*
0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.
1 not fully installed or removed.
After this operation, 635 kB disk space will be freed.
(Reading database ... 89365 files and directories currently installed.)
Removing python-pip (8.1.1-2ubuntu0.4) ...
Traceback (most recent call last):
  File "/usr/bin/pyclean", line 25, in <module>
    import optparse
  File "/usr/lib/python2.7/optparse.py", line 90, in <module>
    from gettext import gettext
  File "/usr/lib/python2.7/gettext.py", line 49, in <module>
    import locale, copy, os, re, struct, sys
  File "/usr/lib/python2.7/locale.py", line 17, in <module>
    import functools
  File "build/bdist.linux-x86_64/egg/functools.py", line 72, in <module>
    root = max(roots)       # prefer __lt__ to __le__ to __gt__ to __ge__
AttributeError: 'module' object has no attribute 'compose'
dpkg: error processing package python-pip (--purge):
 subprocess installed pre-removal script returned error exit status 1
Traceback (most recent call last):
  File "/usr/bin/pycompile", line 27, in <module>
    import optparse
  File "/usr/lib/python2.7/optparse.py", line 90, in <module>
    from gettext import gettext
  File "/usr/lib/python2.7/gettext.py", line 49, in <module>
    import locale, copy, os, re, struct, sys
  File "/usr/lib/python2.7/locale.py", line 17, in <module>
    import functools
  File "build/bdist.linux-x86_64/egg/functools.py", line 72, in <module>
    root = max(roots)       # prefer __lt__ to __le__ to __gt__ to __ge__
AttributeError: 'module' object has no attribute 'compose'
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 python-pip
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@ip-172-26-10-185:~# pip check
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 4, in <module>
    import locale
  File "/usr/lib/python2.7/locale.py", line 17, in <module>
    import functools
  File "build/bdist.linux-x86_64/egg/functools.py", line 72, in <module>
    root = max(roots)       # prefer __lt__ to __le__ to __gt__ to __ge__
AttributeError: 'module' object has no attribute 'compose'

If anyone can point in a promising direction, I would be very grateful.

This seems to be a bug in the Ubuntu Trusty version of pip. Hopefully they will fix it in an update ASAP. https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1658844

Looks like we shouldn't use pip from ubuntu repositories.
Below fixed it and it has always worked for me.

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

I want to install pip,then it must install setuptools first,so got the same problem.

$ cat /etc/issue
Ubuntu 14.04.5 LTS \n \l

$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 11, in
import setuptools
File "/home/user/Downloads/setuptools-35.0.1/setuptools/__init__.py", line 12, in
import setuptools.version
File "/home/user/Downloads/setuptools-35.0.1/setuptools/version.py", line 1, in
import pkg_resources
File "/home/user/Downloads/setuptools-35.0.1/pkg_resources/__init__.py", line 70, in
import packaging.version
ImportError: No module named packaging.version

at last,simplely sudo apt-get install python-pip
$ which pip
/usr/bin/pip

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
import setuptools.version
File "/usr/local/lib/python2.7/dist-packages/setuptools/version.py", line 1, in
import pkg_resources
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 70, in
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 !

I am having same issues, I have tried everything from redeploying and installing correct library versions. Still I am not able to resolve the issue.

"{u'message': u'An uncaught exception happened while servicing this request. You can investigate this with the zappa tail command.', u'traceback': ['Traceback (most recent call last):\n', ' File \"/var/task/handler.py\", line 434, in handler\n response = Response.from_app(self.wsgi_app, environ)\n', ' File \"c:\\users\\dell\\appdata\\local\\temp\\pip-build-hhbeih\\Werkzeug\\werkzeug\\wrappers.py\", line 903, in from_app\n', ' File \"c:\\users\\dell\\appdata\\local\\temp\\pip-build-hhbeih\\Werkzeug\\werkzeug\\wrappers.py\", line 57, in _run_wsgi_app\n', ' File \"c:\\users\\dell\\appdata\\local\\temp\\pip-build-hhbeih\\Werkzeug\\werkzeug\\test.py\", line 884, in run_wsgi_app\n', \"TypeError: 'NoneType' object is not callable\n\"]}"

I think issue is with WerkZeug.

Can anyone help me out?

@mhumzawan Check your zappa logs, the real exception happens before that WerkZeug error. Only once on the first call to the lambda after deployment.

I had installed pip via easy_install,
easy_install -U pip
now I used
python -m pip install -U pip

This reinstalled pip and somehow the dependency on setuptools got fixed!

(tensorflow) C:\Users\Lenovo\Desktop\CoopNets-master\CoopNets-master>python main.py --category alp --data_dir ./data/scene --output_dir ./output --num_epochs 300 --batch_size 100 --d_lr 0.01 --g_lr 0.0001
Traceback (most recent call last):
File "main.py", line 85, in
tf.app.run()
File "C:\Users\LenovoAnaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 126, in run
_sys.exit(main(argv))
File "main.py", line 71, in main
tf.gfile.MakeDirs(log_dir)
File "C:\Users\LenovoAnaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 374, in recursive_create_dir
pywrap_tensorflow.RecursivelyCreateDir(compat.as_bytes(dname), status)
File "C:\Users\LenovoAnaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 519, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a directory: ./output\alp\log; No such file or directory

what to do at this time...plz reply fast..

Just commenting on here for folks that are having this issue with newer versions of setuptools on conda. What fixed this for me was conda install packaging. I don't know why the other top-results on google did not work for me, but this did the trick.

Hi All,

When I am running RUN pip install -U setuptools inside docker file facing

---> Running in f1588f1aeeec
Downloading/unpacking setuptools from https://files.pythonhosted.org/packages/7c/1b/9b68465658cda69f33c31c4dbd511ac5648835680ea8de87ce05c81f95bf/setuptools-50.3.0.zip#sha256=39060a59d91cf5cf403fa3bacbb52df4205a8c3585e0b9ba4b30e0e19d4c4b18
Running setup.py (path:/tmp/pip_build_root/setuptools/setup.py) egg_info for package setuptools
Traceback (most recent call last):
File "", line 3, in
File "setuptools/__init__.py", line 16, in
import setuptools.version
File "setuptools/version.py", line 1, in
import pkg_resources
File "pkg_resources/__init__.py", line 1365
raise SyntaxError(e) from e
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 3, in

File "setuptools/__init__.py", line 16, in

import setuptools.version

File "setuptools/version.py", line 1, in

import pkg_resources

File "pkg_resources/__init__.py", line 1365

raise SyntaxError(e) from e

                        ^

SyntaxError: invalid syntax


Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/setuptools
Storing debug log for failure in /home/.pip/pip.log
The command '/bin/sh -c pip install -U setuptools' returned a non-zero code: 1

what can be the fix for this issue

Was this page helpful?
0 / 5 - 0 ratings