Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name requests

Tags:

python

pip

Whenever I run .py code using terminal (ubuntu).

I get this error.

Traceback (most recent call last):                                                                                                                               
File "./twitterstream.py", line 15, in <module>                                                                                                                  
    from pip._vendor import requests                                                                                                                             
File "/usr/local/lib/python2.7/dist-packages/pip-10.0.1-py2.7.egg/pip/_vendor/requests/__init__.py", line 83, in <module>                                        
    from pip._internal.compat import WINDOWS                                                                                                                     
File "/usr/local/lib/python2.7/dist-packages/pip-10.0.1-py2.7.egg/pip/_internal/__init__.py", line 42, in <module>                                               
    from pip._internal import cmdoptions                                                                                                                         
File "/usr/local/lib/python2.7/dist-packages/pip-10.0.1-py2.7.egg/pip/_internal/cmdoptions.py", line 16, in <module>                                             
    from pip._internal.index import (                                                                                                                            
File "/usr/local/lib/python2.7/dist-packages/pip-10.0.1-py2.7.egg/pip/_internal/index.py", line 15, in <module>                                                  
    from pip._vendor import html5lib, requests, six
ImportError: cannot import name requests

All the errors are import errors. (pip)

I have tried reinstalling pip and python.

Any suggestions on this?

like image 367
nidhi kalra Avatar asked Dec 17 '22 23:12

nidhi kalra


2 Answers

Little bit late, but just came to the same error as described here. However none of the suggested answers fixed my issue.

In my case pip was installed from OS' package manager (python-pip in Arch Linux) as well as requests (which is a dependency of the first). After removing requests using pip (sudo pip uninstall requests) I ended up with this error.

Fixed by reinstalling using my distro's package manager (pacman -Sy python-requests).

like image 200
fernandezcuesta Avatar answered Dec 31 '22 14:12

fernandezcuesta


write on your terminal

pip install requests

beacause you didnt Installed Yet requests module , And you can install every Module by pip , pip install urlib2 , pip install readlines , pip install termcolor etc//

like image 26
Skiller Dz Avatar answered Dec 31 '22 13:12

Skiller Dz