首页 > 解决方案 > 在 Ubuntu 18.04 上使用 Python3.6 安装底图

问题描述

在过去的几个小时里,我一直在尝试启动并运行Basemap 。按照本教程,我运行:

conda install basemap在我venv的 Pycharm 上。安装按计划进行,我在终端中收到一条消息,说明 basemap-1.2.0 已安装。运行我的程序时:

Downloading and Extracting Packages
proj4-5.0.1          |  7.0 MB | ############################################################################################################################################################################################################################### | 100% 
certifi-2018.10.15   |  139 KB | ############################################################################################################################################################################################################################### | 100% 
libgcc-ng-8.2.0      |  7.6 MB | ############################################################################################################################################################################################################################### | 100% 
libstdcxx-ng-8.2.0   |  2.9 MB | ############################################################################################################################################################################################################################### | 100% 
pyshp-1.2.12         |   35 KB | ############################################################################################################################################################################################################################### | 100% 
pyproj-1.9.5.1       |   64 KB | ############################################################################################################################################################################################################################### | 100% 
openssl-1.0.2p       |  3.5 MB | ############################################################################################################################################################################################################################### | 100% 
conda-4.5.11         |  1.0 MB | ############################################################################################################################################################################################################################### | 100% 
geos-3.6.2           |  1.6 MB | ############################################################################################################################################################################################################################### | 100% 
basemap-1.2.0        | 15.2 MB | ############################################################################################################################################################################################################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done


 Traceback (most recent call last):
  File "/home/PycharmProjects/first_prog/venv/test.py", line 5, in <module>
    from mpl_toolkits.basemap import Basemap
ModuleNotFoundError: No module named 'mpl_toolkits.basemap'

我看到一些答案说 Basemap 应该从源安装而不是使用 conda,所以我从源安装 Basemap。

我首先安装了geos。从 basemap-1.xx 目录,我切换到 geos 目录并设置 GEOS_DIR 环境变量。

basemap-1.x.x $ cd geos-3.3.3
basemap-1.x.x/geos-3.3.3 $ export GEOS_DIR=~/
basemap-1.x.x/geos-3.3.3 $ ./configure --prefix=$GEOS_DIR

basemap-1.x.x/geos-3.3.3 $ make  <---- ERROR HERE
basemap-1.x.x/geos-3.3.3 $ make install

运行make命令时出现此错误:

Makefile:373: recipe for target 'IndexedPointInAreaLocator.lo' failed
make[4]: *** [IndexedPointInAreaLocator.lo] Error 1
make[4]: Leaving directory '/home/Downloads/basemap-1.0.7/geos-3.3.3/src/algorithm/locate'
Makefile:392: recipe for target 'check-recursive' failed
make[3]: *** [check-recursive] Error 1
make[3]: Leaving directory '/home/Downloads/basemap-1.0.7/geos-3.3.3/src/algorithm/locate'
Makefile:444: recipe for target 'check-recursive' failed
make[2]: *** [check-recursive] Error 1
make[2]: Leaving directory '/home/Downloads/basemap-1.0.7/geos-3.3.3/src/algorithm'
Makefile:476: recipe for target 'check-recursive' failed
make[1]: *** [check-recursive] Error 1
make[1]: Leaving directory '/home/Downloads/basemap-1.0.7/geos-3.3.3/src'
Makefile:368: recipe for target 'check-recursive' failed
make: *** [check-recursive] Error 1

此错误有多种解决方案,但均未奏效。我尝试使用CheckInstall,遵循这个线程,尝试使用DNF,遵循这些命令等等,但没有任何效果。

ImportError: Ubuntu 16.04.3 - 在 python 2.7.12 上安装底图模块是相关的,但错误仍然存​​在。

安装 Basemapmake错误有关,但make: *** [all-recursive] Error 1仍然存在。

我究竟做错了什么?安装Basemap真的这么难吗?我完全被困在这里,非常感谢任何帮助。

标签: pythonmatplotlib

解决方案


我发现这个脚本对我有用。它与其他答案略有不同,因为它无需单独下载即可下载和安装底图。

pip install --upgrade --user matplotlib numpy pyproj pyshp OWSLib Pillow 
sudo apt-get update 
sudo apt install libgeos-dev 
pip install --user https://github.com/matplotlib/basemap/archive/master.zip

推荐阅读