简体   繁体   中英

Fixing “pyproj import _datadir” error: specified module could not be found

I am doing a Python project in Jupyter Notebook. Everything was fine until I tried to use Basemap, which I have installed in the Anaconda terminal for my environment using:

conda install -c anaconda basemap

I attempt to import:

from mpl_toolkits.basemap import Basemap as Basemap

which gives the error:

ImportError                               Traceback (most recent call last)
<ipython-input-17-c19d6352b4bd> in <module>
      3 #from pyproj import _datadir
      4 #from pyproj import _datadir, datadir
----> 5 from mpl_toolkits.basemap import Basemap as Basemap

~\Anaconda3\envs\name_of_my_env\lib\site-packages\mpl_toolkits\basemap\__init__.py in <module>
     44 from matplotlib.lines import Line2D
     45 from matplotlib.transforms import Bbox
---> 46 import pyproj
     47 from mpl_toolkits.axes_grid1 import make_axes_locatable
     48 from matplotlib.image import imread

~\Anaconda3\envs\name_of_my_env\lib\site-packages\pyproj\__init__.py in <module>
     48 import warnings
     49 
---> 50 from pyproj import _datadir
     51 from pyproj._list import (  # noqa: F401
     52     get_angular_units_map,

ImportError: DLL load failed: The specified module could not be found.

Thinking there was an issue with pyproj I installed:

conda install -c conda-forge pyproj
conda install -c conda-forge/label/broken pyproj

This didn't fix anything so I installed:

conda install -c conda-forge geopandas

for good measure, but even import geopandas does not work, giving:

ImportError                               Traceback (most recent call last)
<ipython-input-18-5f9c797680a3> in <module>
      1 import pandas as pd
----> 2 import geopandas
      3 #from pyproj import _datadir
      4 #from pyproj import _datadir, datadir
      5 from mpl_toolkits.basemap import Basemap as Basemap

~\Anaconda3\envs\name_of_my_env\lib\site-packages\geopandas\__init__.py in <module>
----> 1 from geopandas.geoseries import GeoSeries  # noqa
      2 from geopandas.geodataframe import GeoDataFrame  # noqa
      3 from geopandas.array import _points_from_xy as points_from_xy  # noqa
      4 
      5 from geopandas.io.file import read_file  # noqa

~\Anaconda3\envs\name_of_my_env\lib\site-packages\geopandas\geoseries.py in <module>
      7 from pandas.core.internals import SingleBlockManager
      8 
----> 9 from pyproj import CRS, Transformer
     10 from shapely.geometry.base import BaseGeometry
     11 from shapely.ops import transform

~\Anaconda3\envs\name_of_my_env\lib\site-packages\pyproj\__init__.py in <module>
     48 import warnings
     49 
---> 50 from pyproj import _datadir
     51 from pyproj._list import (  # noqa: F401
     52     get_angular_units_map,

ImportError: DLL load failed: The specified module could not be found.

Clearly, the error is with pyproj import _datadir, but I have no clue how to fix this.

I know it's not an ideal solution, but the only way I could manage to solve this issue was to completely uninstall Anaconda , then reinstall Anaconda and and my packages in a new environment. Seeing as you posted two days ago, I'm sure you've probably already resorted to this by now.

Things I tried before the reinstall:

  1. conda update conda
  2. conda install anaconda=2020.02
  3. Created a fresh environment, installed only pyproj via conda install -c conda-forge pyproj . During installation, I got a warning that I should manually remove a "libssl-1_1-x64.dll" file because conda apparently could not do it. After manually removing, I still had the useless ImportError .

I did not get this error in an environment that used geopandas 0.6.3, but I needed to update to 0.7.0 to use the geopandas.clip() function. After this update is when I started experiencing this problem with pyproj . Again, not an ideal answer, but I was able to "solve" the problem in my case by uninstalling and reinstalling.

Ran into this problem myself. Here is what fixed it for me.

When pyproj looks for the _datadir module, it is looking for your-env/Lib/site-packages/pyproj/_datadir.pyd

When I browsed to that directory, I found that all of the *.pyd files were named *.cp38-win_amd64.pyd This seems common enough in other packages, and perhaps someone with greater expertise can speak to why it does or doesn't appear in various package filenames.

Regardless, deleting that bit of text between the two . characters seemed to do it, ie, renaming _datadir.cp38-win_amd64.pyd > _datadir.pyd .

I tested a number of operations using geopandas after editing the filenames, and everything worked as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM