Basemap import error in PyCharm — KeyError: 'PROJ_LIB'

前端 未结 9 578
生来不讨喜
生来不讨喜 2020-11-30 02:27

I tried to use Basemap package to plot a map by PyCharm, but I got something wrong with

from mpl_toolkits.basemap import Basemap`

And the T

相关标签:
9条回答
  • 2020-11-30 03:11

    This worked for me:

    import os
    os.environ["PROJ_LIB"] = os.path.join(os.environ["CONDA_PREFIX"], "share", "proj")
    

    This extends @Yusuf Baktir 's answer by omitting hard-coding the path to the epsg file. This way the code works on any machine that has conda installed (and activated of course).

    0 讨论(0)
  • 2020-11-30 03:14

    I faced same problem. I installed anaconda and install conda install -c anaconda basemap.

    I used Anaconda built in IDE named "Spyder". Spyder is better than pycharm. only problem with spyder is lack of intellisense.

    I solved problem of Proj4 by setting path.

    Other problem kernel restarting when loading of .json larger file dataset.

    I use notepad++ and 010 editor to re-save file in small chunks and at last I merged all outputs.

    0 讨论(0)
  • 2020-11-30 03:22

    For Windows 10 with Anaconda + Python 3.71 (and I'm sure other Python 3 versions and Windows 7/8), you can tell Basemap where Proj4's "epsg" file is to succeed. I don't have an "environment" or whatever because it's too much work to figure out - so I didn't have an anaconda\share\proj area (as far as I could discern why I didn't have it).

    But, what Basemap wants is the file "epsg", search the Anaconda directory for it with Windows Explorer. If it doesn't find it, install Proj4 by opening the "Anaconda Prompt" and typing in:

    conda install -c conda-forge proj4
    

    If it finds it, it should be in something like:

    C:\Utilities\Python\Anaconda\Library\Share (it's where mine was, as well as \pkgs\ places where I guess it puts the package itself - and those can work too if need be, I used them at first, but the library one should work through updates better (maybe)).

    Use the following code before importing Basemap and it'll work. Sets the environment variable PROJ_LIB to wherever epsg is and then Basemap can be happy.

    import os
    os.environ["PROJ_LIB"] = "C:\\Utilities\\Python\\Anaconda\\Library\\share"; #fixr
    from mpl_toolkits.basemap import Basemap
    

    As a nice bonus, to get hi-res data of Basemap, which Anaconda doesn't include in the Basemap install to start, type into "Anaconda Prompt":

    conda install -c conda-forge basemap-data-hires
    
    0 讨论(0)
提交回复
热议问题