kadrlica / skymap

Python skymaps based on basemap
MIT License
39 stars 15 forks source link

KeyError: 'PROJ_LIB' on cori #15

Closed zdu863 closed 4 years ago

zdu863 commented 4 years ago

Hi, I'm trying to install skymap on cori and use the environment as a Jupyter notebook kernel. I did,

conda create -n skymap numpy scipy pandas matplotlib basemap astropy ephem healpy nose -c conda-forge
source activate skymap
pip install skymap
conda install -q ipykernel -c conda-forge --no-update-deps
python -m ipykernel install --user --name skymap --display-name skymap

but when I ran a notebook using the created kernel, import skymap gave me an error message KeyError: 'PROJ_LIB'.

fjaviersanchez commented 4 years ago

@zdu863 this is a problem with anaconda/basemap rather than skymap.

A possible solution is to do this before importing skymap.

import os

def default_proj_lib():
    proj_lib = os.getenv('PROJ_LIB')
    if proj_lib not in (None, 'PROJ_LIB'):
        return proj_lib
    try:
        import conda
    except ImportError:
        conda = None
    if conda is not None or os.getenv('CONDA_PREFIX') is None:
        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')
        if os.path.exists(proj_lib):
            return proj_lib
        return None
    return None
os.environ['PROJ_LIB']=default_proj_lib()
kadrlica commented 4 years ago

That solution looks good to me. I've also seen some success with explicitly installing proj4 with the rest of the basemap dependencies.

zdu863 commented 4 years ago

Thanks, that worked out for me, after I downgraded proj4 to 5.2.0 and did os.environ['PROJ_LIB']=default_proj_lib().

kadrlica commented 4 years ago

Thanks for the update. I'm going to close this issue with the note that problems with proj4 are one of the reasons that we would like to move from basemap to cartopy (see issue #13).