4

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?

ash
  • 5,139
  • 2
  • 27
  • 39
nidhi kalra
  • 41
  • 1
  • 1
  • 2

7 Answers7

3

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).

fernandezcuesta
  • 2,390
  • 1
  • 15
  • 32
2

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//

Skiller Dz
  • 897
  • 10
  • 17
2

Instead of this:

from pip._vendor import requests

do this:

import requests

Your code is currently trying to import Requests from another program; that program has just reorganised all its code, so it's not surprising that this doesn't work any more.

ash
  • 5,139
  • 2
  • 27
  • 39
  • That worked, but... there are so many more! It looks like I need to run the failing software on 18.04 instead of 16.04 (Ubuntu). Testing now.... – Alexis Wilke Aug 30 '19 at 19:13
  • Well even under 18.04 the upgrade to pip 19.x fails. But at least it gives me version 9.x instead of 8.x. – Alexis Wilke Aug 30 '19 at 19:43
  • @AlexisWilke you may want to consider asking a new question; it sounds like you're having a different problem. – ash Aug 31 '19 at 19:50
  • I found out that I had to run that software through Docker, then it worked. The setup is still invalid in my case, but otherwise the problem reported here is not happening. – Alexis Wilke Aug 31 '19 at 21:16
2

Pip 10.0.1 seems to be broken so there workaround for the moment is to pin pip at version 9:

pip install --upgrade pip==9.0.3

Otherwise, you need to get the latest version of pip, not the distro version as well as update your PATH:

export PATH="~/.local/bin:$PATH"
RyanH
  • 991
  • 7
  • 13
1

I'm got this error too on pip 10.0.1.
On pip 9.0.3 there is no this error.

jackpot
  • 19
  • 5
1

On a Mac, I hit this where any pip commands failed with that traceback.

This was due to a situation where I had upgraded most packages, but I neglected to upgrade the virtualenv related packages. These upgrades fixed it for me.

pip install --upgrade virtualenvwrapper
pip install --upgrade virtualenv
pip install --upgrade virtualenv-clone

this fixed pip commands, as well as the mkvirtualenv commands and such.

I see how several things might cause this, but this is one case that other users might help. In general, you may want to look for severely out-of-sync packages in your environment.

AlanSE
  • 2,597
  • 2
  • 29
  • 22
0

i got the very same error. The problem was that i had deleted few folders named requests since it clashed with my Requests module in my python code. And then when i put the files back from the trash the pip3 list command worked fine.

varsh
  • 1