Reputation: 821
I am trying to use the Matplotlib Basemap toolkit but am running into a FileNotFoundError
related to epsg
when I try importing it.
I installed it using the following command:
conda install -c conda-forge basemap
Here's my import command:
from mpl_toolkits.basemap import Basemap
Here's the error:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-1-d9467465a3b6> in <module>
----> 1 from mpl_toolkits.basemap import Basemap
/anaconda3/lib/python3.7/site-packages/mpl_toolkits/basemap/__init__.py in <module>
154 # create dictionary that maps epsg codes to Basemap kwargs.
155 pyproj_datadir = os.environ['PROJ_LIB']
--> 156 epsgf = open(os.path.join(pyproj_datadir,'epsg'))
157 epsg_dict={}
158 for line in epsgf:
FileNotFoundError: [Errno 2] No such file or directory: '/anaconda3/share/proj/epsg'
I'm completely new to Basemap, so I'm not sure how to go about fixing this. I'm using Jupyter Notebook to run Python 3.7.3 on macOS Mojave 10.14.6.
Thanks in advance.
Upvotes: 1
Views: 6186
Reputation: 11
As said in another comment run this command in terminal or in the Anaconda executor thing (if you run it in Anaconda make sure you redo the single quotes part if you copy and paste the below):
$ find `conda info --base` -name epsg
When you run that command several file paths should come up. Before you import Basemap into your program put the following lines:
import os
os.environ['PROJ_LIB'] = '/Users/XXXXXXXX/opt/anaconda3/pkgs/proj4-5.2.0-h0a44026_1/share/proj/'
where the whole line in quotes is the filepath that appears from the first line of code (without the epsg/ at the end). The part in quotes above is what appeared for me. If no file paths come up or another issue arrises check out the github pages on this (just google the error) or try
conda install -c conda-forge proj4
Upvotes: 1
Reputation: 20593
You are looking for this file: https://github.com/matplotlib/basemap/blob/master/lib/mpl_toolkits/basemap/data/epsg
Your PROJ_LIB
env var does not appear to end with .../site-packages
.
Please refer to https://ctcoding.wordpress.com/2019/01/29/solved-proj_lib-error-when-installing-basemap-on-windows-using-anaconda/
Take a look at $ conda info --base
, and then run
$ find `conda info --base` -name epsg
to verify the file was installed in the intended directory.
Adjust PROJ_LIB
to point there.
Upvotes: 1