centos安装python3详细教程
一、安装python3环境
centos7自带版本是python2.7
如果要用的3.0以上的版本需要手动安装,下载地址:https://www.python.org/ftp/python/
1、先查看系统python的位置在哪儿
whereis python
python2.7默认安装是在 /usr/bin目录中,切换到/usr/bin/
cd /usr/bin/
ll python*
python指向的是python2,python2指向的是python2.7,因此我们可以装个python3,然后将python指向python3,然后python2指向python2.7,那么两个版本的python就能共存了。
2、下载python3的包之前,要先安装相关的依赖包,用于下载编译python3:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
运行了以上命令以后,就安装了编译python3所用到的相关依赖
3、默认的centos7是没有安装pip,先添加epel扩展源
yum -y install epel-release
4、安装pip
yum install python-pip
5、用yum装wget
yum -y install wget
6、用wget下载python3的源码包,或者自己先下载好,上传到服务器再安装,如果网络快可以直接安装
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
7、编译python3源码包,解压
xz -d Python-3.6.8.tar.xz
tar -xf Python-3.6.8.tar
8、进入解压后的目录,依次执行下面命令进行手动编译
cd Python-3.6.8
./configure --prefix=/usr/local/python3 --enable-optimizations --enable-shared --with-ssl
make && make install
9、安装依赖zlib、zlib-deve
yum install zlib zlib
yum install zlib zlib-devel
10、最后没提示出错,就代表正确安装了,在/usr/local/目录下就会有python3目录
11、添加软链接,将原来的链接备份
mv /usr/bin/python /usr/bin/python.bak
12、添加python3的软链接
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
13、测试是否安装成功了
python -V
如果遇到如下错误
[root@localhost local]# python -v
python: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory
我们只需要将该文件复制到usr/lib64
cp /installPackage/Python-3.6.8/libpython3.6m.so.1.0 /usr/lib64/
14、更改yum配置,因为其要用到python2才能执行,否则会导致yum不能正常使用
vi /usr/bin/yum
15、把第一行的#! /usr/bin/python 修改为如下
#! /usr/bin/python2
16、还有一个地方也需要修改
vi /usr/libexec/urlgrabber-ext-down
17、把第一行的**#! /usr/bin/python** 修改如下
#! /usr/bin/python2
18、启动python2
python2
19、启动python3
python
二、安装pyinstaller
python -m pip install pyinstaller
如果遇到command not found 的情况,解决方式:复制pyinstaller到**/usr/bin/**下
cd /usr/local/python3/bin/
cp pyinstaller /usr/bin/.
如果打包时报错:
OSError: Python library not found: libpython3.6m.so.1.0, libpython3.6mu.so.1.0, libpython3.6.so.1.0
This would mean your Python installation doesn't come with proper library files.
This usually happens by missing development package, or unsuitable build parameters of Python installation.
* On Debian/Ubuntu, you would need to install Python development packages
* apt-get install python3-dev
* apt-get install python-dev
* If you're building Python by yourself, please rebuild your Python with `--enable-shared`(or, `--enable-framework` on Darwin)
解决方式:是因为编译python 的时候没有加–enable-shared ,重新编译即可
有时候打包的时候发现缺少libpython3.6m.so.1.0,可以先在服务器中搜索libpython3.6m.so.1.0在哪里,然后拷贝到**/usr/lib64**
cd /usr/local/python36/lib/
cp libpython3.6m.so.1.0 /usr/lib64/
三、安装第三方库
安装zeroc-ice时遇到错误:
............
running build_ext
building 'IcePy' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/src
creating build/temp.linux-x86_64-3.6/src/ice
creating build/temp.linux-x86_64-3.6/src/ice/cpp
creating build/temp.linux-x86_64-3.6/src/ice/cpp/src
creating build/temp.linux-x86_64-3.6/src/ice/cpp/src/Ice
creating build/temp.linux-x86_64-3.6/src/ice/cpp/src/Slice
creating build/temp.linux-x86_64-3.6/src/ice/cpp/src/IceSSL
creating build/temp.linux-x86_64-3.6/src/ice/cpp/src/IceLocatorDiscovery
creating build/temp.linux-x86_64-3.6/src/ice/cpp/src/IceUtil
creating build/temp.linux-x86_64-3.6/src/ice/cpp/src/IceDiscovery
creating build/temp.linux-x86_64-3.6/src/ice/mcpp
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DICE_PYPI -DICE_STATIC_LIBS -Isrc -Isrc/ice/cpp/include -Isrc/ice/cpp/include/generated -Isrc/ice/cpp/src -I/usr/local/python3/include/python3.6m -c src/ConnectionInfo.cpp -o build/temp.linux-x86_64-3.6/src/ConnectionInfo.o -w
gcc: error trying to exec 'cc1plus': execvp: 没有那个文件或目录
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-q4oetdsy/zeroc-ice_5d02e88c62d246a09eaebdb3cc1ad114/setup.py'"'"'; __file__='"'"'/tmp/pip-install-q4oetdsy/zeroc-ice_5d02e88c62d246a09eaebdb3cc1ad114/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-ogw_3t2t/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/python3/include/python3.6m/zeroc-ice Check the logs for full command output
这是因为没有安装gcc
yum install -y gcc-c++
然后就可以安装了,记得指定python 版本哦!
python -m pip install zeroc-ice
版权归原作者 开心吧~小艺子 所有, 如有侵权,请联系我们删除。