Linux非root用户下安装了python及MySQLdb

Linux非root用户下安装Python及MySQLdb记录:
安装所需软件包: Python-2.6.tar.bz2、MySQL-python-1.2.3c1.tar、setuptools-0.6c11.tar.gz、

安装前

#定义python的安装目录
PYTHON_DIR = /home/$USER/local/python
#定义安装目录
INSTALL_DIR = /home/$USER/install
#先查看本机python版本, 如果已安装相应版本则跳过第一步
python
Python 2.6 (r26:66714, Jul 21 2010, 11:47:32)
[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
#Ctrl + D退出第一步, 安装python

tar -C $INSTALL_DIR -xjvf Python-2.6.tar.bz2
cd $INSTALL_DIR/Python-2.6
./configure --prefix = $PYTHON_DIR
make && make install第二步, 安装MySQLdb

tar -C $INSTALL_DIR -xzvf MySQL-python-1.2.3c1.tar
cd $INSTALL_DIR/MySQL-python-1.2.3c1
#修改配置项mysql_config=your_mysql_dir/mysql-bin/bin/mysql_config
vi site.cfg
$PYTHON_DIR/bin/python setup.py build
$PYTHON_DIR/bin/python setup.py install  --prefix = $PYTHON_DIR
#这一步可能会提示ImportError: No module named setuptools
#则需要安装setuptools模块第三步, 安装setuptool

tar -C $INSTALL_DIR -xzvf setuptools-0.6c11.tar.gz
cd $INSTALL_DIR/setuptools-0.6c1
$PYTHON_DIR/bin/python  setup.py build
$PYTHON_DIR/bin/python  setup.py install
 
#回到MySQL-python-1.2.3c1目录,执行安装MySQLdb最后一步:
cd $INSTALL_DIR/MySQL-python-1.2.3c1
$PYTHON_DIR/bin/python setup.py install  --prefix = $PYTHON_DIR
#这一步可能会提示如下错误
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
#修改配置项,
#embedded = False
#threadsafe = False
#static = False
vi site.cfg
#再执行
$PYTHON_DIR/bin/python setup.py install  --prefix = $PYTHON_DIR安装完成测试

python
Import MySQLdb
#如果报错ImportError: libmysqlclient.so: cannot open shared object file: No such file or directory
cd ~ && vi .bash_profile
#在最后增加
export LD_LIBRARY_PATH=/home/$USER/local/mysql/lib/mysql:$LD_LIBRARY_PATH
#重启session
#再测试正常安装完成!

相关推荐