简体   繁体   中英

ImportError: No module named 'pkg_resources.extern.six.moves'; 'pkg_resources.extern.six' is not a package

I can not import pkg_resources. Whenever I tried it shows

Python 3.5.2 (default, Jun 28 2016, 08:46:01) 
[GCC 6.1.1 20160602] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> import pkg_resources
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 47, in <module>
      from pkg_resources.extern.six.moves import urllib, map, filter
ImportError: No module named 'pkg_resources.extern.six.moves'; 'pkg_resources.extern.six' is not a package

Is from pkg_resources referring to /usr/lib/python3.5/site-packages/pkg_resources/extern (in which there is no six package). Can you point out what I am doing wrong?

I am using Arch Linux, Python 3.5.2

Well, there is no six package there. six is just a name defined in

/usr/lib/python3.5/site-packages/pkg_resources/extern/__init__.py

To be exact, it looks as follows:

names = 'packaging', 'pyparsing', 'six'
VendorImporter(__name__, names).install()

But VendorImporter is a rather uncommon piece of python , it is part of setuptools therefore it can be expected, I guess. In simple words it performs the import from:

/usr/lib/python3.5/site-packages/six.py

Which does contain moves alright:

_MovedItems._moved_attributes = _moved_attributes

moves = _MovedItems(__name__ + ".moves")
_importer._add_module(moves, "moves")

Now let's see how pacman deals with that:

# pacman -Qo /usr/lib/python3.5/site-packages/pkg_resources/extern/__init__.py
/usr/lib/python3.5/site-packages/pkg_resources/extern/__init__.py is owned by python-setuptools 1:25.1.3-1

Right, extern/__init__.py is owned by setuptools , that is what we expected. Now

# pacman -Qo /usr/lib/python3.5/site-packages/six.py
/usr/lib/python3.5/site-packages/six.py is owned by python-six 1.10.0-2

We see that six is part of python-six .

So, we discovered that python-setuptools is dependent on python-six . The python-setuptools dependency chain is therefore incorrect since it does not list python-six , that is something that happens sometimes with package managers (not only pacman but all package managers suffer from problems with dependency chains from time to time).

For the problem at hand, you need to install python-six manually, and python-setuptools will then work as expected:

pacman -S python-six

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM