ImportError: cannot import name urlencode
I am running Python 2.7.8. I get the following error from import requests:
Traceback (most recent call last):
File "request_get.py", line 1, in <module>
import requests
File "/usr/local/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module>
from . import utils
File "/usr/local/lib/python2.7/site-packages/requests/utils.py", line 25, in <module>
from .compat import parse_http_list as _parse_list_header
File "/usr/local/lib/python2.7/site-packages/requests/compat.py", line 7, in <module>
from .packages import chardet
File "/usr/local/lib/python2.7/site-packages/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/__init__.py", line 10, in <module>
from .connectionpool import (
File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 37, in <module>
from .request import RequestMethods
File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/request.py", line 4, in <module>
from urllib import urlencode
ImportError: cannot import name urlencode
$ python
Python 2.7.8 (default, Aug 24 2014, 21:26:19)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> from urllib import urlencode
>>>
Can you give us more information?
- How did you install requests?
- What system are you running on?
- What happens when you do
python -c 'from urllib import urlencode; print("Imported")'? - Do you have a file in the same directory as
request_get.pycalledurllib.py?
@sigmavirus24 Thanks for giving me pointers for troubleshooting. The file I was originally using was haphazardly called 'urllib.py'. Once I ran Requests from a different directory it worked fine.
@evanemolo it was a lucky guess. :)
The error message for this is really bad. I wish they'd make it more clear that you're shadowing a module name.
On Saturday, October 4, 2014, Ian Cordasco [email protected] wrote:
@evanemolo https://github.com/evanemolo it was a lucky guess. :)
— Reply to this email directly or view it on GitHub https://github.com/kennethreitz/requests/issues/2264#issuecomment-57923709 .
Kevin Burke phone: 925.271.7005 | twentymilliseconds.com
@kevinburke it's doubtful that this will be updated in 2.7 and in 3.x it's a non-issue. I tried adding from __future__ import absolute_import and that doesn't fix it either. There's not much we can do here.