ImportError: No Module named six; six already installed

北城以北 提交于 2021-02-07 08:52:57

问题


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.


回答1:


This should work:

pip install --ignore-installed six

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




回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/44658258/importerror-no-module-named-six-six-already-installed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!