4

I have installed python requests module. I used standard pip install requests, the install was successful but it does not work at all. I am not able to import this module to any script file. I always get an error.

Traceback (most recent call last):
  File "D:\Rzeczy Mariusza\Python\aaaa.py", line 3, in <module>
    import requests
  File "D:\Programy\Python34\lib\site-packages\requests\__init__.py", line 58, in <module>
    from . import utils
  File "D:\Programy\Python34\lib\site-packages\requests\utils.py", line 12, in <module>
    import cgi
  File "D:\Programy\Python34\lib\cgi.py", line 39, in <module>
    from email.parser import FeedParser
  File "D:\Programy\Python34\lib\email\parser.py", line 12, in <module>
    from email.feedparser import FeedParser, BytesFeedParser
  File "D:\Programy\Python34\lib\email\feedparser.py", line 27, in <module>
    from email import message
  File "D:\Programy\Python34\lib\email\message.py", line 16, in <module>
    from email import utils
  File "D:\Programy\Python34\lib\email\utils.py", line 40, in <module>
    from email.charset import Charset
  File "D:\Programy\Python34\lib\email\charset.py", line 15, in <module>
    import email.quoprimime
  File "D:\Programy\Python34\lib\email\quoprimime.py", line 44, in <module>
    from string import ascii_letters, digits, hexdigits
ImportError: cannot import name 'ascii_letters'
[Finished in 0.2s with exit code 1]

It is strange, that when I am using IDLE I am able to import it (the module) without any problem. I run Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32 if that info helps.

3
  • 2
    if you run from string import ascii_letters from a python3.4 shell what happens? Commented Dec 3, 2015 at 21:08
  • Have you multiple python versions installed? If you installed another version than 3.4 last, double-click or python yourscript.py won't open it with version 3.4 so requests may not be installed. Commented Dec 3, 2015 at 21:10
  • I do not have any other version installed than python 3.4. Commented Dec 3, 2015 at 21:14

1 Answer 1

13

This usually means that you have a script called string.py in the same folder from which you execute it, and it messes up the imports.

If it is in fact the case, consider renaming it.

Sign up to request clarification or add additional context in comments.

6 Comments

It does not have to be in the same folder, it just has to be in the path.
@PadraicCunningham, valid point. Is it common, though, to have .py files in path?
That was the case. It is the trap of naming simple test files, as simple as string.py. Thank you for your help.
I mean anywhere python looks for files before it gets to the builtins, if you ran the script from a directory where the parent had a string.py file it would import from that, the string.py could be anywhere. The way to check is import string; string.__file__, that will tell you exactly what is being imported
I see, print(string.__file__) gives me path to the 'trap' file. It is good trick to know.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.