Unable to import BeautifulSoup4.

Asked 2 years ago, Updated 2 years ago, 153 views

from bs4 import BeautifulSoup running on IDLE(3.7.0)shell displays the following error:

Traceback (most recent call last):
  File "C:\Users\Desktop\python Script\test\scraper.py", line 2, in <module>
    from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'

If you check the version with python --version at the command prompt, you will see python 3.7.0.

pip install beautifulsup4 reinstalling beautifulsup will show:

C:\Users\Desktop\python> pip install beautifulgroup4
Collecting beautifulsup4
  Downloading https://files.pythonhosted.org/packages/21/0a/47fdf541c97fd9b6a610cb5fd518175308a7cc60569962e776ac52420387/beautifulsoup4-4.6.3-py3-none-any.whl (90kB)
    100% | | 92kB 610kB/s
**tensorflow 1.10.0 has requirement numpy <=1.14.5, >=1.13.3, but you'll have numpy 1.15.2 which is incompatible.
tensorflow 1.10.0 has requirement setups <=39.1.0, but you'll have setups 40.4.3 which is incompatible.**
Installing collected packages:beautifulgroup4
Successfully installed beautiful group 4-4.6.3

adding
After doing these, running from bs4 import BeautifulSoup results in the same error.
I'm sorry that I couldn't understand your question.
The pip freeze list has the notation beautifulsup4==4.6.3.
The following is the result of pipe show beautifulgroup4.

C:\Users\Desktop\python> pip show beautifulgroup4
Name—beautifulsoup4
Version: 4.6.3
Summary—Screen-scraping library
Home-page: http://www.crummy.com/software/BeautifulSoup/bs4/
Author—Leonard Richardson
Author-email: [email protected]
licenses:MIT
Location: c:\users\anaconda3\lib\site-packages
Requirements:
Required-by —conda-build

Below is the result of import sys;print(sys.path,sys.executable) on IDLE.

['C:\\Users\\AppData\\Local\\Programs\\Python\\Lib\\idlelib', 'C:\\Users\\Anaconda3\\python37.zip', 'C:\\Users\\\AppData\Local\\Programs\Python\\\\\Python\\\\\\Lib\\\\\\\\\\\\LocalDUsers\\\\\\\\\\\\\\\\\\\\\\\\\\\\US>\pData\\Local\\Programs\\Python\\Python37', 'C:\\Users\\AppData\\Local\\Programs\\Python\\Python37\\lib\site-packages'] C:\Users\Desktop\python script\test\pythonw.exe

python windows-10 beautifulsoup python-idle

2022-09-29 22:38

1 Answers

The first half error, ModuleNotFoundError: No module named 'bs4' , indicates that the module for beautifulSoap4 could not be installed.In the latter half, pip install beautifulSoup4 installs and displays the message Successfully, so you should be able to use frombs4import BeautifulSoup.

You may be wondering about the following message, but since this is warning, the installation of beautifulsoup4 has been completed.

**tensorflow 1.10.0 has requirement numpy <=1.14.5, >=1.13.3, but you'll have numpy 1.15.2 which is incompatible.
tensorflow 1.10.0 has requirement setups <=39.1.0, but you'll have setups 40.4.3 which is incompatible.**

This warning is because numpy was upgraded to numpy-1.15.2, so it no longer matches the dependency numpy<=1.14.5,>=1.13.3 of tensorflow 1.10.0.One way to resolve the warning is to upgrade tensorflow because tensorflow 1.11.0 is published.However, tensorflow binaries for python 3.7 are not available yet, so you cannot simply install them with pip install sensorflow.

If you are unable to upgrade tensorflow for some reason, downgrade numpy.To install the downgrade method, specify the version that meets the requirement as follows:

 pip uninstall numpy
pip install numpy == 1.14.5

Also, as the number of projects increases, package conflicts are common when all packages are installed in the site directory on the system, so it is better to create a virtual environment.We recommend that you create and install a virtual environment, especially if the dependencies are severe, such as tensorflow.

Python Tutorial: 12.Virtual Environments and Packages

adding
If bs4 still fails to import, run the following command to see if beautifulsoup4 is included in the list at the location where pip install beautifulsoup4:

 pip freeze

If beautifulsoup4 is included in the list, could you run the following command to add the results?I would like to know where Location is located.

 pip show beautifulsup4 

Also, if you associate it with the output of import sys;print(sys.path, sys.executable) in the comment, you will most likely know why.

Based on the postscript to the question, the reason is that pip install beautifulsup4 was installed in Anaconda3 and not python3.7.

If you are installing more than one python, you will have to specify which python you want to pip into the one that does not have a path.

One way is to have it run pip on IDLE.

>>import pip._internal as pip
>> pip.main (['install', 'beautifulgroup4'])

Also, I think the following commands can be installed in python 3.7.

py-3.7-mpip install beautifulsup4

You can also specify the python.exe path for python 3.7.

pathtopython/python.exe-mpip install beautifulsup4

If you are installing Anaconda3, it may be easier to use Spyder that comes with Anaconda3.


2022-09-29 22:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.