python源码多平台编译_Python3源码方式编译

一般使用源代码编译完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 大功告成。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值