How to install Mysql-python in a virtualenv virtual environment

Source: Internet
Author: User
Tags virtual environment virtualenv

After exposure to virtualenv, you want to install a separate development environment in this virtual environment. Error encountered while installing MYSQLDB

PC 09:09:30
File "/home/pc/work/venv/py3/local/lib/python2.7/site-packages/setuptools/sandbox.py", line #, in Run_setup
Lambda:execfile (
File "/home/pc/work/venv/py3/local/lib/python2.7/site-packages/setuptools/sandbox.py", line +, in run
return func ()
File "/home/pc/work/venv/py3/local/lib/python2.7/site-packages/setuptools/sandbox.py", line-in <lambda>
{' __file__ ': setup_script, ' __name__ ': ' __main__ '}
File "setup.py", line +, in <module>
File "/tmp/easy_install-ftc77z/mysql-python-1.2.5/setup_posix.py", line +, in Get_config
File "/tmp/easy_install-ftc77z/mysql-python-1.2.5/setup_posix.py", line +, in Mysql_config
Environmenterror:mysql_config not found

In the domestic online search for a long time has not found a way, most of it is about how to install Mysql-python. Let's talk about the solution.

I have virtualenv installed on UBUNTU14, Mysql-server installed in the Global environment, installation commands

sudo apt-get Install Mysql-server

Subsequent processes are performed in a virtual environment. Mine is py3.

Start finding what you want to use MySQL to installlibmysqlclient-dev

Install Mysql-python or error after installation

(PY3) [Email protected]:~/work/venv/py3/bin$ pip Install Mysql-python
Downloading/unpacking Mysql-python
Downloading Mysql-python-1.2.5.zip (108kB): 108kB downloaded
Running setup.py (path:/home/pc/work/venv/py3/build/mysql-python/setup.py) Egg_info for package Mysql-python

Installing collected Packages:mysql-python
Running setup.py Install for Mysql-python
Building ' _mysql ' extension
I686-linux-gnu-gcc-pthread-fno-strict-aliasing-dndebug-g-fwrapv-o2-wall-wstrict-prototypes-fpic-dversion_info= (1,2,5, ' final ', 1)-d__version__=1.2.5-i/usr/include/mysql-i/usr/include/python2.7-c _mysql.c-o build/ Temp.linux-i686-2.7/_mysql.o-dbig_joins=1-fno-strict-aliasing-dtaocrypt_disable_x86asm-g-DNDEBUG
_mysql.c:29:20:fatal error:python.h:no such file or directory
#include "Python.h"
^
Compilation terminated.
Error:command ' I686-LINUX-GNU-GCC ' failed with exit status 1
Complete output from command/home/pc/work/venv/py3/bin/python-c "Import setuptools, tokenize;__file__= '/home/pc/work /venv/py3/build/mysql-python/setup.py '; Exec (Compile (getattr (tokenize, ' open ', open) (__file__). Read (). replace (' \ r \ n ', ' \ n '), __file__, ' exec ') ' Install--record/tmp/pip-v4whky-record/install-record.txt-- Single-version-externally-managed--compile--install-headers/home/pc/work/venv/py3/include/site/python2.7:
Running Install

Running Build

Running Build_py

Creating build

Creating build/lib.linux-i686-2.7

Copying _mysql_exceptions.py-build/lib.linux-i686-2.7

Creating BUILD/LIB.LINUX-I686-2.7/MYSQLDB

Copying mysqldb/__init__.py-Build/lib.linux-i686-2.7/mysqldb

Copying mysqldb/converters.py-Build/lib.linux-i686-2.7/mysqldb

Copying mysqldb/connections.py-Build/lib.linux-i686-2.7/mysqldb

Copying mysqldb/cursors.py-Build/lib.linux-i686-2.7/mysqldb

Copying mysqldb/release.py-Build/lib.linux-i686-2.7/mysqldb

Copying mysqldb/times.py-Build/lib.linux-i686-2.7/mysqldb

Creating build/lib.linux-i686-2.7/mysqldb/constants

Copying mysqldb/constants/__init__.py-build/lib.linux-i686-2.7/mysqldb/constants

Copying mysqldb/constants/cr.py-build/lib.linux-i686-2.7/mysqldb/constants

Copying mysqldb/constants/field_type.py-build/lib.linux-i686-2.7/mysqldb/constants

Copying mysqldb/constants/er.py-build/lib.linux-i686-2.7/mysqldb/constants

Copying mysqldb/constants/flag.py-build/lib.linux-i686-2.7/mysqldb/constants

Copying mysqldb/constants/refresh.py-build/lib.linux-i686-2.7/mysqldb/constants

Copying mysqldb/constants/client.py-build/lib.linux-i686-2.7/mysqldb/constants

Running Build_ext

Building ' _mysql ' extension

Creating build/temp.linux-i686-2.7

I686-linux-gnu-gcc-pthread-fno-strict-aliasing-dndebug-g-fwrapv-o2-wall-wstrict-prototypes-fpic-dversion_info= (1,2,5, ' final ', 1)-d__version__=1.2.5-i/usr/include/mysql-i/usr/include/python2.7-c _mysql.c-o build/ Temp.linux-i686-2.7/_mysql.o-dbig_joins=1-fno-strict-aliasing-dtaocrypt_disable_x86asm-g-DNDEBUG

_mysql.c:29:20:fatal error:python.h:no such file or directory

#include "Python.h"

^

Compilation terminated.

Error:command ' I686-LINUX-GNU-GCC ' failed with exit status 1

----------------------------------------
Cleaning up ...
Command/home/pc/work/venv/py3/bin/python-c "Import setuptools, tokenize;__file__= '/home/pc/work/venv/py3/build/ Mysql-python/setup.py '; Exec (Compile (getattr (tokenize, ' open ', open) (__file__). Read (). replace (' \ r \ n ', ' \ n '), __file __, ' exec ')) "Install--record/tmp/pip-v4whky-record/install-record.txt--single-version-externally-managed-- Compile--install-headers/home/pc/work/venv/py3/include/site/python2.7 failed with error code 1 in/home/pc/work/venv/ Py3/build/mysql-python
Storing debug log for failure In/home/pc/.pip/pip.log

See if Python-dev is not installed, you need to install this to start the installation

sudo apt-get install python-dev

At this point the installation of Mysql-python is possible, so the installation steps are

1 Installing Python-Dev

sudo apt-get install python-dev

2 installation libmysqlclient-dev

sudo apt-get install libmysqlclient-dev

3 Installing Mysql-python

pip install mysql-python

Verify at the end

(PY3) [Email protected]:~/work/venv/py3/bin$ python
Python 2.7.6 (default, June 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "Help", "copyright", "credits" or "license" for more information.
>>> Import MySQLdb
>>>

If the import does not have a problem, the import succeeds.

How to install Mysql-python in a virtualenv virtual environment

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.