Centos7安装Python3的方法
由于centos7原本就安装了Python2,而且这个Python2不能被删除,因为有很多系统命令,比如yum都要用到。
输入Python命令,查看可以得知是Python2.6.6版本
[root@xxx]# python
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
输入
which python
可以查看位置,一般是位于/usr/bin/python
目录下。
下面介绍安装Python3的方法
首先安装依赖包
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
然后根据自己需求下载不同版本的Python3,我下载的是Python3.6.5
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
使用命令:
mkdir /usr/local/python3
建立一个空文件夹,作为python3的安装目录
然后解压压缩包,进入该目录,安装Python3
tar -xvJf Python-3.6.2.tar.xz
cd Python-3.6.2
./configure --prefix=/usr/local/python3
make && make install
最后创建软链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
我为了方便在pycharm中使用,将软链接改成了如下形式,直接替换了默认的python和pip,这样的话,输入python和pip就默认是3的版本了
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
在命令行中输入python测试,显示为3.6.5
Python 3.6.5 (default, May 29 2018, 15:00:50)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
下面是我配置环境的过程中遇到的问题
1、ta-lib这个插件安装不上,附上解决办法
$ pip install TA-Lib
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/zhangshoug/anaconda2/envs/rqalpha/lib/python3.6/site-packages/numpy/core/include -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/home/zhangshoug/anaconda2/envs/rqalpha/include/python3.6m -c talib/_ta_lib.c -o build/temp.linux-x86_64-3.6/talib/_ta_lib.o
talib/_ta_lib.c:526:28: fatal error: ta-lib/ta_defs.h: 没有那个文件或目录
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Failed building wheel for TA-Lib
解决方法:
wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar -zxvf ta-lib-0.4.0-src.tar.gz
cd ta-lib
./configure --prefix=/usr
make && make install
2.缺少python-devel
src/pcm.c:2:20: 致命错误:Python.h:没有那个文件或目录
#include
^
编译中断。
error: command 'gcc' failed with exit status 1
make: *** [install] 错误 1
解决办法
yum install python-devel