简体   繁体   English

为什么Python 3找不到安装的软件包(例如BeautifulSoup4)?

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

Using Ubuntu 16.04 with Python 3.5 I get import errors for some packages, eg 'BeautifulSoup4' or 'requests'. 将Ubuntu 16.04与Python 3.5结合使用时,某些软件包出现导入错误,例如“ BeautifulSoup4”或“ requests”。 Both libraries are installed from the Ubuntu repositories: 这两个库都是从Ubuntu存储库安装的:

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

Yet I get "ImportError: no module named 'bs4'/'requests'". 但是我收到“ ImportError:没有名为'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. 只有当我(另外!)通过pip3安装这些库时,它才起作用。 The documentation of BeautifulSoup says to install it as "python3-bs4" via apt. BeautifulSoup的文档说要通过apt将其安装为“ python3-bs4”。 Why does it only work with the pip3 method? 为什么它仅适用于pip3方法? What's the purpose of the python3-bs4/python3-requests packages? python3-bs4 / python3-requests软件包的目的是什么?

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和apt彼此混淆了实际安装的内容。 pip3 also listed several python packages which were installed via apt . pip3还列出了几个通过apt安装的python软件包。

I removed/purged everything via apt that was recognized by pip3 list and also purged pip3. 我通过pip3 list识别的apt删除/清除了所有内容, pip3 list除了pip3。 Then I apt install --reinstall the packages that gave me trouble previously: python3-bs4 and python3-requests. 然后我apt install --reinstall以前给我带来麻烦的软件包:python3-bs4和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. requests库仍然无法正常工作,因为它错过了软件包python3-sixpython3-chardetpython3-urllib3 ,这些python3-urllib3据报告已由apt安装。 A apt install --reinstall fixed this as well. apt install --reinstall修复了此问题。 And then it worked! 然后它起作用了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM