Python basemap module impossible to import

冷暖自知 提交于 2019-11-28 08:18:22

I was facing this issue and I was able to solve it using anaconda

After activating my profile

source activate MyProfileName
conda install basemap

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# setup Lambert Conformal basemap.
# set resolution=None to skip processing of boundary datasets.
m = Basemap(width=12000000,height=9000000,projection='lcc',
            resolution=None,lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.)
m.bluemarble()
plt.show()

I was in the same situation until a minute ago, installing it trough this made the trick:

sudo apt-get install libgeos-3.5.0
sudo apt-get install libgeos-dev
sudo pip install https://github.com/matplotlib/basemap/archive/master.zip

I had the same issue; trying to access basemap using sys would produce that error. But this worked for me:

import mpl_toolkits
mpl_toolkits.__path__.append('/usr/lib/python2.7/dist-packages/mpl_toolkits/')
from mpl_toolkits.basemap import Basemap

I do not use Anaconda, using MacOS, and I have found this solution works for me. I guess it is straight forward, and should work with both Linux and MacOs.

https://stackoverflow.com/a/53171723/2570842

brew install geos
pip3 install https://github.com/matplotlib/basemap/archive/master.zip

For Ubuntu,

sudo apt-get install geos
sudo pip3 install https://github.com/matplotlib/basemap/archive/master.zip

Download it from here and install it manually. Make sure to download the right version(i.e. if you are Python3.6 then download basemap‑1.2.0‑cp36‑cp36m‑win_amd64.whl)

Reference: https://stackoverflow.com/a/33020524/8730201

I was able to get basemap working through the following steps. Note that I did a --user install.

  1. Create shallow clone of basemap (git clone --depth 1 git@github.com:matplotlib/basemap.git) or extract the tarball of the current version.
  2. Install the necessary prerequisite libraries (on Ubuntu, libgeos-dev, libproj-dev, libgeos++-dev, proj-data, proj-bin, libgeos-c1v5, libgeos, libproj12, I think).
  3. pip install --user pyproj matplotlib geos (not actually sure if geos is necessary).

Now, here's where I had to improvise a little bit. When I install basemap using python setup.py install, it creates a new egg directory among my Python packages. That directory contains an mpl_toolkits subdirectory which duplicates a separate mpl_toolkits directory installed by matplotlib.

So, instead, I did

python setup.py build_ext --inplace
cp -a lib/mpl_toolkits/basemap /my/python/packages/dir/mpl_toolkits/basemap
cp lib/_geoslib.so /my/python/packages/dir

I am now able to run examples like simpletest.py.

I followed this answer:

https://stackoverflow.com/a/43234894/3818277

Though, I can have wrongly installed mpl_toolkits (or I do not know), in my case I found out, that basemap is located in pymodules like that:

    mpl_toolkits.__path__.append('/usr/lib/pymodules/python2.7/mpl_toolkits/')
    from mpl_toolkits.basemap import Basemap

So this worked for me on ubuntu 14.04 LTS.

If you're using Anaconda, it has a package for basemap

conda install basemap

(pip doesn't have the basemap package any more)

OR

If you using Ubuntu system you can try

apt install python3-mpltoolkits.basemap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!