I successfully install different modules using pip and they are shown in the
pip list
such as:
beautifulsoup4 (4.4.1)
requests (2.10.0)
Scrapy (1.1.0)
From Terminal
However, whenever I try to import it
import beautifulsoup4
/ import bs4
or import Scrapy
or import requests
the following error is shown:
$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
Update: if I launch python when I am at the correct site-packages directory
$ pwd
/usr/local/lib/python2.7/site-packages
$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
>>> import requests
>>> import bs4
>>> import scrapy
Then it works. This would solve the issue if writing directly on the Terminal. However, I have no clue about how to make it work inside a file.py, which will be the normal use.
As far as I know, I only have Python2.7 installed.
From file.py
If I have a file.py saved in some local folder. This contains, for instance
import requests
from bs4 import BeautifulSoup
when I try
python file.py
I get the same error.
Approach
Same happens with any other module from the list. I would think pip is installing them in a directory that Python is not reading, but as per what I read, it is the correct one.
They are all installed here:
/usr/local/lib/python2.7/site-packages
Output requested by Padraic Cunningham:
$ which -a pip
/usr/local/bin/pip
$ which -a python
/usr/bin/python
/usr/local/bin/python
Output requested by leovp:
$ pip -V
pip 8.1.2 from /usr/local/lib/python2.7/site-packages (python 2.7)
Threads already checked
I have checked the following threads, but unfortunately they did not help me to solve the issue:
- installing pyside using PIP - nmake not found
- PIp installs but module is not found ==> might have provided the right answer, but the links given do not work anymore
- google.protobuf installed, but module not found
- Python pip install module is not found. How to link python to pip location?
Any ideas of what the problem is?
which -a pip
andwhich -a python
– Entreatpip -V
show? Is there a chance that you have both Python 2 and Python 3 installed? – Earleenearlene/usr/local/bin/python
and try importing. – Entreat$ cd /usr/local/bin/python
and-bash: cd: /usr/local/bin/python: Not a directory
If I just go one level above, it is OK, and doingls
shows actually inside the list apython
directory – Abelmosk/usr/local/bin/python
and hit enter. Your system/default python is/usr/bin/python
, pip is installing for/usr/local/bin/python
so that is why you cannot seem to import anything you install, when you just typepython
then the/usr/bin/python
interpreter is started . – Entreat/usr/local/bin/python
interpreter the simplest way would be to export the path in your .bashrc file. – Entreat/usr/bin/python
? Could that be done? Anyhow, if the simplest way is the one you meant, could you explain how to export the path in my .bashrc file? – Abelmosk