python3.6.6的安装
使用官网python3.6.6.tgz安装包,在Ubuntu18.04上进行源代码安装
(这里下载安装的Ubuntu 18系统,自带pythoin3.6.5,没有python2,安装3.6.6后,3.6.5被覆盖)
在构建测试make test的时候,报出以下问题:
No module named '_ssl'
No module named '_tkinter'
No module named '_msi'
No module named 'winreg'
No module named '_bz2'
No module named '_dbm'
No module named 'readline'
No module named '_lzma'
No module named '_curses'
No module named '_gdbm'
No module named '_sqlite3'
尝试在python3中导入以上库
比如
Python 3.6.6 (default, Jul 21 2018, 10:14:45)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.6/tkinter/__init__.py", line 36, in
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
很明显,失败了
因为无法导入ssl,使用pip3安装虚拟环境virtualenv失败了,所以我先解决这个
sudo aptitude install openssl
sudo aptitude install libssl-dev
cd ~/software/Python3.6.6
./configure --with-ssl
make
sudo make install
Python 3.6.6
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>
这次没有报错,可以正常导入
sudo pip3 install virtualenv
virtualenv --version
16.0.0
虚拟环境也安装成功了
No module named '_ssl'问题解决。
sudo aptitude install python3-tk
sudo aptitude install tk-dev
注意这里因为是python3环境,所以是安装python3-tk
如果是python2环境,是安装python-tk
cd ~/software/Python3.6.6
./configure
make
sudo make install
进行构建测试make test时,就可以看到
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_dbm _gdbm _lzma
_sqlite3 readline
No module named 'ssl' ‘No module named 'tkinter' 的提示也已经没有了
tests skipped的提示也减少到19,之前为23
Python 3.6.6
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
没有报错,导入成功
在3.6.6上导入sqlite3的包,使用上面apt安装的方法直接安装,然后对python再次编译安装的方法,已经无效了。
所以需要要手动进行sqlite3的源代码安装
根据时间而定,可以自行去官网下最新的
https://www.sqlite.org/
tar -zxvf sqlite-autoconf-3240000.tar.gz -C ~/software
cd ~/software/sqlite-autoconf-3240000
./configure --prefix=/usr/local/sqlite3
make
sudo make install
cd ~/software/Python3.6.6 #进入目录
ls # 查看目录中文件及目录列表
vim setup.py # vim打开文件setup.py
/sqlite # 定位文档中sqlite的位置
# 修改setup.py,列表中增添一条路径 '/usr/local/sqlite3/include',
sqlite_inc_paths = [ '/usr/include',
'/usr/include/sqlite',
'/usr/include/sqlite3',
'/usr/local/include',
'/usr/local/include/sqlite',
'/usr/local/include/sqlite3',
'/usr/local/sqlite3/include', #添加的路径
]
esc:wq #保存退出
./configure
make
sudo make install
进行构建测试make test
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_dbm _gdbm _lzma
readline
_sqlite3不见了,所以应该是成功了
Python 3.6.6
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>>
没有报错,导入成功
版本不同,依赖包会改名字,但是一般都包含关键字(就因为这个,走了多少弯路
Ubuntu查找依赖包的网址:https://packages.ubuntu.com/
终端内使用指令:
apt search 关键字
也可以。
sudo aptitude install libncurses5-dev
sudo aptitude install libreadline-dev
vim ~/software/Python3.6.6/Modules/Setup.dist.
# 查找:/readline readline,找到下面这段代码,把前面的注释号去掉(去掉#号
readline readline.c -lreadline -ltermcap
#退出保存,回到上一级目录
esc:wq
cd ..
./configure
make
sudo make install
进行构建测试make test,就剩4个了
The necessary bits to build these optional modules were not found:
_bz2 _dbm _gdbm
_lzma
Python 3.6.6
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
>>>
没有报错,导入成功
PS:通过readline写脚本,可以在Python命令行中使用 tab 命令补全,以及在vim编辑时自动补全,不过另写一篇吧,连续解决这4个包的问题,用时间太多了,去休息会儿。
能找到的参考资料很少,只好通过查询相关依赖包,通过解读注释来尝试解决
aptitude search dbm
找到的结果很多,i386版本是32位处理器通用的,我用不到,不用看,根据之前的经验,优先找dev或者devel这种开发版本,找到以下两个包:
clisp-module-gdbm # clisp模块,为GNU添加接口
libgdbm-dev
./configure
make
sudo make install
进行构建测试make test,就剩3个了
The necessary bits to build these optional modules were not found:
_bz2 _dbm _lzma
但是,dbm模块确实已经可以正常导入了
`Python 3.6.6
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbm
>>>
因为在python3中,gdbm模块已重命名为dbm.gnu,那么测试导入gdbm
Python 3.6.6
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dbm import gnu
>>>
都成功导入了,应该是不影响正常使用l,毕竟这时候依赖包最新版本的是针对3.6.5版本,大概是因为这一点差别,所以make test时仍会报错。
The necessary bits to build these optional modules were not found:
_dbm _lzma
这个能查到的资料,基本都是centos的,想办法自行解决吧
这是bzip的源文件下载地址:http://www.bzip.org/downloads.html
apt工具的安装bzip包,基本没用,安了和没安一样
sudo aptitude installl libzip-dev
tar -zxvf bzip2-1.0.6.tar.gz -C ~/software
cd ~/software/sqlite-autoconf-3240000
./configure --prefix=/usr/local/sqlite3
make
sudo make install
./configure
make
sudo make install
进行构建测试make test,就剩2个了
The necessary bits to build these optional modules were not found:
_dbm _lzma
所以说啊,是否使用apt工具安装,没什么关系OTL
但是啊,虽然在make test中看不到bz2了,在终端尝试导入,依然是不行的
Python 3.6.6
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bz2
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.6/bz2.py", line 23, in
from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'
>>>
但是的但是,这时在pycharm中是可以成功导入bz2模块的,真是神奇。。而且即使不对bz2进行源代码安装,pycharm中依然可以导入bz2模块。。。emmmmm
反正就这样吧,我决定回档使用3.6.5,3.6.6在ubuntu18.04上实在太神奇了,有些驾驭不住
补充说明
虽然安装pythoin3.6.6之后,使用命令
pip3 --version
可以看到有安装pip 10.0.1,但是,如果使用pycharm,创建虚拟环境,是会报错的
No module named 'distutils.core'
也就是,没有第三方模块管理工具,并且根据提示也安装不上
此时应退出pycharm,进入终端,安装python3-pip
sudo aptitude install python3-pip
之后在pycharm中根据提示安装工具,就能安装上了
sudo aptitude install python-lzma
sudo aptitude install liblzma-dev
cd ~/software/Python3.6.6
./configure
make
sudo make install
Python 3.6.6
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lzma
>>>
这次没有报错,可以正常导入
另外,make test显示
The necessary bits to build these optional modules were not found:
_dbm
ok,暂告结束