当前位置: 首页 > news >正文

突然无法调用scikit-learn、xgboost

遇到的错误包含:

  File "<string>", line 3, in <module>File "/usr/anaconda3/envs/py37/lib/python3.7/site-packages/sklearn/__init__.py", line 81, in <module>from . import __check_build  # noqa: F401File "/usr/anaconda3/envs/py37/lib/python3.7/site-packages/sklearn/__check_build/__init__.py", line 50, in <module>raise_build_error(e)File "/usr/anaconda3/envs/py37/lib/python3.7/site-packages/sklearn/__check_build/__init__.py", line 43, in raise_build_error% (e, local_dir, "".join(dir_content).strip(), msg)
ImportError: dlopen: cannot load any more object with static TLS
___________________________________________________________________________
Contents of /usr/anaconda3/envs/py37/lib/python3.7/site-packages/sklearn/__check_build:
__init__.py               setup.py                  _check_build.cpython-37m-x86_64-linux-gnu.so
__pycache__
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
  File "<string>", line 5, in <module>File "/usr/anaconda3/envs/py37/lib/python3.7/site-packages/xgboost/__init__.py", line 6, in <module>from .core import (File "/usr/anaconda3/envs/py37/lib/python3.7/site-packages/xgboost/core.py", line 231, in <module>_LIB = _load_lib()File "/usr/anaconda3/envs/py37/lib/python3.7/site-packages/xgboost/core.py", line 197, in _load_lib"""
xgboost.core.XGBoostError: 
XGBoost Library (libxgboost.so) could not be loaded.
Likely causes:* OpenMP runtime is not installed- vcomp140.dll or libgomp-1.dll for Windows- libomp.dylib for Mac OSX- libgomp.so for Linux and other UNIX-like OSesMac OSX users: Run `brew install libomp` to install OpenMP runtime.* You are running 32-bit Python on a 64-bit OSError message(s): ['dlopen: cannot load any more object with static TLS']

解决办法:
在脚本最开头加如下代码

# 添加在最顶部
import ctypes
import os# 强制预加载关键库(先于任何其他导入)
# ctypes.CDLL('libgomp.so.1', mode=ctypes.RTLD_GLOBAL)
# 强制预加载 OpenMP 库
try:ctypes.CDLL('libgomp.so.1', mode=ctypes.RTLD_GLOBAL)
except OSError:# 如果上述失败,尝试指定具体路径ctypes.CDLL('/usr/anaconda3/envs/py37/lib/libgomp.so.1', mode=ctypes.RTLD_GLOBAL)ctypes.CDLL('libpthread.so.0', mode=ctypes.RTLD_GLOBAL)# 设置OpenMP环境变量
os.environ["OMP_NUM_THREADS"] = "1"
os.environ["MKL_NUM_THREADS"] = "1"
os.environ["KMP_INIT_AT_FORK"] = "FALSE"# # 恢复导入路径(如有必要)
# import sys
# sys.path.insert(0, '/usr/anaconda3/envs/py37/lib/python3.7/site-packages')# 以下是你的原始代码...
import sklearn  # 这行应该在预加载后
import xgboost

相关文章:

  • 【Ubuntu崩溃修复】
  • 新品推广的四个阶段,做好新品推广从这四个方面出发
  • 【机械视觉】Halcon—【十二、边缘提取】
  • 达梦数据库CASE WHEN条件
  • PP-OCRv5 ubuntu20.04 OCR识别服务
  • 博科FC交换机管理IP地址用户名密码
  • MCP和Function Calling
  • SpringCloud优势
  • 力扣面试150题--蛇梯棋
  • Linux初步介绍
  • C#中LINQ技术:自然语言集成与统一数据操作的艺术
  • 【题解-洛谷】B4292 [蓝桥杯青少年组省赛 2022] 路线
  • 3D Web轻量化引擎HOOPS Communicator赋能一线场景,支持本地化与动态展示?
  • C语言中的段错误(Segmentation Fault):底层原理及解决方法
  • 蓝桥杯 回文日期
  • BIO、NIO、AIO的区别
  • GAMES202-高质量实时渲染(Assignment 4)
  • 你应该使用的 php 加解密函数
  • 【开发技术】Abp.vnext下的JWT处理,添加多种认证处理方式
  • ES Serverless 8.17王牌发布:向量检索「火力全开」,智能扩缩「秒级响应」!
  • 设计吧 网站/谷歌seo推广培训班
  • 化妆品销售网站开发与设计/国内免费发布产品的平台
  • 买奢侈品代工厂做的产品的网站名/今日国内新闻最新消息10条
  • 公司外贸网站/网络营销推广机构
  • 网站构建的滚动新闻怎么做/seo在线教学
  • java做网站代码/关键词排名点击软件首页