ImportError: No Module named six; six already installed
Asked Answered
A

5

9

I'm running python 3.6 on Mac OS X El Capitan.

I'm trying to run code that uses the six module, but am getting the following error:

ImportError: No module named six.

When I search for six it appears no problem, and I've made sure that the location is included in the sys.path

$ pip show six
Name: six
Version: 1.10.0
Summary: Python 2 and 3 compatibility utilities
Home-page: http://pypi.python.org/pypi/six/
Author: Benjamin Peterson
Author-email: [email protected]
License: MIT
Location: /usr/anaconda/lib/python3.6/site-packages

However, when I try to run something basic I encounter an error:

$ python -c "import six; print (six.__version__)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'six' has no attribute 'version'

I've tried uninstalling and reinstalling, and have tried installing using $ python -m pip install six, but nothing has worked.

If anyone has any ideas or needs more information, I would appreciate it.

Archaeological answered 20/6, 2017 at 16:18 Comment(4)
I had a similar problem with pytz at the weekend, uninstalling using pip then reinstalling fixed for me :)Ocieock
after installation, see if six is installed by pip listTass
pip list does show six (1.10.0) installed, but the error persistsArchaeological
I'm experiencing this as well to. None of the Answers to date have helped either. I'm running Ubuntu GNOME 17.04.Prakash
A
10

I recently updated macOS Monterey 12.4 and I was facing same issue

ModuleNotFoundError: No module named 'six'

So I have installed 'six' using below command

brew install six

This resolved the issue. Hope this will be useful for someone, who is not able to do import or do not have 'pip'.

Arevalo answered 1/6, 2022 at 8:40 Comment(1)
Yeah, got the same while installing streamlink through brew install streamlink on Monterey 12.6.7. This fixed the issue, thanks!Bookcraft
H
9

This should work:

pip install --ignore-installed six

more info here: https://github.com/pypa/pip/issues/3165

Hashum answered 20/6, 2017 at 16:20 Comment(2)
I tried running this and got the following error: PermissionError: [Errno 13] Permission denied: '/usr/anaconda/lib/python3.6/site-packages/six-1.10.0.dist-info/DESCRIPTION.rst' I also tried to sudo pip install --ignore-installed six and even though it appeared to install correctly, I am still not able to run the original code - I continue to see ImportErrorArchaeological
Permission error means you just that. Try adding --user tot he command and read the provided linkHashum
C
1

I didn't see any method version() for six from six Documentation Release 1.10.0, and the error you got also says six doesn't have the attribute which makes sense to me, below I print all the attributes and there's __version__ inside

>>> import six
>>> six.__dir__()
['_moved_attributes', 'remove_move', '__path__', '__author__', '_MovedItems', 'Module_six_moves_urllib', 'Module_six_moves_urllib_robotparser', 'raise_from', '_SixMetaPathImporter', 'get_function_code', 'callable', 'absolute_import', '_func_code', 'moves', '_urllib_error_moved_attributes', 'text_type', 'Module_six_moves_urllib_parse', 'iteritems', 'iterlists', 'print_', '_assertCountEqual', '__builtins__', 'sys', 'Module_six_moves_urllib_error', 'Module_six_moves_urllib_request', 'assertRegex', 'MovedModule', 'create_bound_method', '_urllib_robotparser_moved_attributes', '_func_closure', 'indexbytes', 'string_types', 'with_metaclass', 'reraise', 'exec_', 'assertRaisesRegex', 'types', 'python_2_unicode_compatible', 'get_function_globals', '_LazyModule', '_assertRaisesRegex', '_meth_self', 'itertools', '_LazyDescr', 'BytesIO', 'add_move', 'iterbytes', '_func_defaults', '__file__', 'unichr', 'get_method_function', 'create_unbound_method', 'get_unbound_function', 'Module_six_moves_urllib_response', 'functools', '__doc__', 'assertCountEqual', 'integer_types', 'PY34', '_importer', '__spec__', '_urllib_response_moved_attributes', 'Iterator', 'StringIO', '_import_module', '__package__', '__version__', 'get_function_defaults', 'operator', 'PY3', 'MAXSIZE', 'int2byte', '_urllib_request_moved_attributes', '_urllib_parse_moved_attributes', 'b', 'class_types', 'next', 'itervalues', '_add_doc', 'viewkeys', 'MovedAttribute', 'advance_iterator', '__cached__', 'u', '__loader__', '_func_globals', 'get_method_self', 'PY2', 'iterkeys', 'wraps', '_meth_func', 'byte2int', 'io', 'viewitems', 'viewvalues', '__name__', 'get_function_closure', 'binary_type', 'add_metaclass', '_assertRegex']
>>> six.__version__
'1.10.0'

Therefore you can get the version of six by

 python -c "import six; print (six.__version__)"
Cobber answered 20/6, 2017 at 16:26 Comment(7)
Thanks, this makes sense why version() was not working. When I run python -c "import six; print (six.__version__)" it correctly prints 1.10.0, but the ImportError still persistsArchaeological
how can that be possible if the module is not imported ? Try use python shell and see what happensCobber
I should clarify - running the small code mentioned here works no problem. The code I'm having issues with starts with from six import string_types and I'm seeing an ImportError here.Archaeological
@Archaeological string_types are constants, you use it directly: six.integer_types, now you should be goodCobber
I'm not sure that I follow - are you saying I should replace string_types used in the code with six.string_types and not import the module six?Archaeological
@Archaeological use import six and then when you need string_types just call six.string_typesCobber
I'm still seeing the same ImportError when using import six in the other file. Now that I can tell import six works for a different file though it seems my error is likely coming from something differentArchaeological
V
1

For those not finding any of the above answers taking care of your issue - python3.10 will require you in some cases to call pip+python version so...

my fix was: pip3.10 install six

And ta-da! Six IS/WAS installed for python3 (if you have overlapping versions) but it was NOT installed for the current version of python.

You can check if this will solve your issue because when you enter: pip3 --version you will likely not see the same version that python3 is calling.

If you see this:

pip3 --version
pip 23.0 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

but your python3 --version shows you:

python3 --version
Python 3.10.9

(or mis-matched versions of python3 and pip3) you will get your issue resolved using my answer.

(You can check to see the version Python3 alias calls by using: which python3)

Violoncello answered 14/2, 2023 at 16:9 Comment(0)
C
0

The issue I ran into was the script I was running was using Python 2.7, and I was using 3+ on my machine. After switching to Python 2.7 using venv, everything worked correctly.

Charactery answered 24/9, 2018 at 18:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.