Home Why doesn't Python 3 find installed packages (e.g. BeautifulSoup4)?
Reply: 1

Why doesn't Python 3 find installed packages (e.g. BeautifulSoup4)?

Andreas N
1#
Andreas N Published in 2018-01-12 13:28:50Z

Using Ubuntu 16.04 with Python 3.5 I get import errors for some packages, e.g. 'BeautifulSoup4' or 'requests'. Both libraries are installed from the Ubuntu repositories:

$ dpkg --get-selections | grep -E "python3-req|python3-bs"
python3-bs4                         install
python3-requests                    install

Yet I get "ImportError: no module named 'bs4'/'requests'".

$ python3 -c "import bs4"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named 'bs4'

Only when I (additionally!) install those libraries via pip3 it works. The documentation of BeautifulSoup says to install it as "python3-bs4" via apt. Why does it only work with the pip3 method? What's the purpose of the python3-bs4/python3-requests packages?

Andreas N
2#
Andreas N Reply to 2018-01-21 17:08:07Z

I was able to resolve the issue.

I'm still not quite sure what was the exact problem, but I suspect that pip3 and apt confused each other about what was actually installed. pip3 also listed several python packages which were installed via apt.

I removed/purged everything via apt that was recognized by pip3 list and also purged pip3. Then I apt install --reinstall the packages that gave me trouble previously: python3-bs4 and python3-requests. The requests library still didn't work because it missed the packages python3-six, python3-chardet and python3-urllib3 which where reported as already installed by apt. A apt install --reinstall fixed this as well. And then it worked!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.351761 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO