Search code examples
pythonpython-3.xsix

ImportError: No module named 'urllib.request'


I have received the following error when trying to launch the python executable I have created.

Below is how the code is being imported:

from six.moves.urllib.request import Request, urlopen
from six.moves.urllib.error import HTTPError
from six.moves.urllib.parse import urlencode

More specifically, I receive the following when trying to run the code:

  from six.moves.urllib.request import Request, urlopen
ImportError: No module named 'six'

I am using python 3.4 and any help would be greatly appreciated.


Solution

  • You appear to be trying to write code for Python 3 only. In that case you do not need to use the six library.

    six is an external add-on for Python that helps you write code that can run on both Python 2 and Python 3. You'd normally install it explicitly, or copy the library directly into your project (it is just one file and the license explicitly allows for this).

    Just import directly from the Python 3 libraries:

    from urllib.request import Request, urlopen
    from urllib.error import HTTPError
    from urllib.parse import urlencode