||
多谢louxiao!~
安装依赖库gfortran
#gfortran --version
它会提示:
bash: gfortran: command not found...
Install package 'gcc-gfortran' to provide command 'gfortran'? [N/y] y
选y,下面就安装好了
然后安装了ncepbufr
参考:https://github.com/jswhit/py-ncepbufr
但是import ncepbufr的时候出错:
/root/anaconda3/lib/python3.6/site-packages/_bufrlib.cpython-36m-x86_64-linux-gnu.so: cannot map zero-fill pages
内存不够了?
解决步骤:
(1)
[root@localhost ~]# free -h
total used free shared buff/cache available
Mem: 2.0G 1.1G 126M 5.3M 701M 605M
Swap: 2.1G 662M 1.4G
(2)
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 988M 0 988M 0% /dev
tmpfs 1000M 0 1000M 0% /dev/shm
tmpfs 1000M 1.9M 998M 1% /run
tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
/dev/mapper/fedora-root 49G 16G 31G 34% /
tmpfs 1000M 140K 1000M 1% /tmp
/dev/sda1 976M 158M 752M 18% /boot
/dev/mapper/fedora-home 199G 9.9G 179G 6% /home
tmpfs 200M 32K 200M 1% /run/user/42
tmpfs 200M 4.6M 196M 3% /run/user/1000
tmpfs 200M 0 200M 0% /run/user/0
tmpfs 200M 0 200M 0% /run/user/1007
(3)##创建一个4GB的文件,文件名是.4g.swap
[root@localhost ~]# dd if=/dev/zero of=.4g.swap bs=33554432 count=128
128+0 records in
128+0 records out
4294967296 bytes (4.3 GB, 4.0 GiB) copied, 44.8419 s, 95.8 MB/s
(4) ##使用ls -Al可以看到这个文件
[root@localhost ~]# ls -Al
total 4194400
-rw-r--r--. 1 root root 4294967296 Nov 9 23:15 .4g.swap
drwxr-xr-x. 28 root root 4096 Nov 9 18:08 anaconda3
...
...
(5)##这个是格式化刚才的文件,用来创建交换分区(文件)
[root@localhost ~]# mkswap .4g.swap
mkswap: .4g.swap: insecure permissions 0644, 0600 suggested.
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=3a84b799-123f-4eae-a0f0-26cfc9bc5b77
(6)##这个是把刚才的文件挂载为交换分区
[root@localhost ~]# swapon .4g.swap
swapon: /root/.4g.swap: insecure permissions 0644, 0600 suggested.
(7)
[root@localhost ~]# free -h
total used free shared buff/cache available
Mem: 2.0G 1.1G 66M 5.3M 828M 666M
Swap: 6.1G 739M 5.4G
[root@localhost ~]# python
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ncepbufr
>>>
成功!没有再出问题。
注:如果系统重启了,
(1)需要手动执行swapon 这一步,就是挂载操作
(2)也可以加到开机启动项,
主要原理:
是内存占用的,这个库需要预先分配虚拟的内存空间(大概5.6GB),而实际上占用的内存空间只有20MB。通过添加交换分区的方式,增加总体的虚拟内存空间。
虚拟内存就是抽象出来的内存,这些空间使用的时候会对应到真正的物理内存(真正的内存),如果物理内存不够,可以把多余的数据放到磁盘上,以文件的形式存放,这个文件就是交换文件。
总共可用的抽象内存大小= 物理内存大小 + 交换文件的大小。
这样做就是欺骗了这个程序,让它认为内存空间很大。
这个简要看看,虚拟内存的概念的引入,是为了简化内存空间的处理,方便写程序。
【
用普通用户运行python
import ncepbufr
同时用root用户
[root@localhost ~]# ps axu|grep python
root 707 0.0 0.3 360804 7808 ? Ssl Nov06 0:41 /usr/bin/python3 -Es /usr/sbin/firewalld --nofork --nopid
xjj 14183 0.8 1.3 5531880 27352 pts/2 S+ 23:30 0:00 python
root 14186 0.0 0.0 119448 884 pts/3 S+ 23:30 0:00 grep --color=auto python
】
其中5531880是虚拟内存的大小(必须要在python运行时才能看到,import ncepbufr)
27352 说的是实际内存使用了27MB
多谢louxiao!
其他参考:Linux 虚拟内存和物理内存的理解
http://www.cnblogs.com/dyllove98/archive/2013/06/12/3132940.html
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-5-21 23:53
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社