6

我在 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,但没有任何效果。

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

4

3 回答 3

5

这应该有效:

pip install --ignore-installed six

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

于 2017-06-20T16:20:45.813 回答
1

我没有看到来自六个 Documentation Release 1.10.0中六个的任何方法 version() ,并且您得到的错误还说六个没有对我有意义的属性,下面我打印所有属性并且__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'

因此,您可以通过以下方式获得六的版本

 python -c "import six; print (six.__version__)"
于 2017-06-20T16:26:29.650 回答
0

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

于 2018-09-24T18:35:41.143 回答