将源文件都放在 /share/apps/source/phonopy/,源文件包括:
phonopy-1.6.2.tar.gz,Python-2.7.3.tgz,numpy-1.5.1.tar.gz,scipy-0.11.0.tar.gz,lxml-3.0.1.tar.gz, matplotlib-1.2.0.tar.gz,PyYAML-3.09.tar.gz,PyInstaller-2.1.tar.gz ,可能还需要 libxml2-2.7.2.tar.gz, libxslt-1.1.28.tar.gz
(注意:不要使用Python3.x,Python3.x与python2.x在语法上有重大改动,比如在python2.x中输出字符串使用 print “Hello”,但在python3.x中不识别了,要写成
print (“Hello”),phonopy-1.6.2不支持Python3.x,我被坑惨了,全部重来,推荐Python2.4及以上)
1) 解压源文件:
cd /share/apps/source/phonopy
tar -xvf Python-2.7.3.tgz
tar -xvf numpy-1.5.1.tar.gz
tar -xvf scipy-0.11.0.tar.gz
tar -xvf matplotlib-1.2.0.tar.gz
tar -xvf lxml-2.3.4.tar.gz
tar -xvf PyYAML-3.10.tar.gz
tar -xvf PyInstaller-2.1.tar.gz
2)Python 安装
cd /share/apps/source/phonopy
cd Python-2.7.3
./configure --enable-shared --prefix=/share/apps/python2.7
make
make install
注意:不加 --enable-shared 参数将编译静态的python,无法使用PyInstall的打包。
export PATH=/share/apps/python2.7/bin:$PATH
export LD_LIBRARY_PATH=/share/apps/python2.7/lib:$LD_LIBRARY_PATH
which python2.7 查看是否找到python2.7
3)Numpy和scipy的安装(提前做好ifort和MKL的环境变量,PATH及LD_LIBRARY_PATH)
cd /share/apps/source/phonopy/numpy-1.5.1
cp site.cfg.example site.cfg
----------------------------------------
修改 site.cfg
将
# [mkl]
# library_dirs = /opt/intel/mkl/10.0.1.014/lib/32/
# lapack_libs = mkl_lapack
# mkl_libs = mkl, guide
改为(根据实际情况修改):
[mkl]
library_dirs = /share/apps/intel/intel2/ifc/mkl/lib/em64t
include_dirs = /share/apps/intel/intel2/ifc/mkl/include
mkl_libs = mkl_def, mkl_intel_lp64, mkl_intel_thread, mkl_core, mkl_mc
lapack_libs = mkl_lapack95_lp64
-------------------------------------------------------------
python2.7 setup.py build --fcompiler=intelem (使用的是intel fortran编译器,可用python2.7 setup.py build --help-fcompiler来查看可使用的编译器。最好能在环境变量中能找到ifort)
python2.7 setup.py install --home=/share/apps/python2.7/pymodule
下一步是关键:
export PATH=/share/apps/python2.7/bin:/share/apps/python2.7/pymodule/bin:$PATH
export PYTHONPATH=/share/apps/python2.7/pymodule/lib/python
让python知道到哪里去找模块,测试python是否能够调用numpy
cd .. (退出 numpy的目录)
执行 python2.7 进入python界面
执行 import numpy
然后执行 numpy 看是否出错,若有类似 <module 'numpy' from '/share/apps/python2.7/pymodule/lib/python/numpy/__init__.py'>的语句表示调入numpy成功,
执行numpy.show_config()查看blas库等是否能找到。
然后输入exit()退出python界面。
cd /share/apps/source/phonopy/scipy-0.11.0
将 Numpy下的 site.cfg 复制过来
python2.7 setup.py build --fcompiler=intelem
python2.7 setup.py install --home=/share/apps/python2.7/pymodule
测试方法与Numpy相同。
4)Matplotlib的安装
cd /share/apps/source/phonopy/matplotlib-1.2.0
python2.7 setup.py install --home=/share/apps/python2.7/pymodule
5)lxml 的安装
cd /share/apps/source/phonopy/lxml-3.0.1
python2.7 setup.py install --home=/share/apps/python2.7/pymodule
若发现 error: command 'gcc' failed with exit status 1 之类的错误,这是因为lxml对
cd /share/apps/source/phonopy/
tar -xvf libxml2-2.7.2.tar.gz
cd libxml2-2.7.2
./configure --prefix=/share/apps/sharelib --without-python
make
make install
然后
cd /share/apps/source/phonopy/
tar -xvf libxslt-1.1.28.tar.gz
cd libxslt-1.1.28
./configure --prefix=/share/apps/sharelib --without-crypto --without-python --with-libxml-prefix=/share/apps/sharelib
make
make install
cd /share/apps/source/phonopy/lxml-3.0.1
python2.7 setup.py build --with-xslt-config=/share/apps/sharelib/bin/xslt-config
python2.7 setup.py install --home=/share/apps/python2.7/pymodule
export LD_LIBRARY_PATH=/share/apps/sharelib/lib:$LD_LIBRARY_PATH
6)PyYAML的安装
cd /share/apps/source/phonopy/PyYAML-3.10
python2.7 setup.py install --home=/share/apps/python2.7/pymodule
7)编译 phonopy
cd /share/apps
tar -xvf /share/apps/source/phonopy/phonopy-1.6.2.tar.gz
cd phonopy-1.6.2
python2.7 setup.py install --home=.
export PATH=/share/apps/phonopy-1.6.2/bin:$PATH
export PYTHONPATH=/share/apps/python2.7/pymodule/lib/python:/share/apps/phonopy-1.6.2/lib/python
执行phonopy测试,
_
_ __ | |__ ___ _ __ ___ _ __ _ _
| '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
| |_) | | | | (_) | | | | (_) || |_) | |_| |
| .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
|_| |_| |___/
1.6.2
POSCAR could not be found.
_
___ _ __ __| |
/ _ \ '_ \ / _` |
| __/ | | | (_| |
\___|_| |_|\__,_|
8)环境变变量汇总,
export LD_LIBRARY_PATH=/share/apps/python2.7/lib:/share/apps/sharelib/lib:$LD_LIBRARY_PATH
export PATH=/share/apps/python2.7/bin:/share/apps/python2.7/pymodule/bin:/share/apps/phonopy-1.6.2/bin:$PATH
export PYTHONPATH=/share/apps/python2.7/pymodule/lib/python:/share/apps/phonopy-1.6.2/lib/python
可以将这些环境变量写入一个文件,使用phonopy之前调用一次做一下环境变量。
9)使用PyInstall将Phonopy打包,
cd /share/apps/phonopy-1.6.2/bin 看到一堆phonopy 相关命令
bandplot dispmanager gruneisen outcar-born pdosplot phonopy phonopy-FHI-aims phonopy-qha propplot tdplot
cd /share/apps/PyInstaller-2.1
执行 python2.7 pyinstaller.py --onefile /share/apps/phonopy-1.6.2/bin/phonopy
在但当前目录下会声生成一个phonopy目录,在./phonopy/dist下生成生成一个可执行可执行文件phonopy,
这是一个独立的不依赖于python的程序。
其它的命令用类似方法生成。
-----------------------------------------------------------
主要参考: