一、在CentOS7系统上安装Python3
在anaconda官网下载()(Anaconda指的是一个开源的Python发行版本,是Python的包管理器和环境管理器)
下载linux安装包:Anaconda3-5.2.0-Linux-x86_64.sh,上传到服务器
执行“sh Anaconda3-5.2.0-Linux-x86_64.sh”进行安装
输入“yes”,进行许可证确认
输入“本地安装路径”,执行普通用户目录下安装(注意安装完成后,不要再更改anaconda路径了)
注意“同意安装程序在bashrc中添加环境变量”,安装完成后source ~/.bashrc
(export PATH="/home/xxx/usr/local/anaconda3/bin:$PATH")
输入“python3”测试成功与否
二、配置vim的Python3支持
通过设置~/.vimrc和在~/.vim添加插件,来实现有代码高亮、代码自动补全(pydiction-1.2.3)、代码自动提示(autocomplpop.vim)等,使vim接近IDE
三、Python3读取netcdf数据,并简单画图
1、添加conda清华源,加快安装速度
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls true
2、更新conda本身和自带库(前提:服务器可以连接外网)
conda update -n base conda
conda upgrade --all
3、安装netCDF4、basemap库
分别conda install netCDF4、conda install basemap即可
分别import netCDF4 as nc和from mpl_toolkits.basemap import Basemap不报错即可
4、错误undefined symbol: omp_get_num_procs
conda install mkl-rt
5、错误Qt: Could not determine keyboard configuration data from X server
在bashrc中添加
export XKB_DEFAULT_RULES=base
export QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb
6、错误Qt: XKEYBOARD extension not present on the X server
设置xmange中的Xconfig->Default Profile->Properties->Advanced->X Extensions-> check the 'XKEYBOARD'(勾选)
7、错误QXcbConnection: Failed to initialize XRandr(弯路,请跳过)
(Qt5:Qt是诺基亚公司的C++可视化开发平台,最新版本为Qt5;XRandr:设置屏幕显示的软件包)
a、执行qtcreator,发现服务器本身就没有安装qt5和qt,因此先进行安装
感谢参考:CentOS7安装EPEL源()
感谢参考:配置国内y和e源()
配置yum国内源:
cd /etc/yum.repos.d/; mkdir repo_bak; mv *.repo repo_bak/
wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all && yum makecache
安装epel并配置epel国内源:
yum -y install epel-release
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all && yum makecache
查看所有可用源和所有源(可用源和禁用源):
yum repolist enabled
yum repolist all
安装qt-creator和qt:
yum install qt-creator
yum install qt
b、再次执行qtcreator,报错:libGL error: No matching fbConfigs or visuals found
暂时终止排错,因为虽然有错误,但是不影响简单画图
8、python读取nc数据,简单画图程序
from mpl_toolkits.basemap import Basemap # import Basemapimport numpy as np import matplotlib.pyplot as plt from netCDF4 import Dataset # netcdf4-python module # load in the netCDF4 file nc = Dataset('mdbz.nc') # read the variables from the netCDF4 file and assign mdbz = nc.variables['mdbz'][:,:] lat = nc.variables['lat'][:] lon = nc.variables['lon'][:] # set the plotting var for 2d shaded figure,set the colormapplt.contourf(mdbz, cmap='Accent') # show and save the figure plt.savefig('mdbz.png') plt.show()
四、Python3读取netcdf数据,并输出到新的netcdf数据
print(type(mdbz)) 查看变量类型
print(mdbz.shape[0]) 查看变量第0维大小
print(id(mdbz)) 查看变量内存地址
lat[:] = lats[:] 正确赋值;lat = lats 错误赋值
from netCDF4 import Dataset # netcdf4-python module from scipy.io import netcdf # load in the netCDF4 file nc = Dataset('mdbz.nc') # read the variables from the netCDF4 file and assign mdbz = nc.variables['mdbz'][:,:] lats = nc.variables['lat'][:] lons = nc.variables['lon'][:] # output to the new netCDF4 file f = netcdf.netcdf_file('mdbz_new.nc', 'w') f.createDimension('lat', mdbz.shape[0]) f.createDimension('lon', mdbz.shape[1]) reflectivity = f.createVariable('reflectivity', 'f8', ('lat', 'lon')) lat = f.createVariable('lat', 'f8', ('lat', )) lon = f.createVariable('lon', 'f8', ('lon', )) reflectivity[:,:] = mdbz[:,:] lat[:] = lats[:] lon[:] = lons[:] lat.units = "degrees_north" lon.units = "degrees_east" reflectivity.units = "dBZ" f.close()