Linux_Python 安装

    本文写于 20190712 ,目前python 对于 linux 与 mac 的安装比较友好,linux 只能源码编译安装,

我们记录下安装过程,本文针对的是 Python 3.7.4 的 Linux 安装过程。

 

Step1 : 下载安装包


首先,我们通过 wget 将压缩包下载下来 :


wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz

将 tgz 包解压到一个目录 ( 确保目录已经存在 ) 

tar -xvf Python-3.7.4.tgz -C python/

 

Step2 :安装依赖

 

在正式安装前,我们需要安装 一些 额外的依赖 

此处是 Centos , 其他的系统自动换为其他系统的安装指令

yum install gcc gcc-c++ libffi-devel


Step 3  正式安装

 

进入到解压好的目录, 查看下里面都有什么文件:

[root@dev-109-kvm Python-3.7.4]# ll
total 40164
-rw-r--r--  1  501  501    10953 Jul  9 02:03 aclocal.m4
drwxr-xr-x  5 root root       82 Jul 12 11:25 build
-rw-r--r--  1  501  501      631 Jul  9 02:03 CODE_OF_CONDUCT.rst
-rwxr-xr-x  1  501  501    44166 Jul  9 02:03 config.guess
-rw-r--r--  1 root root   924713 Jul 12 11:19 config.log
-rwxr-xr-x  1 root root    40834 Jul 12 11:19 config.status
-rwxr-xr-x  1  501  501    36251 Jul  9 02:03 config.sub
-rwxr-xr-x  1  501  501   503641 Jul  9 02:03 configure
-rw-r--r--  1  501  501   167840 Jul  9 02:03 configure.ac
drwxr-xr-x 18  501  501     4096 Jul  9 02:31 Doc
drwxr-xr-x  2  501  501       21 Jul  9 02:03 Grammar
drwxr-xr-x  3  501  501     4096 Jul  9 02:03 Include
-rwxr-xr-x  1  501  501     7122 Jul  9 02:03 install-sh
drwxr-xr-x 34  501  501     8192 Jul 12 11:24 Lib
-rw-r--r--  1 root root 24810386 Jul 12 11:24 libpython3.7m.a
-rw-r--r--  1  501  501    12769 Jul  9 02:03 LICENSE
drwxr-xr-x  2  501  501       33 Jul  9 02:03 m4
drwxr-xr-x  8  501  501      160 Jul  9 02:03 Mac
-rw-r--r--  1 root root    72420 Jul 12 11:19 Makefile
-rw-r--r--  1 root root    63330 Jul 12 11:19 Makefile.pre
-rw-r--r--  1  501  501    63658 Jul  9 02:03 Makefile.pre.in
drwxr-xr-x  2  501  501     4096 Jul 12 11:19 Misc
drwxr-xr-x 13  501  501     8192 Jul 12 11:24 Modules
drwxr-xr-x  4  501  501     4096 Jul 12 11:23 Objects
drwxr-xr-x  2  501  501     4096 Jul 12 11:22 Parser
drwxr-xr-x  6  501  501     4096 Jul  9 02:03 PC
drwxr-xr-x  2  501  501     4096 Jul  9 02:03 PCbuild
drwxr-xr-x  2  501  501      137 Jul 12 11:25 Programs
-rw-r--r--  1 root root       26 Jul 12 11:24 pybuilddir.txt
-rw-r--r--  1 root root    45270 Jul 12 11:19 pyconfig.h
-rw-r--r--  1  501  501    43204 Jul  9 02:03 pyconfig.h.in
-rwxr-xr-x  1 root root 13988176 Jul 12 11:24 python
drwxr-xr-x  3  501  501     4096 Jul 12 11:24 Python
-rw-r--r--  1 root root     2917 Jul 12 11:25 python-config
-rw-r--r--  1 root root     1950 Jul 12 11:25 python-config.py
-rw-r--r--  1 root root    65363 Jul 12 11:25 python-gdb.py
-rw-r--r--  1  501  501    10113 Jul  9 02:03 README.rst
-rw-r--r--  1  501  501   103776 Jul  9 02:03 setup.py
drwxr-xr-x 23  501  501      322 Jul  9 02:03 Tools

 

 

配置 python 的安装目录 :  

./configure --prefix=/opt/PYTHON_HOME/Python37

该步奏主要是检查环境是否满足安装需要

checking for X509_VERIFY_PARAM_set1_host in libssl... yes
checking for --with-ssl-default-suites... python
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup
creating Modules/Setup.local
creating Makefile


If you want a release build with all stable optimizations active (PGO, etc),
please run ./configure --enable-optimizations

 

 

编译 并 安装 

make && make install

 

 

Step4 : 校验

 

进入安装好的目录 :

cd /opt/PYTHON_HOME/Python37/

查看 :

[root@dev-109-kvm Python37]# ll
total 0
drwxr-xr-x 2 root root 295 Jul 12 11:30 bin
drwxr-xr-x 3 root root  24 Jul 12 11:26 include
drwxr-xr-x 4 root root  63 Jul 12 11:29 lib
drwxr-xr-x 3 root root  17 Jul 12 11:26 share

 

进入 bin , 执行 python3

[root@dev-109-kvm bin]# ./python3
Python 3.7.4 (default, Jul 12 2019, 11:24:17) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

 

好了,安装完成 !!!

 

Extra  : 遇到的问题与解决方法

 

问题一 :ModuleNotFoundError: No module named '_ctypes'

 

完整报错:

  File "/tmp/tmpz0xux87_/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/__init__.py", line 40, in <module>
  File "/tmp/tmpz0xux87_/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py", line 8, in <module>
  File "/tmp/tmpz0xux87_/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py", line 12, in <module>
  File "/tmp/tmpz0xux87_/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/__init__.py", line 6, in <module>
  File "/tmp/tmpz0xux87_/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/completion.py", line 6, in <module>
  File "/tmp/tmpz0xux87_/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/base_command.py", line 20, in <module>
  File "/tmp/tmpz0xux87_/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/download.py", line 37, in <module>
  File "/tmp/tmpz0xux87_/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/utils/glibc.py", line 3, in <module>
  File "/opt/PYTHON_HOME/Python-3.7.4/Lib/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

 

解决方法 :

Python 3.7 + 需要一个额外的包  libffi-devel

yum install libffi-devel -y

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值