Python3.7源码包编译安装

摘要:
看到Python-3.7.2.tgz然后根据地址栏的链接拼接成如下链接:https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz我们回到Linux终端,开始下载Python3.7源码包:这里需要新建一个文件夹/usr/local/src/以保存下载的源码包和待会解压之后的文件。[root@localhost~]#mkdir/usr/local/src#如果存在请忽略[root@localhost~]#cd/usr/local/src/[root@localhostsrc]#wgethttps://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz2、下载完成后解压缩:[root@localhostsrc]#ls-al|grepPython-rw-r--r--1rootroot2289780212月2411:42Python-3.7.2.tgz[root@localhostsrc]#tar-zxvfPython-3.7.2.tgz...[root@localhostsrc]#ls-al|grepPythondrwxr-xr-x18501501409612月2411:41Python-3.7.2-rw-r--r--1rootroot2289780212月2411:42Python-3.7.2.tgz[root@localhostsrc]#3、指定安装位置./configure--prefix=安装路径,这里建议安装在/usr/local/python3下面,即:[root@localhostPython-3.7.2]#cdPython-3.7.2/[root@localhostPython-3.7.2]#./configure--prefix=/usr/local/python34、编译编译之前请确认是否安装安装readline相关模块。如果没有安装,请执行:yum-yinstallreadlinereadline-devel上述操作完成之后,开始编译:make编译[root@localhostPython-3.7.2]#make编译时间取决于硬件配置,耐心等待。
环境:
[root@localhost python3]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core) 
[root@localhost python3]# 
1、下载Python

方式一:

方式二:

  • 进入https://www.python.org/ftp/python/ 这里存放着所有版本的Python源码。往下拉看到最新版本3.7.2/,点击进入
    在这里插入图片描述

    在这里插入图片描述

  • 看到Python-3.7.2.tgz

在这里插入图片描述

我们回到Linux终端,开始下载Python3.7源码包:
这里需要新建一个文件夹/usr/local/src/以保存下载的源码包和待会解压之后的文件。

[root@localhost ~]# mkdir /usr/local/src  # 如果存在请忽略
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
2、下载完成后解压缩:
[root@localhost src]# ls -al | grep Python
-rw-r--r--   1 root root   22897802 12月 24 11:42 Python-3.7.2.tgz
[root@localhost src]# tar -zxvf Python-3.7.2.tgz
...
[root@localhost src]# ls -al | grep Python
drwxr-xr-x  18  501   501      4096 12月 24 11:41 Python-3.7.2
-rw-r--r--   1 root root   22897802 12月 24 11:42 Python-3.7.2.tgz
[root@localhost src]# 
3、 指定安装位置

./configure --prefix=安装路径,这里建议安装在/usr/local/python3下面,即:

[root@localhost Python-3.7.2]# cd Python-3.7.2/
[root@localhost Python-3.7.2]# ./configure --prefix=/usr/local/python3
4、编译

编译之前请确认是否安装安装 readline 相关模块readlinebash shell 用的库,包含许多使用功能,例如:命令行自动补全。
如果没有安装,请执行:yum -y install readline readline-devel

上述操作完成之后,开始编译:
make编译

[root@localhost Python-3.7.2]# make

编译时间取决于硬件配置,耐心等待。

5、安装

make install 编译安装

[root@localhost Python-3.7.2]# make install

如果安装出现异常ModuleNotFoundError: No module named '_ctypes',不要慌,这是因为在安装Python3.7以上版本时,需要一个新的libffi-devel包做依赖,执行命令安装:

yum -y install libffi-devel

安装完成后,重新执行make install即可。

Looking in links: /tmp/tmpea1pr1kb
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-18.1 setuptools-40.6.2
[root@localhost Python-3.7.2]# 
6、启动

如果没有异常,则启动Python3.7测试一下是否安装成功:
启动位置:/usr/local/python3/bin/python3

[root@localhost Python-3.7.2]# cd ~
[root@localhost ~]# ls -al /usr/local/python3/
总用量 0
drwxr-xr-x   6 root root  56 1月  29 19:53 .
drwxr-xr-x. 19 root root 222 1月  29 19:53 ..
drwxr-xr-x   2 root root 295 1月  29 19:53 bin
drwxr-xr-x   3 root root  24 1月  29 19:53 include
drwxr-xr-x   4 root root  63 1月  29 19:53 lib
drwxr-xr-x   3 root root  17 1月  29 19:53 share
[root@localhost ~]# /usr/local/python3/bin/p
pip3               pydoc3             python3            python3.7-config   python3.7m-config  pyvenv             
pip3.7             pydoc3.7           python3.7          python3.7m         python3-config     pyvenv-3.7         
[root@localhost ~]# /usr/local/python3/bin/python3
Python 3.7.2 (default, Jan 29 2019, 19:48:46) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@localhost ~]# /usr/local/python3/bin/python3.7
Python 3.7.2 (default, Jan 29 2019, 19:48:46) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()      
[root@localhost ~]# 
7、快速启动
  1. 方法一:生成Python3的软链接

/usr/bin路径下生成Python3的软链接:ln -s /usr/local/python3/bin/python3 /usr/bin/python3

[root@localhost ~]# rm -rf /usr/bin/python3
[root@localhost ~]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@localhost ~]# python3
Python 3.7.2 (default, Jan 29 2019, 19:48:46) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@localhost ~]# 
  1. 方法二:更改别名

