最近在看一本python的书CPython Internals,打算研究一下CPython的代码,然后就在Linux(ubuntu)下编译了CPython源码,在此记录一下。

1. 使用git下载cpython源码

git clone --branch 3.9 https://github.com/python/cpython
cd cpython

2. 使用weget下载cpython3.9.7版本,使用这种是适用于没安装git或者访问github网络比较差的小伙伴

 wget https://github.com/python/cpython/archive/refs/tags/v3.9.7.tar.gztar zxf v3.9.7.tar.gzcd cpython-3.9.7

3. 下载完成之后,需要对cpython进行编译

# 编译工具安装
sudo apt install build-essential
# 依赖库安装
sudo apt install libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev libffi-dev

4. 运行配置脚本,配置的时候选择一个debug模式,也可以不选择,这个看个人选择。

./configure --with-pydebug

5. 生成Makefile,j2表示启动两个job来加速编译,-s 表示silent,即不打印output

 make -j2 -s

注:在linux执行make --help可参考具体的参数选项

mark123@ubuntu-vm:~/cpythonCode/cpython$ make --help
Usage: make [options] [target] ...
Options:-b, -m                      Ignored for compatibility.-B, --always-make           Unconditionally make all targets.-C DIRECTORY, --directory=DIRECTORYChange to DIRECTORY before doing anything.-d                          Print lots of debugging information.--debug[=FLAGS]             Print various types of debugging information.-e, --environment-overridesEnvironment variables override makefiles.--eval=STRING               Evaluate STRING as a makefile statement.-f FILE, --file=FILE, --makefile=FILERead FILE as a makefile.-h, --help                  Print this message and exit.-i, --ignore-errors         Ignore errors from recipes.-I DIRECTORY, --include-dir=DIRECTORYSearch DIRECTORY for included makefiles.-j [N], --jobs[=N]          Allow N jobs at once; infinite jobs with no arg.-k, --keep-going            Keep going when some targets can't be made.-l [N], --load-average[=N], --max-load[=N]Don't start multiple jobs unless load is below N.-L, --check-symlink-times   Use the latest mtime between symlinks and target.-n, --just-print, --dry-run, --reconDon't actually run any recipe; just print them.-o FILE, --old-file=FILE, --assume-old=FILEConsider FILE to be very old and don't remake it.-O[TYPE], --output-sync[=TYPE]Synchronize output of parallel jobs by TYPE.-p, --print-data-base       Print make's internal database.-q, --question              Run no recipe; exit status says if up to date.-r, --no-builtin-rules      Disable the built-in implicit rules.-R, --no-builtin-variables  Disable the built-in variable settings.-s, --silent, --quiet       Don't echo recipes.-S, --no-keep-going, --stopTurns off -k.-t, --touch                 Touch targets instead of remaking them.--trace                     Print tracing information.-v, --version               Print the version number of make and exit.-w, --print-directory       Print the current directory.--no-print-directory        Turn off -w, even if it was turned on implicitly.-W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILEConsider FILE to be infinitely new.--warn-undefined-variables  Warn when an undefined variable is referenced.This program built for x86_64-pc-linux-gnu
Report bugs to <bug-make@gnu.org>
mark123@ubuntu-vm:~/cpythonCode/cpython$

6. 执行./python 进入python交互式环境

mark123@ubuntu-vm:~/cpythonCode/cpython$ ./python
Python 3.9.7 (default, Sep 11 2021, 15:23:18)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>

至此,CPython源码已经编译完成。

