Python 导入某些库时出现“非法指令(核心转储)”(beautifulsoup4.yfinance)

问题描述 投票:0回答:1

我在 Ubuntu 22.04.4 上使用 Python3.10,并且尝试运行我最初在 Windows 11 计算机上编写的代码。每当我运行这个脚本时--

main.py
--它总是在导入阶段停止,并且无法导入
beautifulsoup4
yfinance
,特别是:

print("Starting imports.")
import pandas
print("Imported pandas...")
from bs4 import BeautifulSoup
print("Imported beautifulsoup4...")
import yfinance as yf
print("Imported yfinance...")

# Rest of code...

当我在终端中运行此脚本时,它只打印

Starting imports. Imported pandas...
。在打印语句之后,它会输出
Illegal instruction (core dumped)
:

(myenv) minime@Shaguar:~/Coding/WebScraping$ python main.py
Starting imports.
Imported pandas...
Illegal instruction (core dumped)

我对这个“非法指令”错误做了一些研究,并遇到过由于CPU架构不兼容而导致TensorFlow、numpy等导入失败的情况,但我不知道在这种情况下它将如何应用于beautifulsoup4。

如何成功导入

beautifulsoup4
yfinance
而不会出现
Illegal instruction (core dumped)
错误?

lscpu
的架构输出):

Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         36 bits physical, 48 bits virtual
  Byte Order:            Little Endian
python python-3.x ubuntu beautifulsoup yfinance
1个回答
0
投票

我已经解决了!经过进一步检查

/var/log/syslog
——Ubuntu错误/警告日志文件——我发现一些
etree
的东西有问题:

kernel: [ 3887.864653] traps: python3[5907] trap invalid opcode ip:74ab4c0807c0 sp:7fffee156560 error:0 in etree.cpython-310-x86_64-linux-gnu.so[74ab4c04e000+329000]

经过一番研究,我发现

yfinance
beautifulsoup4
共享的库是导致核心转储的原因:
lxml

我查看了

lxml
PyPI 页面,发现最新版本不支持 2011 年之前的架构。因此,我使用 pip 卸载并降级了我的
lxml
版本,一切顺利。

© www.soinside.com 2019 - 2024. All rights reserved.