一、miniconda3安装
1.miniconda3文件下载
按照时间排序,下载最新版本。下载地址:https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/
2.安装
sudo chmod +x Miniconda3-py39_4.10.3-Linux-x86_64.sh #赋予执行权限
sudo ./Miniconda3-py39_4.10.3-Linux-x86_64.sh #执行文件
显示更多信息,一直回车
是否接受licese terms 输入yes
是否初始化,yes
安装成功
3.配置环境
dedit ~/.bashrc
然后向文件末尾加入如下语句以修改环境变量。修改完成后保存文件并退出,然后重启终端使其生效(或者使用 source ~.bashrc更新):
export PATH=/home/用户名/miniconda3/bin:$PATH
4.测试是否安装成功
conda --version
conda 4.10.3
二、配置pygmt
1.创建环境
conda create --name pygmt --channel conda-forge pygmt
如果出现问题,确认是否关闭VPN
2.激活环境
conda activate pygmt
3.测试
forge pygmt安装了python3.9+pygmt的虚拟环境。直接输入import pygmt指令后,出现如下错误:
网上搜索发现原因是没有进入python环境。
解决办法:输入python后,再输入 import pygmt指令即可。
(pygmt) andyfay@andyfay-PC:~/software$ python
Python 3.9.7 | packaged by conda-forge | (default, Sep 23 2021, 07:28:37)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygmt
>>> pygmt.show_versions()
PyGMT information:
version: v0.4.1
System information:
python: 3.9.7 | packaged by conda-forge | (default, Sep 23 2021, 07:28:37) [GCC 9.4.0]
executable: /home/andyfay/software/miniconda3/envs/pygmt/bin/python
machine: Linux-5.10.18-amd64-desktop-x86_64-with-glibc2.28
Dependency information:
numpy: 1.21.2
pandas: 1.3.3
xarray: 0.19.0
netCDF4: 1.5.7
packaging: 21.0
ghostscript: 9.54.0
gmt: 6.2.0
GMT library information:
binary dir: /home/andyfay/software/miniconda3/envs/pygmt/bin
cores: 8
grid layout: rows
library path: /home/andyfay/software/miniconda3/envs/pygmt/lib/libgmt.so
padding: 2
plugin dir: /home/andyfay/software/miniconda3/envs/pygmt/lib/gmt/plugins
share dir: /home/andyfay/software/miniconda3/envs/pygmt/share/gmt
version: 6.2.0
继续测试
>>> fig=pygmt.Figure()
>>> fig.coast(region="g",frame=True, shorelines=1)
>>> fig.show()
完成
退出python模式
exit()
4.运行py脚本
首先要保证激活pygmt,在这个模式里输入代码:
conda activate pygmt
python3 first_figure.py
即可出现脚本的图像
备注
- 安装模块
运行下面代码查看python模块,缺失的话,安装
python -m pip list
缺失以下模块
(1)matplotlib, Matplotlib 是 Python 的绘图库。 它可与 NumPy 一起使用,提供了一种有效的 MatLab 开源替代方案。 它也可以和图形工具包一起使用,如 PyQt 和 wxPython。
(2)skiamge 需要改名字scikit-image
(3)statsmodels
pip 安装:
pip install matplotlib scikit-image statsmodels
(4)cm_utils (https://github.com/craigmillernz)
直接安装setup.py出错,
python setup.py install
error: package directory 'cm_utils' does not exist
创建 'cm_utils' 文件夹,将 'cm_utils.py'复制进去 ,再次安装即可。然后复制两个文件夹进入/home/andyfay/software/miniconda3/envs/pygmt/lib/python3.9/site-packages
- deepin 鼠标变成十字,无法点击
原因:不小心在终端中import了python的包
解决方法: 输入ps -aux | grep import
找到进程,然后kill -9 id
杀掉进程就ok了
- 换源
sudo dedit ~/.condarc
弹出文本添加
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- 安装指定版本包
(1)pip
pip install pymc3==3.10.0
(2) conda
conda install pymc3=3.10.0