Ubuntu下编译Python2.7
步骤
- 因 python 使用 ANSI 编写,所以在各平台上编译一般都顺利
- Download souce code from www.python.org/
- 参考相应最新的编译说明,如 docs.python.org/2.7/using/unix.html#building-python 以及源码中的 ./configure 说明等
- make and make install
Attention
-
安装路径,参考 ./configure 说明,设置 --prefix 用于以后 make install 路径,以免覆盖系统 python
-
make 时出现如下类似提示,不必慌张。如 readline 依赖,先 sudo apt-get install libreadline-dev, 然后重新 make clean ./configure make 其它库也类似。重要的是参考对应的官方说明加GOOGLE,比如先前版本的编译是在 ./configure 加参数 --with-readline 来增加此支持,但新版已去除此配置。可以参考 Building Python and more on missing modules
Python build finished, but the necessary bits to build these modules were not found: _bsddb _curses _curses_panel _tkinter bsddb185 bz2 dbm gdbm readline sunaudiodev _sqlite3 To find the necessary bits, look in setup.py in detect_modules() for the module's name.
-
最后 make install 到之前 --prefix 配置的相应目录下
-
补充 Linux Python 路径下 dist-packages site-packages 的区别。总的来说是,系统或Python工具安装的包位于各个 dist-packages 路径下,而用户手动安装的位于 site-packages。参考 Python 路径下 dist-packages site-packages 区别