Не ставится from bs4 import BeautifulSoup

satfan

Пользователь
Пользователь
Апр 21, 2020
98
6
8
IDLE (Python 3.8 32-bit) Windows 7
index.html --- лежит в папке со скриптом.
-------------
Запускаю этот скрипт:
Python:
from bs4 import BeautifulSoup
import re

def main():
    html = open('index.html').read()
    print(html)
    
    

if __name__ == '__main__':
    main()
Получаю ошибку:
Код:
Traceback (most recent call last):
  File "C:\Users\Александр\Desktop\6\main.py", line 2, in <module>
    from bs4 import BeautifulSoup
  File "C:\Python38-32\lib\site-packages\bs4\__init__.py", line 32, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "C:\Python38-32\lib\site-packages\bs4\builder\__init__.py", line 515, in <module>
    from . import _lxml
  File "C:\Python38-32\lib\site-packages\bs4\builder\_lxml.py", line 16, in <module>
    from lxml import etree
  File "src\lxml\etree.pyx", line 1, in init lxml.etree
ValueError: builtins.type size changed, may indicate binary incompatibility. Expected 440 from C header, got 432 from PyObject
Раньше все модули ставились так:
C:\Python38-32\python.exe -m pip install beautifulsoup
Пробовал так:
C:\Python38-32\python.exe -m pip install --upgrade beautifulsoup4
Обновилось. Что мне сделать ?
 
  • Мне нравится
Реакции: Student

stud_55

Модератор
Команда форума
Модератор
Апр 3, 2020
1 522
672
113
Обновилось. Что мне сделать ?
Попробуйте удалить bs4 и поставить заново:
Код:
pip uninstall bs4
pip install bs4
 
  • Мне нравится
Реакции: Student

satfan

Пользователь
Пользователь
Апр 21, 2020
98
6
8
Спасибо.
Всё сделал как Вы сказали.
Опять ошибка:
Код:
Traceback (most recent call last):
  File "C:\Users\Александр\Desktop\6\main.py", line 2, in <module>
    from bs4 import BeautifulSoup
  File "C:\Python38-32\lib\site-packages\bs4\__init__.py", line 32, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "C:\Python38-32\lib\site-packages\bs4\builder\__init__.py", line 515, in <module>
    from . import _lxml
  File "C:\Python38-32\lib\site-packages\bs4\builder\_lxml.py", line 16, in <module>
    from lxml import etree
  File "src\lxml\etree.pyx", line 1, in init lxml.etree
ValueError: builtins.type size changed, may indicate binary incompatibility. Expected 440 from C header, got 432 from PyObject
 

stud_55

Модератор
Команда форума
Модератор
Апр 3, 2020
1 522
672
113
Проблема скорее всего из-за неправильной установки Beautifulsoup: pip install beautifulsoup - так вы установили старую версию.
Попробуйте удалить все установленные версии и поставить только новую версию:
Код:
pip uninstall beautifulsoup
pip uninstall bs4
pip uninstall beautifulsoup4

pip install beautifulsoup4
 

satfan

Пользователь
Пользователь
Апр 21, 2020
98
6
8
Спасибо. Сделал всё как Вы велели.
Скрипт опять ошибка:
Код:
Traceback (most recent call last):
  File "C:\Users\Александр\Desktop\6\main.py", line 2, in <module>
    from bs4 import BeautifulSoup
  File "C:\Python38-32\lib\site-packages\bs4\__init__.py", line 32, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "C:\Python38-32\lib\site-packages\bs4\builder\__init__.py", line 515, in <module>
    from . import _lxml
  File "C:\Python38-32\lib\site-packages\bs4\builder\_lxml.py", line 16, in <module>
    from lxml import etree
  File "src\lxml\etree.pyx", line 1, in init lxml.etree
ValueError: builtins.type size changed, may indicate binary incompatibility. Expected 440 from C header, got 432 from PyObject
>>>
-------------------------
А это проходило при удалении и установке:
Код:
Microsoft Windows [Version 6.1.7601]
(c) Корпорация Майкрософт (Microsoft Corp.), 2009. Все права защищены.

C:\Windows\System32>C:\Python38-32\python.exe -m pip uninstall beautifulsoup
WARNING: Skipping beautifulsoup as it is not installed.

C:\Windows\System32>C:\Python38-32\python.exe -m pip uninstall bs4
Found existing installation: bs4 0.0.1
Uninstalling bs4-0.0.1:
  Would remove:
    c:\python38-32\lib\site-packages\bs4-0.0.1.dist-info\*
Proceed (y/n)? y
  Successfully uninstalled bs4-0.0.1

C:\Windows\System32>C:\Python38-32\python.exe -m pip uninstall beautifulsoup4
Found existing installation: beautifulsoup4 4.9.3
Uninstalling beautifulsoup4-4.9.3:
  Would remove:
    c:\python38-32\lib\site-packages\beautifulsoup4-4.9.3.dist-info\*
    c:\python38-32\lib\site-packages\bs4\*
Proceed (y/n)? y
  Successfully uninstalled beautifulsoup4-4.9.3

C:\Windows\System32>C:\Python38-32\python.exe -m pip install beautifulsoup4
Collecting beautifulsoup4
  Using cached beautifulsoup4-4.9.3-py3-none-any.whl (115 kB)
Requirement already satisfied: soupsieve>1.2 in c:\python38-32\lib\site-packages
 (from beautifulsoup4) (1.8)
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.9.3

C:\Windows\System32>
C:\Windows\System32>
 

Форум IT Специалистов