简体   繁体   中英

ImportError: No Module named six; six already installed

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: benjamin@python.org
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.

This should work:

pip install --ignore-installed six

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

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__)"

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.

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'.

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