一般使用源代码编译完Python3后,会出现多个常用包没有编译出来,并且交互式Python3不能用退格。
下文介绍如何解决。
常见问题:
1.Python3交互式时不能使用退格和方向键。原因:编译Python3时,依赖readline-devel库
2.解决无法引入curses库。原因:编译Python3时,依赖ncurses-devel库
3.解决无法引入sqlite3库。原因:编译Python3时,依赖sqlite3-devel库
具体编译过程:
如果已安装相关devel库,则直接编译python3即可解决。
下面是根据TarBall方式安装各依赖包至非标准目录,最后编译python3。
1.zlib。被sqlite3以及python3依赖。
说明:zlib很简单,不需要复杂配置,直接编译即可。
./configure --prefix=/home/linuxuser/freeware/zlb
make
make install
2.ncurses。被readline以及python依赖。
./configure --prefix=/home/linuxuser/freeware/ncurses --without-cxx --without-cxx-binding --with-shared
make
make install
3.readline。被python依赖。
说明:需要在编译选项中配置ncurses安装目录,生成makefile时,使用编译选项--with-curses替换对termcap依赖。
export CFLAGS="-I/home/linuxuser/freeware/ncurses/include"
export LDFLAGS="-L/home/linuxuser/freeware/ncurses/lib"
./configure --prefix=/home/linuxuser/freeware/readline --with-curses
make
make install
4.sqlite3。被python3依赖。
说明:需要在编译选项中配置readline、ncurses目录以便sqlite3可执行程序,可以使用退格。此步骤可选。
需要在编译选项中配置zlib、pthread、dl等选项,可选。
export CPPFLAGS="-I/home/linuxuser/freeware/ncurses/include -I/home/linuxuser/freeware/readline/include -I/home/linuxuser/freeware/zlib/include"
export LDFLAGS="-L/home/linuxuser/freeware/ncurses/lib -L/home/linuxuser/freeware/readline/lib -L/home/linuxuser/freeware/zlib/lib"
export LIBS="-lpthread -lz -lncurses"
./configure --prefix=/home/linuxuser/freeware/sqlite3 --enable-readline
make
make install
5.python3
说明:配置以上各组件目录。注意ncurses的头文件包含目录需要多配置一层,即/home/linuxuser/freeware/ncurses/include/ncurses
export CPPFLAGS="-I/home/linuxuser/freeware/ncurses/include -I/home/linuxuser/freeware/ncurses/include/ncurses -I/home/linuxuser/freeware/sqlite3/include/
-I/home/linuxuser/freeware/readline/include -I/home/linuxuser/freeware/zlib/include"
export LDFLAGS="-L/home/linuxuser/freeware/ncurses/lib -L/home/linuxuser/freeware/readline/lib -L/home/linuxuser/freeware/zlib/lib -L/home/linuxuser/freeware/sqlite3/lib"
export LIBS="-lncurses"
./configure --prefix=/home/linuxuser/freeware/python3 --enable-shared
make
make install
按照此步骤,常见组件安装ok
可以看make结果,sqlite3 curses readline都没有在失败列表
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _dbm _gdbm
_lzma _ssl _tkinter
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
atexit pwd time
编译完成后,配置 LD_LIBRARY_PATH 大功告成。
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有