[Python]ImportError: DLL load failed奇怪的解决方式

问题描述

利用Python进行绘图,在导入xarray库(包括cartopy、matplotlib、Eof等)中突然报错

ImportError: DLL load failed while importing lib: 找不到指定的程序。

折腾了两天,试过网上分享的各种方法:pip,conda重装各种库、新建虚拟环境、重装anaconda与spyder等方法都无法解决问题。

奇怪的是:该报错在重新进入spyder后时有时无。


解决方案:

通过排除法发现:更改import的运行顺序可以在一定程度上解决问题

示例如下:

1.报错:进入新控制台时,先运行如下的代码,后续就会一直出现DLL load failed错误

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from eofs.standard import Eof
import pandas as pd 
import xarray as xr 
from scipy.interpolate import Rbf
from matplotlib import rcParams
from matplotlib.path import Path
from matplotlib.patches import PathPatch
import cartopy.crs as ccrs
import shapefile
from collections import Iterable
import geopandas as gpd
from shapely.geometry import Point as ShapelyPoint
from shapely.geometry import Polygon as ShapelyPolygon
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import cartopy.feature as cfeature

2.关掉原先的控制台,新建一个

3.先运行如下代码,不会出现DLL load failed错误,并且在该控制台下后续import其他库也不会报错

from matplotlib.path import Path
from matplotlib import rcParams
from matplotlib.patches import PathPatch
import shapefile
from collections import Iterable
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import cartopy.crs as ccrs
import geopandas as gpd
from shapely.geometry import Point as ShapelyPoint
from shapely.geometry import Polygon as ShapelyPolygon
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import cartopy.feature as cfeature

成功解决问题!

ImportError: DLL load failed是一种Python错误,它通常发生在导入某个模块时出现问题。这个错误信息表明Python无法加载所需的动态链接库(DLL)模块。根据引用和引用的信息,这个错误可能与导入matplotlib模块相关。一种可能的解决方法是检查是否已正确安装了matplotlib模块。你可以通过引用中提供的URL链接来下载和安装适合你操作系统和Python版本的matplotlib模块。另外,你还可以尝试更新或重新安装matplotlib模块以解决这个问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ImportError: DLL load failed: 不到指定的模块。](https://download.youkuaiyun.com/download/weixin_38637884/13742003)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [ImportErrorDLL load failed不到指定的模块。终极无敌解决方法!(点赞支持一下新手)](https://blog.youkuaiyun.com/fish_turtle/article/details/118638751)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值