Tanmay Baranwal
Tanmay Baranwal

Reputation: 185

Importing request module in python doesn't work on OS X

I have the requests module installed on my system.

pip install requests

Now I am trying to import requests in the rpel

import requests

It fails with the following error

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests

I found a answer for this problem here, but it does't says anything about having python 2.x in same directory.

My terminal outs are :

MacBook-Pro:~ tanmaybaranwal$ which python

/usr/bin/python

MacBook-Pro:~ tanmaybaranwal$ which python2.6

/usr/bin/python2.6

MacBook-Pro:~ tanmaybaranwal$ which pip

/usr/local/bin/pip

MacBook-Pro:~ tanmaybaranwal$ sudo pip install python-firebase
Password:
Requirement already satisfied (use --upgrade to upgrade): python-firebase in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): requests>=1.1.0 in ./Library/Python/2.7/lib/python/site-packages (from python-firebase)
Cleaning up...

MacBook-Pro:~ tanmaybaranwal$ sudo pip install requests
Requirement already satisfied (use --upgrade to upgrade): requests in ./Library/Python/2.7/lib/python/site-packages
Cleaning up...

MacBook-Pro:~ tanmaybaranwal$ python
Python 2.7.10 (default, Oct 23 2015, 18:05:06) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import firebase
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/firebase/__init__.py", line 4, in <module>
    from firebase import *
  File "/Library/Python/2.7/site-packages/firebase/firebase.py", line 10, in <module>
    from .decorators import http_connection
  File "/Library/Python/2.7/site-packages/firebase/decorators.py", line 1, in <module>
    import requests
ImportError: No module named requests

Listing PIP modules also doesn't has any requests module.

Upvotes: 2

Views: 6164

Answers (2)

ngeorger
ngeorger

Reputation: 43

With macos sonoma and python3.9+, this is what worked for me:


brew install --verbose --require-sha python-requests

Upvotes: 0

Wayne Werner
Wayne Werner

Reputation: 51877

To ensure that you're using the correct python to install something with pip, you can run it via -m

$ python -m pip install --user requests

(if you omit the --user flag then you may need root privileges)

Upvotes: 6

Related Questions