接触过virtualenv后,想在这个虚拟环境中安装独立的开发环境。在安装MySQLdb时遇到错误

pc 09:09:30
File "/home/pc/work/VENV/py3/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 50, in run_setup
lambda: execfile(
File "/home/pc/work/VENV/py3/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 100, in run
return func()
File "/home/pc/work/VENV/py3/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 52, in <lambda>
{'__file__':setup_script, '__name__':'__main__'}
File "setup.py", line 17, in <module>
File "/tmp/easy_install-FtC77Z/MySQL-python-1.2.5/setup_posix.py", line 43, in get_config
File "/tmp/easy_install-FtC77Z/MySQL-python-1.2.5/setup_posix.py", line 25, in mysql_config
EnvironmentError: mysql_config not found

在国内的网上找了好长时间也没有找到办法,大多数是讲如何安装mysql-python的。先说一下解决过程吧

我是在ubuntu14上安装有virtualenv,在全局环境中安装了mysql-server,安装命令

sudo apt-get install mysql-server

后续过程都是在虚拟环境中进行的。我的是py3

开始找到要想使用mysql需要安装libmysqlclient-dev

安装过后在安装mysql-python还是出错

(py3)pc@pc-virtual-machine:~/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

看到如果没有安装python-dev,需要安装这个就开始安装

sudo apt-get install python-dev

此时在安装mysql-python就可以了,所以安装步骤是

1 安装python-dev

sudo apt-get install python-dev

2 安装 libmysqlclient-dev

sudo apt-get install libmysqlclient-dev

3 安装mysql-python

pip install mysql-python

最后进行验证

(py3)pc@pc-virtual-machine:~/work/VENV/py3/bin$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>

如果导入没有问题就说明导入成功了。

如何在virtualenv虚拟环境中安装mysql-python的更多相关文章

  1. 如何在Ubuntu14.04中安装mysql

    接触过MySQL的小伙伴们都知道,在Windows下安装MySQL是一件让人十分头大的事情,但是在Ubuntu等其他Linux系统中安装MySQL就简单很多了,具体的教程如下.1.在Ubuntu的命令 ...

  2. 如何在virtualenv环境中安装指定的python版本

    指定python版本:virtualenv   -p python执行文件路径     自定义虚拟环境名称.如果文件路径有空格,用引号. 如果不指定python版本,则默认使用环境变量中的python ...

  3. 如何在centos6.5中安装MySQL数据库

    huidaoli 东华理工大学信工IT网-项目1+1学习基地(www.ecit-it.com)

  4. 如何在RedHat 7.0系统中安装mysql 5.7.22

    如何在RedHat 7.0系统中安装mysql 5.7.22 今天给大家介绍一下如何安装mysql5.7,在安装之前,首先要查看的是,你的系统中有没有已经安装过的情况.键入rpm -qa|grep m ...

  5. 在docker中安装mysql

    #!/bin/sh # 安装docker # 在docker中安装mysql # 解决了docker容器中无法输入中文的问题 ##########################安装docker # ...

  6. windows 虚拟环境下 安装 mysql 引擎一系列错误处理

    报错现象 运行django 报错. 很明显是缺少引擎 下载引擎 django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb m ...

  7. win7中安装mysql

    这篇文章主要介绍了如何在win7中安装mysql,所以加上了MySQL的下载过程,希望对需要的人有所帮助大家都知道MySQL是一款中.小型关系型数据库管理系统,很具有实用性,对于我们学习很多技术都有帮 ...

  8. 如何在win7系统中安装redis

    转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/92.html?1455871954 如何在win7系统中安装redis​ ...

  9. centos 7 中安装 mysql 5.7

    centos 7 中安装 mysql 5.7 环境说明: 查看centos的版本:cat /etc/redhat-release 安装和配置步骤: 下载 mysql 源安装包: sudo curl - ...

随机推荐

  1. 图解Eclipse或者SpringSource Tool Suite 创建模块化Maven项目

    第一步:Package Explorer里选择右键,新建Maven项目,如果没有在Other里找,还没有确认一下是否安装了Maven插件 第二步:在Wizards向导里可以通过搜索,找到Maven P ...

  2. Visio 2013 由于形状保护、容器和/或图层属性的设置,无法完全执行此命令

    形状的保护 解决问题:Visio 2013 由于形状保护.容器和/或图层属性的设置,无法完全执行此命令 重要: 本文是由机器翻译的,请参阅免责声明.请在 此处 中查找本文的英文版本以便参考. 禁止对形 ...

  3. [Functional Programming] mapReduce over Async operations and fanout results in Pair(rejected, resolved) (fanout, flip, mapReduce)

    This post is similar to previous post. The difference is in this post, we are going to see how to ha ...

  4. [React GraphQL] Pass Parameters to urql's useQuery React Hook

    Showing how to use 'uqrl' library to do GraphQL in React. import React, {useState} from 'react' impo ...

  5. 使用sed进行文字替换

    范式: sed -i "s/查找内容/替换后内容/g" `grep 查找内容 -rl 查找开始路径` 例子: #sed -i "s/abc/ABC/g" `gr ...

  6. uni - 介绍

    uni-app 是一个使用 Vue.js 开发跨平台应用的前端框架,开发者编写一套代码,可编译到iOS.Android.H5.小程序等多个平台 优点:基于vue.mpvue.微信小程序 微信小程序AP ...

  7. RESTful到底是什么玩意??

      0. REST不是"rest"这个单词,而是几个单词缩写.: 1. REST描述的是在网络中client和server的一种交互形式:REST本身不实用,实用的是如何设计 RE ...

  8. html字符转义

    常用表: No. 文字表記 10進表記 16進表記 文字   Comment 001 " " " """   quotation mark ...

  9. vim插件之pathogen,NERDTree,Command-T,Powerline

    pathogen 功能说明 一个插件包往往具备多种功能,每个文件根据Vim的路径约定会放置到不同的目录下,通用插件放到plugin下,语法高亮插件放到syntax下,自动加载插件放到autoload下 ...

  10. 源码安装和配置zabbix 3.0 LST

    Zabbix是什么 Zabbix 是由Alexei Vladishev创建,目前由Zabbix SIA在持续开发和支持. Zabbix 是一个企业级的分布式开源监控方案. Zabbix是一款能够监控各 ...