centos安装python3小白_Centos7 安装Python3
Centos7 安裝Python3
一、linux安裝Python3
1.安裝相關(guān)依賴
[root@3f9 ~]# 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 gcc
2.官網(wǎng)下載Python源碼包
[root@3f9 ~]# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
3.創(chuàng)建安裝目錄
[root@3f9 ~]# mkdir -p /usr/local/python3
4.解壓文件
[root@3f9 ~]# tar -zxvf Python-3.6.4.tgz
5.進(jìn)入解壓目錄
[root@3f9 ~]# cd Python-3.6.4
6.配置
[root@3f9 Python-3.6.4]# ./configure --prefix=/usr/local/python3 --enable-shared --enable-optimizations
# --enable-shared啟用共享,方便其他依賴python的一些內(nèi)置庫(比如 mysqlclient) 的資源的正常# 安裝,在pyinstaller python打包時(shí),也需要開啟 --enable-shared
# --enable-optimizations是優(yōu)化選項(xiàng)(LTO,PGO 等)加上這個(gè) flag 編譯后,性能有 10% 左右的優(yōu)化
7.編譯安裝
[root@3f9 Python-3.6.4]# make && make install
8.將python3加入環(huán)境變量
[root@3f9 ~]# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
# 將python3的路徑加入此文件
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
[root@3f9 ~]# source ~/.bash_profile
9.創(chuàng)建python3軟連接
[root@3f9 ~]# ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
[root@3f9 ~]# python -V
10.創(chuàng)建pip3軟連接,升級(jí)pip3
[root@3f9 ~]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
[root@3f9 ~]# pip3 -V
[root@3f9 ~]# pip3 install --upgrade pip
二、問題
1.運(yùn)行python3 -V報(bào)錯(cuò)
python3: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory
1. 將python3安裝目錄的lib目錄下的文件libpython3.6m.so.1.0復(fù)制到/usr/lib/目錄下
[root@3f9 ~]# cp /usr/local/python3/lib/libpython3.6m.so.1.0 /usr/lib/
2.將目錄/usr/lib/添加到/etc/ld.so.conf.d/目錄下的python3.6.conf文件中
[root@3f9 ~]# echo "/usr/lib" > /etc/ld.so.conf.d/python3.6.conf
3.刷新動(dòng)態(tài)鏈接庫
[root@3f9 ~]# ldconfig
總結(jié)
以上是生活随笔為你收集整理的centos安装python3小白_Centos7 安装Python3的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python两个list合并成字典_Py
- 下一篇: decode函数python在哪里_Py