Install Python and mysqldb in Linux

Source: Internet
Author: User

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

Tar-C $ install_dir-xjvf Python-2.6.tar.bz2
CD $ install_dir/Python-2.6
./Configure -- prefix = $ python_dir
Make & make install

3. Test

Enter python in the command line. If the python interpreter is displayed, the installation is correct.

Python is installed by default in suse10 or rhel5 (es5), but the version is 2.4.x. After this installation, enter

# Python

The result is displayed:

# Python

Python 2.4.3 (#1, Dec 11 2006, 11:38:52)

[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2

Type "help", "copyright", "credits" or "License" for more information.

>>>

Version 2.4.x

Solution:

# Cd/usr/bin

# Ll | grep Python // view python in this directory

# Rm-RF Python

# Ln-s prefix/Python-2.5.2/python./Python // prefix unzip the python directory for you

# Python

# Python

Python 2.5.2 (#1, Dec 11 2006, 11:38:52)

[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2

Type "help", "copyright", "credits" or "License" for more information.

>>>

Or modify the PATH variable Vim/etc/bashrc to add export Path = $ python_dir/bin :$ {path}

OK! Solve the problem!

4. Install mysqldb:

Tar-C $ install_dir-xzvf MySQL-python-1.2.3c1.tar
CD $ install_dir/MySQL-python-1.2.3c1

5. modify configuration items

Mysql_config = your_mysql_dir/MySQL-bin/mysql_config
VI site. cfg
$ Python_dir/bin/Python setup. py build
$ Python_dir/bin/Python setup. py install -- prefix = $ python_dir
6. Install
Python setup. py build

Sudo Python setup. py install

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

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

8. 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_r
Collect2: LD returned 1 exit status
Error: Command 'gcc 'failed with exit status 1

9. 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
Or
The error is caused by the failure to introduce library libmysqlclient. so.18,
Find that the library file exists and create a link:
Ln-S/usr/local/Server/MySQL/lib/libmysqlclient. so.18/usr/lib/libmysqlclient. so.18

Restart the session and test the normal installation!

Related Article

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.