pycharm导入cartopy,报错ImportError: DLL load failed while importing trace: 找不到指定的模块。

这是我的代码

from matplotlib import pyplot as plt
import numpy as np
import matplotlib as mpl
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import matplotlib.ticker as mticker
import netCDF4 as nc
import matplotlib.pyplot as plt

mpl.rcParams["font.family"] = 'Arial'  #默认字体类型
mpl.rcParams["mathtext.fontset"] = 'cm' #数学文字字体
mpl.rcParams["font.size"] = 15   #字体大小
mpl.rcParams["axes.linewidth"] = 1   #轴线边框粗细(默认的太粗了

f1=nc.Dataset('3.nc') #打开.nc文件

#读取文件中的数据
lat = f1.variables['latitude'][:]
lon = f1.variables['longitude'][:]
time = f1.variables['time'][:]
u1000 = f1.variables['u'][:]#下载的1000hPa的风场数据
v1000 = f1.variables['v'][:]

lon2d, lat2d = np.meshgrid(lon, lat)
u1000_aim = u1000
v1000_aim = v1000

proj = ccrs.PlateCarree(central_longitude=180)
fig = plt.figure(figsize=(10, 8), dpi=550)  # 创建画布
ax = fig.subplots(1, 1, subplot_kw={'projection': proj})  # 创建子图

u_all = u1000_aim[0, :, :]
v_all = v1000_aim[0, :, :]

#-----------绘制地图-------------------------------------------

#ax.add_feature(cfeature.LAND.with_scale('50m'))####添加陆地######
ax.add_feature(cfeature.COASTLINE.with_scale('50m'))#####添加海岸线#########
# ax.add_feature(cfeature.OCEAN.with_scale('50m'))######添加海洋########

#-----------添加经纬度---------------------------------------
extent=[90,-180,-90,180]##经纬度范围
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, linewidth=0., color='k', alpha=0.5, linestyle='--')
dlon, dlat = 45, 30   #设置步长
xticks = np.arange(0, 360.1, dlon)  #设置绘图范围
yticks = np.arange(-90, 90.1, dlat)
ax.set_xticks(xticks, crs=ccrs.PlateCarree())  #图幅设置坐标轴刻度
ax.set_yticks(yticks, crs=ccrs.PlateCarree())
ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=True))  #设置坐标轴刻度标签格式
ax.yaxis.set_major_formatter(LatitudeFormatter())
ax.set_extent(extent)     #显示所选择的区域

#----------修改国界,并添加省界-----------------------------
#在这个网站上可以找到dat文件,https://gmt-china.org/data/
# with open('C:/Users/hj/.local/share/cartopy/shapefiles/natural_earth/physical/CN-border-La.dat') as src:
#     context = src.read()
#     blocks = [cnt for cnt in context.split('>') if len(cnt) > 0]
#     borders = [np.fromstring(block, dtype=float, sep=' ') for block in blocks]
# for line in borders:
#     ax.plot(line[0::2], line[1::2], '-', color='k',lw=0.3, transform=ccrs.Geodetic())

#-------------------plot---------------------------
#levels = np.arange(1004, 1032 + 1, 1)
#cb = ax.contourf(lon2d,lat2d,msl_all, levels=levels, cmap='Spectral_r',transform=ccrs.PlateCarree())

cq =ax.quiver(lon2d[::20,::20],lat2d[::20,::20],u_all[::20,::20],v_all[::20,::20],color='k',scale=250,zorder=10,width=0.002,headwidth=3,headlength=4.5,transform=ccrs.PlateCarree())

plt.savefig('pic.jpg', dpi=300)

img


安装cartopy,显示成功,并且显示有cartopy

img


img


但是在anaconda prompt里就没有cartopy

img


在anaconda prompt安装cartopy

img


img


安装pyproject.toml,显示成功

img


但安装后任然显示同样的问题

img


这种情况要怎么解决?

在使用PyCharm导入cartopy时遇到"ImportError: DLL load failed while importing trace: 找不到指定的模块"错误通常是由于缺少依赖库或环境配置问题引起的。下边是几种可能的解决方案:【1.】 确保已安装正确版本的cartopy:首先确认你安装了适用于你的Python版本的正确版本的cartopy。可以使用pip或conda来安装:

pip install cartopy

或者

conda install -c conda-forge cartopy

确保在虚拟环境中安装cartopy,尽量避免与其他库发生冲突。【2.】 检查缺失的依赖库:cartopy依赖于一些外部库,例如Proj、GEOS和Cython。确保这些库已正确安装并配置到你的环境中。可以尝试使用conda来安装这些依赖库:

conda install -c conda-forge proj geos cython

或者根据你的操作系统手动安装这些依赖库。【3.】 检查环境变量:确保你的环境变量设置正确,以便可以正确识别和加载依赖库。特别是在Windows操作系统中,你可能需要将相关库的路径添加到PATH环境变量中。

先要使用pip安装相应包才能使用啊