PyCUDA error: cannot import name intern

Problem

Running a simple PyCUDA program, I got this error:

$ python hello_cuda.py 
Traceback (most recent call last):
  File "hello_cuda.py", line 5, in <module>
    from pycuda.compiler import SourceModule
  File "/usr/local/lib/python2.7/dist-packages/pycuda/compiler.py", line 1, in <module>
    from pytools import memoize
  File "/usr/local/lib/python2.7/dist-packages/pytools/__init__.py", line 5, in <module>
    from six.moves import range, zip, intern, input
ImportError: cannot import name intern

Solution

The error had nothing to do with PyCUDA or CUDA, but with the six module which helps with compatibility between Python2 and Python3 code. It needed an upgrade and it worked after this:

$ sudo pip install six --upgrade

Tried with: Six 1.9.0, PyCUDA 2014.1, CUDA 5.5 and Ubuntu 14.04

4 thoughts on “PyCUDA error: cannot import name intern”

  1. I tried to use the proposed solution but my Ubuntu 14.04 refuses to uninstall version 1.5.2 of six.

    $ sudo pip install six –upgrade
    Downloading/unpacking six from https://pypi.python.org/packages/3.3/s/six/six-1.9.0-py2.py3-none-any.whl#md5=9ac7e129a80f72d6fc1f0216f6e9627b
    Downloading six-1.9.0-py2.py3-none-any.whl
    Installing collected packages: six
    Found existing installation: six 1.5.2
    Not uninstalling six at /usr/lib/python2.7/dist-packages, owned by OS
    Successfully installed six
    Cleaning up…

    After this I am left with the original version of six on my system and no way to upgrade six. I even tried the following with no better result:

    sudo pip install –upgrade –force-reinstall six

    Any help would be greatly appreciated.

    Charles

    Like

    1. As a followup to my own post I consulted with an expert and he proposed the following work-around:

      in init.py replace (you can find its location in your error mssg):

      from six.moves import range, zip, intern, input

      with the following:

      try:
      from six.moves import range, zip, intern, input
      except ImportError:
      from six.moves import range, zip, input

      This should work.

      Note that the same issue is present with version 1.9.0 of six.

      Happy pythoning.

      Charles

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s