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

使用 NumPy 及其相关库(如 pandas、scikit-learn 等)时,由于 NumPy 的版本不兼容或者某些依赖库与 NumPy 的版本不匹配

题意:

numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

问题背景:

I want to call my Python module from the Matlab. I received the error:

Error using numpy_ops>init thinc.backends.numpy_ops

Python Error:

ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject.

The Python script is as follows

import spacy
def text_recognizer(model_path, text):
try:# Load the trained modelnlp = spacy.load(model_path)print("Model loaded successfully.")# Process the given textdoc = nlp(text)ent_labels = [(ent.text, ent.label_) for ent in doc.ents]return ent_labels

The Matlab script is as follows

% Set up the Python environment
pe = pyenv;
py.importlib.import_module('final_output');% Add the directory containing the Python script to the Python path
path_add = fileparts(which('final_output.py'));
if count(py.sys.path, path_add) == 0insert(py.sys.path, int64(0), path_add);
end
% Define model path and text to process
model_path = 'D:\trained_model\\output\\model-best';
text = 'Roses are red';
% Call the Python function
pyOut = py.final_output.text_recognizer(model_path, text);
% Convert the output to a MATLAB cell array
entity_labels = cell(pyOut);
disp(entity_labels);

I found one solution to update Numpy, what I did, but nothing changed. I am using Python 3.9 and Numpy version 2.0.0

The error was received when I tried to call the Python module using a Matlab script.

How can I fix the issue?

问题解决:

The reason is that pandas defines its numpy dependency freely as "anything newer than certain version of numpy". The problem occured, when numpy==2.0.0 has been released on June 16th 2024, because it is no longer compatible with your pandas version.

The solution is to pin down the numpy version to any before the 2.0.0. Today it could be (this is the most recent numpy 1 release):

numpy==1.26.4

To be added in your requirements or to the pip command you use (but together with installing pandas).

Nowadays pip is very flexible and can handle the issue flawesly. You just need to ask it to install both pandas and numpy of given versions in the same pip install invocation.

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 局域网如何进行内网连接和外网连接
  • 语音识别概述
  • 基于Jetpack Compose实现的Android Preference
  • 代码随想录(day6)哈希表-求两个数组的交集
  • 土壤分析仪:解密土壤之奥秘的科技先锋
  • 探索 Java 8 新特性:函数式接口
  • ES6 Generator函数的语法 (七)
  • Android 自定义Edittext 和TextView 提示文字和填入内容不同的粗细组件
  • 【Linux】shell基础知识点(updating)
  • 欧科云链研究院:坎昆升级后,Layer2变得更好了吗?
  • 解决了一个java Bug:Exception in thread “main“ java.lang.NullPointerException
  • [Hello-algo] 复杂度分析
  • 【数据基础】— B树
  • IOT 可编程控制系统
  • 智慧校园信息化大平台整体解决方案PPT(75页)
  • [Vue CLI 3] 配置解析之 css.extract
  • Android 架构优化~MVP 架构改造
  • Android优雅地处理按钮重复点击
  • Angular 响应式表单 基础例子
  • - C#编程大幅提高OUTLOOK的邮件搜索能力!
  • github指令
  • Laravel5.4 Queues队列学习
  • PHP 的 SAPI 是个什么东西
  • RxJS 实现摩斯密码(Morse) 【内附脑图】
  • Traffic-Sign Detection and Classification in the Wild 论文笔记
  • 从0到1:PostCSS 插件开发最佳实践
  • 从tcpdump抓包看TCP/IP协议
  • 互联网大裁员:Java程序员失工作,焉知不能进ali?
  • 基于组件的设计工作流与界面抽象
  • 坑!为什么View.startAnimation不起作用?
  • 离散点最小(凸)包围边界查找
  • 利用阿里云 OSS 搭建私有 Docker 仓库
  • 区块链技术特点之去中心化特性
  • 使用parted解决大于2T的磁盘分区
  • 手写双向链表LinkedList的几个常用功能
  • (09)Hive——CTE 公共表达式
  • (1)(1.19) TeraRanger One/EVO测距仪
  • (26)4.7 字符函数和字符串函数
  • (6)STL算法之转换
  • (day 2)JavaScript学习笔记(基础之变量、常量和注释)
  • (JSP)EL——优化登录界面,获取对象,获取数据
  • (SERIES12)DM性能优化
  • (代码示例)使用setTimeout来延迟加载JS脚本文件
  • (待修改)PyG安装步骤
  • (附源码)spring boot基于小程序酒店疫情系统 毕业设计 091931
  • (每日一问)操作系统:常见的 Linux 指令详解
  • (牛客腾讯思维编程题)编码编码分组打印下标(java 版本+ C版本)
  • (四)linux文件内容查看
  • (学习总结16)C++模版2
  • (转)程序员技术练级攻略
  • .equals()到底是什么意思?
  • .net core webapi 大文件上传到wwwroot文件夹
  • .Net Core/.Net6/.Net8 ,启动配置/Program.cs 配置
  • .net core使用ef 6
  • .Net 基于MiniExcel的导入功能接口示例