美文网首页
centos 搭建简单python环境

centos 搭建简单python环境

作者: 默然戚戚 | 来源:发表于2018-04-03 21:25 被阅读0次

安装Pip

安装epel扩展源:

yum -y install epel-release

更新完成之后,就可安装pip:

yum -y install python-pip

安装完成之后清除cache:

yum clean all

设置镜像源

可供选择的源为如下:

清华:https://pypi.tuna.tsinghua.edu.cn/simple

阿里云:http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/ 

豆瓣:http://pypi.douban.com/simple/

临时使用

在使用的时候添加参数 -i 就可以了

pip install -i http://mirrors.aliyun.com/pypi/simple lxmy

永久修改

在linux系统下, 可以修改/.pip/pip.conf(代表当前用户的默认目录, 如果.pip文件夹不存在, 那么就重新创建)
内容如下:

[global]
index-url=http://pypi.douban.com/simple/
[install]
trusted-host=mirrors.aliyun.com

安装MySQL-python

安装MySQL-python必须要有mysql 客户端, 如果直接运行命令 pip install mysql-python 可能会抛出以下异常

    Complete output from command python setup.py egg_info:
    sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-RnTDKn/mysql-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 25, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-RnTDKn/mysql-python/

网上查了下在centos内核版本中需要安装mysql-devel:

yum install mysql-devel

提示安装成功后,可以接着尝试去安装MySQL-python模块, 安装过程可能会失败,报以下错误

   gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protecto                                                           r-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDE                                                           BUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4                                                            -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -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-x86_64-2.7/_                                                           mysql.o
    unable to execute gcc: No such file or directory
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ZpgZFV/Mysql-python/setu                                                           p.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))"                                                            install --record /tmp/pip-EJsy2i-record/install-record.txt --single-version-externally-managed --compile" fai                                                           led with error code 1 in /tmp/pip-build-ZpgZFV/Mysql-python/

看报错信息貌似是系统缺少相应的gcc编译器,输入yum 安装相应的编译器

yum -y install gcc

再一次尝试, 如果还是不行,安装以下包:

sudo yum install libffi-devel

sudo yum install openssl-devel

sudo yum install python-devel

相关文章

网友评论

      本文标题:centos 搭建简单python环境

      本文链接:https://www.haomeiwen.com/subject/jgzchftx.html