matplotlib / basemap

Plot on map projections (with coastlines and political boundaries) using matplotlib
MIT License
775 stars 392 forks source link

Error when used plot: "from mpl_toolkits.basemap import Basemap" #448

Closed xuanhoatrieu closed 2 years ago

xuanhoatrieu commented 5 years ago

I am trying to plot the map of OMI data, but I got the error: " File "", line 1, in runfile('D:/Paper_NOx/Training/session_3_code_data/read_and_map_omi_no2_so2.py', wdir='D:/Paper_NOx/Training/session_3_code_data')

File "D:\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile execfile(filename, namespace)

File "D:\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "D:/Paper_NOx/Training/session_3_code_data/read_and_map_omi_no2_so2.py", line 17, in from mpl_toolkits.basemap import Basemap

File "D:\Anaconda3\lib\site-packages\mpl_toolkits\basemap__init__.py", line 155, in pyproj_datadir = os.environ['PROJ_LIB']

File "D:\Anaconda3\lib\os.py", line 678, in getitem raise KeyError(key) from None

KeyError: 'PROJ_LIB'" I search and do follow the same issues from other guy but it not working with me. Please give me the solution to fix it. Thank you so much.

tomerburg commented 5 years ago

I recently ran into this problem as well, and was able to solve it by setting the PROJ_LIB path manually in the basemap init file, just before line 155:

os.environ['PROJ_LIB'] = 'C:/Users/Tomer/Anaconda3/pkgs/pyproj-1.9.5.1-py36_0/Lib/site-packages/pyproj/data' pyproj_datadir = os.environ['PROJ_LIB']

I was able to get basemap working after that, but am unable to plot counties (I posted about this on a separate thread). I'm unsure if these problems are related or separate from each other.

xuanhoatrieu commented 5 years ago

It not working with me. please help me. I already uninstall anaconda and try it again but it still a problem

actcheng commented 4 years ago

It seems to be a problem with conda.

You can check if the espg file is located in the folder specified in the os.environ['PROJ_LIB'] directory. In my case, the "data" directory didn't even exist. So I downloaded the file from basemap github and put into the directory.

Then it worked for me. Hope this helps.

gerazov commented 4 years ago

I installed basemap with conda install basemap and I had the same issue FileNotFound for the epsg file. @actcheng's solution solved it - thanks! But the conda install should be fixed.

Btw this issue seems to be a reoccurrence from here - #430

molinav commented 2 years ago

I am closing this since this seems to be the same as #483 and it is a problem of the Anaconda packaging and not from basemap itself (at least in the latest versions).