CentOS7 Linux 安装可视化所需软件包(mpltoolkits.basemap)

目录

      • 一、pip命令安装matplotlib、pandas
      • 二、安装mpltoolkits.basemap
        • 1、步骤
        • 2、遇到的问题
          • 2.1.AttributeError: 'NoneType' object has no attribute
          • 2.2.ModuleNotFoundError: No module named 'mpl_toolkits.axes_grid1'
          • 2.3.测试时报错ImportError: cannot import name 'basemap' from 'mpl_toolkits.basemap'
          • 2.4.WARN:Service 'SparkUI' could not bind on port

一、pip命令安装matplotlib、pandas

pip3 install matplotlib
pip3 install matplotlib

二、安装mpltoolkits.basemap

1、步骤

(可结合阅读basemap-1.2.2rel文件夹里的REAME.md)

#解压
tar -zxvf basemap-1.2.2rel.tar.gz
#安装basemap依赖pyproj、geos
pip3 install pyproj
pip3 install geos
#修改配置
cd basemap-1.2.2rel/geos-3.3.3/
export GEOS_DIR=/usr/local
./configure --prefix=$GEOS_DIR
#编译
make
make install
#退出到basemap目录,安装
cd ..
python setup.py install

参考:
python如何安装basemap
Basemap–1--Linux下的安装

(这里我用pip3 show geos查看geos的目录,并将目录设置为相同目录)

$ pip3 show geos
Name: geos
......
Location: /home/.../site-packages

$ cd basemap-1.2.2rel/geos-3.3.3
$ export GEOS_DIR=/home/.../site-packages
$ ./configure --prefix=GEOS_DIR

2、遇到的问题

2.1.AttributeError: ‘NoneType’ object has no attribute

Error processing line 1 of /usr/local/python37/lib/python3.7/site-packages/matplotlib-3.5.0-py3.7-nspkg.pth: Traceback (most recent call last):
    File "/usr/local/python3.7/site.py", line 168, in addpackage
    File "", line 1, in 
    File "", line 580, in module_from_spec   AttributeError: 'NoneType' object has no attribute 'loader'

参考文章:AttributeError:“NoneType”对象没有属性“loader”,AttributeErrorNoneTypeobjecthasnoattributeloader
解决方法:将matplotlib-3.5.0-py3.7-nspkg.pth删掉,或改为备份:

mv matplotlib-3.5.0-py3.7-nspkg.pth matplotlib-3.5.0-py3.7-nspkg.pth.bak
2.2.ModuleNotFoundError: No module named ‘mpl_toolkits.axes_grid1’

from mpl_toolkits.axes_grid1 import make_axes_locatable
ModuleNotFoundError: No module named ‘mpl_toolkits.axes_grid1’

解决办法:升级matplotlib

pip install matplotlib --upgrade 如果更新的时候遇到uninstall
six库报错,那么可以修改命令如下,跳过six的更新:
pip install matplotlib --upgrade --ignore-installed six

参考:报错:No module named mpl_toolkits解决方案

2.3.测试时报错ImportError: cannot import name ‘basemap’ from ‘mpl_toolkits.basemap’

测试文件test.py:

import pyproj
import geos
from mpl_toolkits.basemap import basemap
import pandas as pd 

import matplotlib.pyplot as plt

print("1")

Traceback (most recent call last):
File “test.py”, line 3, in
from mpl_toolkits.basemap import basemap
ImportError: cannot import name ‘basemap’ from ‘mpl_toolkits.basemap’ (/usr/local/python3.7/site-packages/basemap-1.2.1-py3.7-linux-x86_64.egg/mpl_toolkits/basemap/init.py)

解决方法:

import pyproj
import geos
from mpl_toolkits import basemap
import pandas as pd 

import matplotlib.pyplot as plt

print("1")

运行结果:
在这里插入图片描述

2.4.WARN:Service ‘SparkUI’ could not bind on port

WARN util.Utils: Service ‘SparkUI’ could not bind on port 4040. Attempting port 4041.

上次运行Spark文件后未关闭端口。
解决办法:查看对应端口,依次关闭

你可能感兴趣的:(虚拟机一定要记得快照,spark,linux)