35
votes

I am trying to import urllib.request for python 2.7.10 on PyCharm 4.5.4 on Window 10 but getting the error "ImportError: No module named request".

6

6 Answers

47
votes

The urllib.request modules have been deprecated .. just use

import urllib

And for your function if you were earlier writing say

urllib.request.urlretrieve

Now you just write

urllib.urlretrieve
19
votes

I have also faced the same error and Googled to solve it. urlib.request is for Python 3.0.

You may use the code below:

import urllib
urllib.urlopen(url)
11
votes

You'll get this error if you try running a python 3 file with python 2.

2
votes

Try to use this in Python3

try:
    x = urllib.request.urlopen('https://www.google.com/search?q=test')
    print(x.read())

except Exception as e:
    print(str(e))
1
votes

It may happen sometimes, usually in the Linux environment. You have both 2.x and 3.x versions of python installed.

So, in that case, if you are using the command python "file.py"

then by default, it will python 2.x will run the file.

So, use the command python3 "file.py"

I was facing this issue. Maybe it can resolve someone's issue.

-2
votes

Use > Path\easy_install.exe requests if you have a windows machine, where easy_install can be found in your Python*\Scripts folder, if it was installed. (Note Path\easy_install.exe is an example, mine is C:\Python32\Scripts\easy_install.exe)

If you don't have easy install and are running on a windows machine, you can get it here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#distribute

If you manually want to add a library to a windows machine, you can download the compressed library, uncompress it, and then place it into the Lib folder of your python path.

OR

You need to install pip first and then install django-request using pip

pip install django-request

also install,

python setup.py install

then import

from urllib.request import urlopen

Helpful Tips:to chech this