Basemap import error in PyCharm — KeyError: 'PROJ_LIB'

前端 未结 9 577
生来不讨喜
生来不讨喜 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 02:57

    This seems to be a common issue. There are several bug reports about it

    • basemap/issues/419,
    • https://github.com/matplotlib/basemap/issues/428
    • basemap/issues/428

    I had run into this error myself, and for me the solution was to uninstall basemap 1.2, then install basemap 1.1 from an old wheel file I still had lying around and then install basemap 1.2 again. I honestly have no idea why that worked though.

    Also from those issues above there are all kinds of other solutions that people have reported to work for them. Hopefully one of them fits here as well.

    0 讨论(0)
  • 2020-11-30 02:58

    Proj4 easy solution to fix on pycharm is goto setting-> project interpreter -> + -> write proj4 in the search field and install.

    0 讨论(0)
  • 2020-11-30 02:59

    Following mewahl's comment I've added to my .bashrc (I use bash):

    export PROJ_LIB=/path/to/your/instalation/of/anaconda/share/proj/

    and now basemap (and others work).

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

    I was not able to solve this problem but I was able to find an alternate, use CartoPy. basemap is being maintained for python 2.7 users. CartoPy is a better alternative

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

    You have to set the path of Proj lib as in newer version , this path has been replaced. Write below two lines of code before importing matplot_toolkits

      ### For Window's Users
          import os
          os.environ['PROJ_LIB'] = r'C:\Users\XXXXX\Anaconda3\pkgs\proj4-5.2.0- 
          ha925a31_1\Library\share'
    

    To find the path of Proj_lib , just search epsg and then copy this epsg file location and put in proj_lib . Your Problem will be solved.

      ### For Linux's Users
      import os
      os.environ['PROJ_LIB'] = r'/home/XXXXXX/anaconda3/pkgs/proj4-5.2.0- 
      he6710b0_1/share/proj'
    
    0 讨论(0)
  • 2020-11-30 03:11

    The answer is from Github and it worked for me.

    import os
    import conda
    
    conda_file_dir = conda.__file__
    conda_dir = conda_file_dir.split('lib')[0]
    proj_lib = os.path.join(os.path.join(conda_dir, 'share'), 'proj')
    os.environ["PROJ_LIB"] = proj_lib
    
    from mpl_toolkits.basemap import Basemap
    
    0 讨论(0)
提交回复
热议问题