Linux下CPython源码的编译相关推荐

  1. 初步了解mac下C源码的编译过程

    初步了解mac下C源码的编译过程 参考: 请问Mac OS X (10.9.1)下创建和使用动态链接库的方法 cc.gcc.g++.CC的区别概括 - 今晚打酱油_ - 博客园 Linux 下 的 c ...

  2. Ubuntu16下bitcoin源码的编译与运行-2021

    Ubuntu16下bitcoin源码的编译与运行 1.更新软件列表 2.安装依赖包 3.将源代码克隆到本地 4.编译运行 5.回到./bitcoin目录下重新编译 6.编写配置文件 7.bitcoin ...

  3. Linux下qwt源码编译,QWT的编译与配置

    QWT,全称是Qt Widgets for Technical Applications,是一个基于LGPL版权协议的开源项目, 可生成各种统计图.它为具有技术专业背景的程序提供GUI组件和一组实用类 ...

  4. 01 linux 下tcl源码编译安装和tcl手册使用

    标签(空格分隔): 源码编译安装 2020.7.7 1 下载安装包.tar.gz 2 解压压缩包 3 进入configure文件所在文件夹,执行./configure ./configure 注解: ...

  5. Linux下Poppler源码编译安装

    Poppler Poppler是用于呈现可移植文档格式(PDF)文档的免费软件实用程序库.它的开发得到freedesktop.org的支持.它通常在Linux系统上使用,并被开源GNOME和KDE桌面 ...

  6. Linux下阅读源码工具

    闲来无事,于是又想进到Linux内核里面去逛逛了,但是只装了个ctags的工具,虽然说它可以在源码中到处跳动查看代码,但是感觉应该会有更好的方法. 虽然说可以转到windows下面去使用SourceI ...

  7. Linux下软件源码包安装问题解决方法

    从源码包安装软件最重要的就是仔细阅读README INSTALL等说明文件 通常从源码包安装软件的步骤是: tar jxvf gtk+-2.4.13.tar.bz2 解开源码包 cd gtk+-2.4 ...

  8. linux下free源码,linux命令free源码解读:Procps free.c

    linux命令free源码解读 linux命令free源码解读:Procps free.c 作者:isayme 发布时间:September 26, 2011 分类:Linux 我们讨论的是linux ...

  9. Linux 下 PostgreSQL 源码编译安装

    由于微信不允许外部链接,你需要点击文章尾部左下角的 "阅读原文",才能访问文中链接. PostgreSQL 是一个功能强大的开源对象关系数据库管理系统(ORDBMS),它从伯克利写 ...

最新文章

  1. HMM+三个基本问题
  2. struts2添加需要的jar包
  3. Jchatting通过Sina SAE云开发平台高级开发者认证
  4. percona mysql安装_mysql 安装 (percona)
  5. list类型的应用场景 —— Redis实战经验
  6. zabbix3.4搭建钉钉报警
  7. Python才是世界上最好的语言
  8. 一文搞定C语言本地变量和全局变量
  9. printf按8进制、16进制输出
  10. Laravel 将数据表中的数据导出,并生成seed文件
  11. 收集程序员动图,不幽默我捶自己!
  12. git关闭密码自动存储_RobotFramework实战篇PC端web自动化demo及持续集成
  13. 【MyBatis框架】订单商品数据模型-分析思路
  14. Vue.js 条件渲染 v-if、v-show、v-else
  15. Windows Server AppFabric缓存参考实例和方案选择 2/3
  16. 容器技术Docker K8s 38 Serverless Kubernetes(ASK)详解-阿里云Serverless容器(ASK)产品介绍
  17. python数据库连接池_Python数据库连接池 -组件 DBUtils
  18. WebService的知识总结(一)
  19. 智能优化算法的常用改进方法
  20. Java由浅入深,考试or面试专用(自我整理)

热门文章

  1. java endpoint_大牛带你深入SpringBoot:自定义Endpoint 及实现原理
  2. 小白转行3D建模,线上课和线下培训怎么选?优缺点全方面分析
  3. 巴山老狼《丑陋的中国皇帝》系列之九——古代历史上与秦始皇齐名的暴君隋炀帝
  4. 微软ERP的制造业解决方案(转)
  5. U盘误删除文件?迅龙数据恢复软件轻松找回数据
  6. 中国剩余定理 - CRT and Garner’s Algorithm
  7. java.lang.NoClassDefFoundError: org/xmlpull/mxp1/MXParser
  8. django教程03
  9. Ansible PlayBook语法
  10. 六轴机械臂正逆解计算