为使Python3和pip正常使用,请修改文件~.bashrc文件——指明pip3和python3的别名。
在文件末尾添加下面的语句:

alias python3='/usr/local/python3/bin/python3.7'
alias pip3='/usr/local/python3/bin/pip3'

详细过程如下:

[root@localhost bin]# cd ~
[root@localhost ~]# ls -al /usr/local/python3/bin/ 
总用量 27336
drwxr-xr-x 2 root root      295 1月  30 12:27 .
drwxr-xr-x 6 root root       56 1月  30 12:27 ..
lrwxrwxrwx 1 root root        8 1月  30 12:27 2to3 -> 2to3-3.7
-rwxr-xr-x 1 root root      109 1月  30 12:27 2to3-3.7
-rwxr-xr-x 1 root root      250 1月  30 12:27 easy_install-3.7
lrwxrwxrwx 1 root root        7 1月  30 12:27 idle3 -> idle3.7
-rwxr-xr-x 1 root root      107 1月  30 12:27 idle3.7
-rwxr-xr-x 1 root root      232 1月  30 12:27 pip3
-rwxr-xr-x 1 root root      232 1月  30 12:27 pip3.7
lrwxrwxrwx 1 root root        8 1月  30 12:27 pydoc3 -> pydoc3.7
-rwxr-xr-x 1 root root       92 1月  30 12:27 pydoc3.7
lrwxrwxrwx 1 root root        9 1月  30 12:27 python3 -> python3.7
-rwxr-xr-x 2 root root 13979352 1月  30 12:27 python3.7
lrwxrwxrwx 1 root root       17 1月  30 12:27 python3.7-config -> python3.7m-config
-rwxr-xr-x 2 root root 13979352 1月  30 12:27 python3.7m
-rwxr-xr-x 1 root root     3105 1月  30 12:27 python3.7m-config
lrwxrwxrwx 1 root root       16 1月  30 12:27 python3-config -> python3.7-config
lrwxrwxrwx 1 root root       10 1月  30 12:27 pyvenv -> pyvenv-3.7
-rwxr-xr-x 1 root root      449 1月  30 12:27 pyvenv-3.7
[root@localhost ~]# cat .bashrc 
# .bashrc

# User specific aliases and functions
...
[root@localhost ~]# vim .bashrc 
# .bashrc

# User specific aliases and functions
...
alias python3='/usr/local/python3/bin/python3.7'
alias pip3='/usr/local/python3/bin/pip3'
                                                                                                                                                              
:wq
[root@localhost ~]# cat .bashrc 
# .bashrc

# User specific aliases and functions
...
alias python3='/usr/local/python3/bin/python3.7'
alias pip3='/usr/local/python3/bin/pip3'
[root@localhost ~]# 

测试pip:不要忘记source编译

[root@localhost ~]# pip3
bash: pip3: 未找到命令...
[root@localhost ~]# source ~/.bashrc      
[root@localhost ~]# pip3

Usage:   
  pip3 <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging
                              levels).
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort).
  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
  --no-color                  Suppress colored output
[root@localhost ~]# 

免责声明:文章转载自《Python3.7源码包编译安装》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇webview个别页面显示空白cscope的使用下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Scala学习2——idea配置scala环境,scala初步学习

了解Scala 使用Java Decompiler反编译字节码到.class源文件可以看到引入Scala库的逻辑。并且: scala源文件中的HelloScala对象编译后成为了一个类,但对象本身编译后就是生成的另一个类HelloScala$类的单例对象HelloScala$.MODULE$,称之为伴生对象。 HelloScala$有一个main实例方...

GUI的最终选择 Tkinter(九):事件

Tkinter事件处理 Tkinter应用会花费大部分的时间在处理事件循环中(通过mainloop()方法进入),事件可以是触发的鼠标,键盘的操作,管理窗口触发的重绘事件(在多数情况下都是有用户间接引起的)。 Tkinter提供了一个强大的机制,可以让你自由的去处理事件,对于每个组件来说。可以通过bond()方法将函数或者方法绑定到具体的事件上。当触发器的...

ubuntu 14.04 源码编译mysql-5.7.17

环境为 Ubuntu 12.04 64 位的桌面版 编译的mysql 版本为 5.7.18 首先需要安装一下依赖包 sudo apt-get install libncurses5-dev cmake chkconfig 创建用户组和用户 mysql groupadd mysql useradd -r -g mysql -s /bin/bash mysq...

升级openssl 支持TLS1.2

升级openssl 支持TLS1.2 支持TLS1.2 背景: 现在许多网站,都要求tls1.2协议以上,像github、 pip3安装包网站https://pip.pypa.io/等。 openssl现有版本不支持。需要升级openssl。 git 底层使用curl库,curl库又调用的libopenssl库。 如果希望git支持tls1.2,需要更新c...

用sublime text3 建立python编译系统

前面有了sublime text3以及python3 的安装教程,现在来用sublime text3 来构建一个python3的编译环境 首先安装package control和sublimeREPL 直接在install package下搜索sublimeREPL就可以了。 然后配置编译系统,点击Tools->Build System->Ne...

Matlab画图中图的方法

大家画图时可能会发现,有些地方太小了,看不清楚!但是这个小的部分,恰恰是我们需要强调的地方!怎么办?如何放大!其实matlab中的magnify函数可以解决我们这个问题。 第一步首先百度文库:magnify matlab源程序;找到对应的代码。   找到代码之后,我们将里面的源程序代码,复制到matlab新建的m文件。注意文件名为:magnif...