我在CentOS 6.5上工作,默认情况下是python 2.6。所以我手动安装python 2.7并在“/home/thomas/Programs/python-2.7_project”中设置了一个带有virtualenv的沙箱。
# Install prerequisites
sudo yum groupinstall "Development tools"
sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel
# Python 2.7.6:
wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && sudo make altinstall # IMPORTANT: does not substitute the default python2.6 otherwise many failures will occur (e.g. yum)
# First get the setup script for Setuptools:
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
# Then install it for Python 2.7 and/or Python 3.3:
sudo `which python2.7` ez_setup.py
# Now install pip using the newly installed setuptools:
sudo `which easy_install-2.7` pip
# Install virtualenv for Python 2.7 and create a sandbox called my27project:
sudo `which pip2.7` install virtualenv
virtualenv-2.7 /home/thomas/Programs/python-2.7_project # create the new sandbox project into your home directory to install python packages without being in the sudoers list
然后我按如下方式编译了numpy和scipy:
chmod -R 777 /home/thomas/Programs/python-2.7_project
source /home/thomas/Programs/python-2.7_project/bin/activate
export PYTHONPATH=/home/thomas/Programs/python-2.7_project/lib64/python2.7/site-packages:$PYTHONPATH
sudo yum remove numpy scipy
sudo yum -y install blas lapack atlas atlas-devel mercurial
sudo ln -s /usr/lib64/libblas.so.3 /usr/lib64/libblas.so
sudo ln -s /usr/lib64/liblapack.so.3 /usr/lib64/liblapack.so
sudo ln -s /usr/lib64/atlas/libatlas.so.3 /usr/lib64/atlas/libatlas.so
export BLAS=/usr/lib64/libblas.so
export LAPACK=/usr/lib64/liblapack.so
export ATLAS=/usr/lib64/atlas/libatlas.so
git clone git://github.com/numpy/numpy.git numpy
cd numpy
python setup.py build
python setup.py install --prefix=/home/thomas/Programs/python-2.7_project
# for scipy
pip install cython # necessary for scipy
git clone git://github.com/scipy/scipy.git scipy
cd scipy
python setup.py build
python setup.py install --prefix=/home/thomas/Programs/python-2.7_project
但是,当我从scipy.stats导入一些函数时出现以下错误:
Traceback (most recent call last):
File "/usr/local/bin/RescoringTK.py", line 66, in <module>
from scipy.stats import pearsonr, linregress, zscore
File "/home/thomas/Programs/python-2.7_project/lib64/python2.7/site-packages/scipy/stats/__init__.py", line 334, in <module>
from .stats import *
File "/home/thomas/Programs/python-2.7_project/lib64/python2.7/site-packages/scipy/stats/stats.py", line 181, in <module>
import scipy.special as special
File "/home/thomas/Programs/python-2.7_project/lib64/python2.7/site-packages/scipy/special/__init__.py", line 546, in <module>
from ._ufuncs import *
ImportError: /home/thomas/Programs/python-2.7_project/lib64/python2.7/site-packages/scipy/special/_ufuncs.so: undefined symbol: npy_exp
有没有人知道错误的原因?