Install python and MySQLdb for non-root users in Linux

Source: Internet
Author: User

LinuxNon-root usersPythonAndMySQLdbRecord:

Install the required software package: python-2.6.tar.bz2133 mysql-python-1.2.3c1.tarw.setuptools-0.6c11.tar.gz.

Before installation:

1. Define the python installation directory:

PYTHON_DIR = /home/$USER/local/python

2. Define the installation directory:

INSTALL_DIR = /home/$USER/install

First, check the python version of the Local Machine. If the corresponding version is installed, skip step 1;

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 Exit Step 1 and install python:

tar -C $INSTALL_DIR -xjvf Python-2.6.tar.bz2 cd $INSTALL_DIR/Python-2.6 ./configure --prefix = $PYTHON_DIR make && make install

3. Install MySQLdb:

tar -C $INSTALL_DIR -xzvf MySQL-python-1.2.3c1.tar cd $INSTALL_DIR/MySQL-python-1.2.3c1

4. modify configuration items

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

This step may prompt ImportError: No module named setuptools. You need to install the setuptools module.

5. Install 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

6. Go back to the MySQL-python-1.2.3c1 directory and perform the last step of installing MySQLdb:

cd $INSTALL_DIR/MySQL-python-1.2.3c1 $PYTHON_DIR/bin/python setup.py install --prefix = $PYTHON_DIR

In this step, the following error may be prompted:

/usr/bin/ld: cannot find -lmysqlclient_rcollect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1

7. modify configuration items,

embedded = False threadsafe = False static = False vi site.cfg

Run the following command:

$PYTHON_DIR/bin/python setup.py install  --prefix = $PYTHON_DIR

Installation completion test:

python Import MySQLdb

If an error is reported:

ImportError: libmysqlclient.so: cannot open shared object file: No such file or directory cd ~ && vi .bash_profile

Add at last

export LD_LIBRARY_PATH=/home/$USER/local/mysql/lib/mysql:$LD_LIBRARY_PATH

Restart the session and test the normal installation!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.