7

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.

rinogo
  • 8,491
  • 12
  • 61
  • 102
Lucas13
  • 71
  • 1
  • 1
  • 3

5 Answers5

7

This should work:

pip install --ignore-installed six

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

raam86
  • 6,785
  • 2
  • 31
  • 46
  • 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 `ImportError` – Lucas13 Jun 20 '17 at 16:48
  • Permission error means you just that. Try adding `--user` tot he command and read the provided link – raam86 Jun 20 '17 at 18:34
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__)"
Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
  • 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 persists – Lucas13 Jun 20 '17 at 16:45
  • how can that be possible if the module is not imported ? Try use python shell and see what happens – Haifeng Zhang Jun 20 '17 at 16:50
  • 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. – Lucas13 Jun 20 '17 at 16:54
  • @Lucas13 `string_types` are constants, you use it directly: `six.integer_types`, now you should be good – Haifeng Zhang Jun 20 '17 at 16:58
  • 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`? – Lucas13 Jun 20 '17 at 17:10
  • @Lucas13 use `import six` and then when you need string_types just call `six.string_types` – Haifeng Zhang Jun 20 '17 at 17:11
  • 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 different – Lucas13 Jun 20 '17 at 17:29
1

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

Vishwasrao
  • 41
  • 6
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)

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.

Bricky
  • 2,572
  • 14
  • 30