ubuntu编译python源码的坑

在linux平台下编译python时只需要3条命令.

编译步骤

在github或https://www.python.org/downloads/中下载python源码

解压压缩包进路目录执行

1. ./configure --prefix=你想安装python的全路径 [--enable-shared在bin目录下生成libpython版本号,so文件 编译成动态链接可选]

2. make

3. make install 

编译出现的错:

在第2个命令make是可能出现错误

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DPy_BUILD_CORE -c ./Modules/xxsubtype.c -o Modules/xxsubtype.o
gcc -pthread -c -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DPy_BUILD_CORE -DSVNVERSION=\"`LANG=C svnversion .`\" -o Modules/getbuildinfo.o ./Modules/getbuildinfo.c
gcc: error: directory": 没有那个文件或目录
make: *** [Modules/getbuildinfo.o] 错误 1

这里说的是svn的版本好出问题了,解决方法1.

编辑Makefile 将的SVNVERSION设置为"", 即SVNVERSION=""

解决方案2.

查看自己本地的svn版本:1.svn --version 2.将SVNVERSION设置为自己对应的版本,export SVNVERSION=1.x.x SVN版本号.

 

在第2个命令make l时可能出现的错误

running build
running build_ext
sqlite: found /usr/include/sqlite3.h
/usr/include/sqlite3.h: version 3.8.2
Traceback (most recent call last):
File "./setup.py", line 1524, in <module>
main()
File "./setup.py", line 1519, in main
'Lib/smtpd.py']
File "/home/cht/code/sourceCode/Python-2.5/Lib/distutils/core.py", line 151, in setup
dist.run_commands()
File "/home/cht/code/sourceCode/Python-2.5/Lib/distutils/dist.py", line 974, in run_commands
self.run_command(cmd)
File "/home/cht/code/sourceCode/Python-2.5/Lib/distutils/dist.py", line 994, in run_command
cmd_obj.run()
File "/home/cht/code/sourceCode/Python-2.5/Lib/distutils/command/build.py", line 112, in run
self.run_command(cmd_name)
File "/home/cht/code/sourceCode/Python-2.5/Lib/distutils/cmd.py", line 333, in run_command
self.distribution.run_command(command)
File "/home/cht/code/sourceCode/Python-2.5/Lib/distutils/dist.py", line 994, in run_command
cmd_obj.run()
File "/home/cht/code/sourceCode/Python-2.5/Lib/distutils/command/build_ext.py", line 281, in run
self.build_extensions()
File "./setup.py", line 97, in build_extensions
self.detect_modules()
File "./setup.py", line 795, in detect_modules
sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
File "/home/cht/code/sourceCode/Python-2.5/Lib/posixpath.py", line 119, in dirname
return split(p)[0]
File "/home/cht/code/sourceCode/Python-2.5/Lib/posixpath.py", line 77, in split
i = p.rfind('/') + 1
AttributeError: 'NoneType' object has no attribute 'rfind'
make: *** [sharedmods] 错误 1

这是python源码用了 /usr/include/sqlite3.h,p原本应该是个str对象导致p最后为None,临时解决方法

将 /usr/include/sqlite3.h先重命名 >> sudo mv  /usr/include/sqlite3.h  /usr/include/sqlite3.h_ 在命执行make和make install 就不会出现这个错误了.

执行完后将sqllite3.h改回 >> sudo mv  /usr/include/sqlite3.h_  /usr/include/sqlite3.h

 

 

 

 

 

 

 

 

posted @ 2018-06-14 19:18  sea101  阅读(3198)  评论(0编辑  收藏  举报