一、安装python3环境
centos7自带版本是python2.7
如果要用的3.0以上的版本需要手动安装,下载地址:https://www.python.org/ftp/python/
先查看系统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就能共存了。
下载python3的包之前,要先安装相关的依赖包,用于下载编译python3:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
运行了以上命令以后,就安装了编译python3所用到的相关依赖
默认的centos7是没有安装pip,先添加epel扩展源
yum -y install epel-release
安装pip
yum install python-pip
用yum装wget
yum -y install wget
用wget下载python3的源码包,或者自己先下载好,上传到服务器再安装,如果网络快可以直接安装
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
编译python3源码包,解压
xz -d Python-3.6.8.tar.xztar -xf Python-3.6.8.tar
进入解压后的目录,依次执行下面命令进行手动编译
cd Python-3.6.8./configure --prefix=/usr/local/python3 --enable-optimizations --enable-shared --with-ssl make && make install
安装依赖zlib、zlib-deve
yum install zlib zlibyum install zlib zlib-devel
最后没提示出错,就代表正确安装了,在/usr/local/目录下就会有python3目录
添加软链接,将原来的链接备份
mv /usr/bin/python /usr/bin/python.bak
添加python3的软链接
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
测试是否安装成功了
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/
更改yum配置,因为其要用到python2才能执行,否则会导致yum不能正常使用
vi /usr/bin/yum
把第一行的#! /usr/bin/python 修改为如下
#! /usr/bin/python2
还有一个地方也需要修改
vi /usr/libexec/urlgrabber-ext-down
把第一行的**#! /usr/bin/python** 修改如下
#! /usr/bin/python2
启动python2
python2
启动python3
python
二、安装pyinstaller
python -m pip install pyinstaller
如果遇到command not found 的情况,解决方式:复制pyinstaller到**/usr/binusr/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
来源地址:https://blog.csdn.net/qq_41494895/article/details/129008449