源码包编译安装python_Python3.7源码包编译安装-Go语言中文社区
環境:
[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 相關模塊。readline 是 bash 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、快速啟動
方法一:生成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 ~]#
方法二:更改別名
為使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 [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 to a verbose appending log.
--proxy Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries Maximum number of retries each connection should attempt (default 5 times).
--timeout Set the socket timeout (default 15 seconds).
--exists-action Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort).
--trusted-host Mark this host as trusted, even though it does not have valid or any HTTPS.
--cert Path to alternate CA bundle.
--client-cert Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
--cache-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 ~]#
總結
以上是生活随笔為你收集整理的源码包编译安装python_Python3.7源码包编译安装-Go语言中文社区的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python学习与数据挖掘_Python
- 下一篇: java criteria and_cr