赞
踩
apt install gcc patch libffi-devel python3-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite3 sqlite3-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
# 解压
tar -zxvf python3.6.9.tar.gz -C /home/laufing
# 创建安装目录,并配置
mkdir /usr/local/python3
cd python3.6.9
./configure --prefix=/usr/local/python3
make && make install
vim /etc/profile
export PATH=/usr/local/python3/bin:$PATH
# source /etc/profile
# 安装
update-alternatives --install /bin/python3 python3 /usr/local/python3/bin/python3.6 1
# 显示
update-alternatives --display python3
# 选择版本
alternatives --set <name> <true-path>
pip3 config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/simple
pip3 config set global.trusted-host mirrors.tuna.tsinghua.edu.cn
whereis python3
# 卸载python3
rpm -qa | grep -iE "python3" | xargs rpm -ev --allmatches --nodeps
whereis python3 | xargs rm -rfv
若python3相关的依赖没有安装或者安装失败,则会有如下问题:
$ python3 >>>import ssl # 失败则安装openssl >>>import sqlite3 # no module named _sqlite3 # 失败,安装sudo apt-get install sqlite3 sqlite3-devel >>>import bz2 #失败,安装sudo apt-get install libbz2-devel >> import ctypes # no module named _ctypes # 安装 libffi-devel # no module named readline # 安装 readline-devel ncurses-devel >>>import lzma #失败,解决sudo apt-get install liblzma-dev >>>import tkiner #失败,sudo apt-get install tk-devel tcl-devel libX11-devel # #然后重新安装 cd Python-3.6.9 sudo ./configure --with-ssl --enable-loadable-sqlite-extensions sudo make sudo make install
安装完3.6.9后,使用software-properties-gtk 查看状态,发现如下问题:
最典型的影响就是,系统设置中文时,点击Language support 无响应。如图:
lauf@master:~$ cd /usr/lib/python3/dist-packages
lauf@master:/usr/lib/python3/dist-packages$ sudo apt-get install python3-apt --reinstall
lauf@master:/usr/lib/python3/dist-packages$ sudo cp apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.cpython-36m-x86_64-linux-gnu.so
#再次执行如下
lauf@master:/usr/lib/python3/dist-packages$ software-properties-gtk
已经解决apt_pkg问题:
1)输入命令行software-properties-gtk 再无apt_pkg问题
2)ipython3下输入import apt_pkg 正常,如下:
但是执行software-properties-gtk出现了新问题:
2. 解决_dbus_bindings
lauf@master:/usr/lib/python3/dist-packages$ sudo cp _dbus_bindings.cpython-35m-x86_64-linux-gnu.so _dbus_bindings.cpython-36m-x86_64-linux-gnu.so
lauf@master:/usr/lib/python3/dist-packages$ ls _dbus_glib_*
_dbus_glib_bindings.cpython-35m-x86_64-linux-gnu.so
lauf@master:/usr/lib/python3/dist-packages$ sudo cp _dbus_glib_bindings.cpython-35m-x86_64-linux-gnu.so _dbus_glib_bindings.cpython-36m-x86_64-linux-gnu.so
lauf@master:/usr/lib/python3/dist-packages$ python3
Python 3.6.9 (default, Sep 2 2021, 07:39:18)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
>>> exit()
#成功解决
但是执行software-properties-gtk又出现如下问题:
lauf@master:/usr/lib/python3/dist-packages/gi$ sudo cp _gi_cairo.cpython-35m-x86_64-linux-gnu.so _gi_cairo.cpython-36m-x86_64-linux-gnu.so
lauf@master:/usr/lib/python3/dist-packages/gi$ sudo cp _gi.cpython-35m-x86_64-linux-gnu.so _gi.cpython-36m-x86_64-linux-gnu.so
再次运行,software-properties-gtk,出现如下界面,则表示解决成功。
from softwareproperties.gtk.SoftwarePropertiesGtk import SoftwarePropertiesGtk
以上就是我在使用源码安装python3.6.9时碰到的问题,仅以此记录以下。
最终解决状态:
lauf@master:/usr/lib/python3/dist-packages$ ipython3
Python 3.6.9 (default, Sep 2 2021, 07:39:18)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import apt_pkg
In [2]: import dbus
In [3]: from softwareproperties.gtk.SoftwarePropertiesGtk import SoftwarePropertiesGtk
/usr/lib/python3/dist-packages/softwareproperties/gtk/SoftwarePropertiesGtk.py:40: PyGIWarning: Gdk was imported without specifying a version first. Use gi.require_version('Gdk', '3.0') before import to ensure that the right version gets loaded.
from gi.repository import GObject, Gdk, Gtk, Gio, GLib
/usr/lib/python3/dist-packages/softwareproperties/gtk/SoftwarePropertiesGtk.py:40: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
from gi.repository import GObject, Gdk, Gtk, Gio, GLib
但是这种解决只是临时的,只能在当前目录导入包。
还需要配置python的搜索路径
$ cd ~
$ sudo vim .bashrc
#末尾添加如下:
export PYTHONPATH=.:/usr/lib/python3/dist-packages:$PYTHONPATH
#保存退出
$ source .bashrc #是配置生效
当前增加的路径,每次导入包时,都会被搜索。使用这个方法解决python3.6.9的大坑问题。
>>>import sys
>>>sys.path.append("/usr/lib/python3/dist-packages")
>>>import apt_pkg #此时会搜索该添加 的路径
一旦退出程序,添加的路径也就GG了。
执行命令行:system-config-kdump,问题如下:
在ipython3中也是无法导入该包:
sudo apt-get install python3.6-gdbm
sudo cp /usr/lib/python3.5/lib-dynload/_gdbm.cpython-35m-x86_64-linux-gnu.so /usr/lib/python3.6/lib/python3.6/lib-dynload/_gdbm.cpython-36m-x86_64-linux-gnu.so
未解决!!!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。