1.安装virtualenv
$ pip install virtualenv
2.创建隔离环境
(virtualenv会在当前工作目录下创建虚拟环境,testdir)
# virtualenv testdir
...Installing setuptools, pip, wheel...done.
要想得到不含任何第三方包的python运行环境,添加参数--no-site-packages:
$ virtualenv --no-site-packages testdir
3.进入testdir环境(source命令)
#source testdir/bin/activate
命令提示符变为:
(testvir2) [root@host-wk testvir2]#
4.安装MySQL-python
# pip install MySQL-python
报错:
mysql_config not found
检查/usr/bin目录:
cd /usr/bin
找不到mysql_config文件
解决办法:
# yum install mysql-devel
...Installed:
mysql-community-devel.x86_64 0:5.7.17-1.el7
Complete!
检查一下:
# whereis mysql_config
mysql_config: /usr/bin/mysql_config /usr/share/man/man1/mysql_config.1.gz
5.重新到虚拟目录下安装MySQL-python
$ pip install MySQL-python
报错:Failed building wheel for MySQL-python
error: command 'gcc' failed with exit status 1
解决办法:
# yum install gcc python-devel
6.正常安装
$ pip install MySQL-python
Successfully installed MySQL-python-1.2.5
7.退出虚拟环境
# deactivate
本文参考:
1.廖雪峰博客:virtualenv:http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432712108300322c61f256c74803b43bfd65c6f8d0d0000