ImportError:没有名为six的模块;六已安装

时间:2017-06-20 16:18:25

标签: python macos six

我在Mac OS X El Capitan上运行python 3.6。

我尝试运行使用六个模块的代码,但收到以下错误:

ImportError: No module named six

当我搜索六个时,它似乎没问题,我确保该位置包含在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

然而,当我尝试运行基本的东西时,我遇到了一个错误:

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

我已尝试卸载并重新安装,并尝试使用$ python -m pip install six进行安装,但没有任何效果。

如果有人有任何想法或需要更多信息,我将不胜感激。

3 个答案:

答案 0 :(得分:3)

这应该有效:

pip install --ignore-installed six

更多信息: https://github.com/pypa/pip/issues/3165

答案 1 :(得分:0)

我没有看到来自six Documentation Release 1.10.0的六个方法版本(),并且你得到的错误也说六个没有对我有意义的属性,下面我打印所有的属性,那里有<{1}}里面

__version__

因此你可以通过

获得六个版本
>>> 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'

答案 2 :(得分:0)

我遇到的问题是我正在运行的脚本使用的是Python 2.7,而我在计算机上使用的是3+。使用venv切换至Python 2.7后,一切正常。