Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installed BeautifulSoup but still get no module named bs4

I'm using a Jupyter notebook, Python 3.5, and a virtual environment.

Within my virtual env I did:

(venv) > pip install BeautifulSoup4

Which seemed to run fine b/c the terminal output was:

Downloading beautifulsoup4-4.6.0-py2-none-any.whl (86kB)
  100% |████████████████████████████████| 92kB 297kB/s 
Installing collected packages: BeautifulSoup4
Successfully installed BeautifulSoup4-4.6.0

But when I run my Jupyter notebook I get:

ImportError                               Traceback (most recent call last)
<ipython-input-1-5fe69888b1a1> in <module>()
      5 from itertools import groupby
      6 import pickle
----> 7 import bs4
      8 import matplotlib.pyplot as plt
      9 get_ipython().run_line_magic('matplotlib', 'inline')

ImportError: No module named 'bs4'

And I can't change the line import bs4 to from bs4 import BeautifulSoup which I've seen on other SO posts b/c its read-only and I'm not supposed to

like image 228
14wml Avatar asked Jan 29 '18 00:01

14wml


1 Answers

Since you are using Python 3, I think you needed to do

pip3 install BeautifulSoup4

Just pip install would have been for the Python 2 package.

Other things to check:

First make sure you ran both the BeautifulSoup install in your virtualenv, and the python3 prompt or Jupyter notebook in your virtualenv. If you did the install in your root environment and the notebook is run in your virtualenv, or vice versa, you might have a mismatch in your site-packages directory.

Ensure that your package indeed installed by typing pip3 list at a command prompt, and noting that it appeared in the list.

Check that you Jupyter notebook is indeed running a Python 3.5 kernel (upper right hand corner of the browser window)

Check that the path where the package is installed is in your sys.path

Open a Python3 prompt or in Jupyter and run

import sys
print (sys.path)
like image 74
paisanco Avatar answered Oct 12 '22 07:10

paisanco