linux中python安装

1、查看当前环境中是否存在python安装包

[[email protected] ~]$  rpm -qa | grep python
gnome-python2-gnome-2.28.0-3.el6.x86_64
python-slip-0.2.20-1.el6_2.noarch
python-iniparse-0.3.1-2.1.el6.noarch
python-pycurl-7.19.0-9.el6.x86_64
gnome-python2-gconf-2.28.0-3.el6.x86_64
gnome-python2-extras-2.25.3-20.el6.x86_64
gnome-python2-libegg-2.25.3-20.el6.x86_64
notify-python-0.1.1-10.el6.x86_64
python-libs-2.6.6-66.el6_8.x86_64
python-ethtool-0.6-6.el6.x86_64
python-mako-0.3.4-1.el6.noarch
abrt-python-2.0.8-43.el6.centos.x86_64
gnome-python2-gnomekeyring-2.28.0-5.el6.x86_64
gnome-python2-bonobo-2.28.0-3.el6.x86_64
python-meh-0.12.1-3.el6.noarch
python-2.6.6-66.el6_8.x86_64
libuser-python-0.56.13-8.el6_7.x86_64

2、在官网上查看最新的版本;也可以通过yum install 安装python安装包,但是有可能yum源上面没有最新的python版本,所以采用下载的方式安装最新的安装包。

https://www.python.org/downloads/source/

[[email protected] home]# yum info python  //查看yum源上的py安装包信息
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Installed Packages
Name        : python
Arch        : x86_64
Version     : 2.6.6
Release     : 66.el6_8
Size        : 78 k
Repo        : installed
From repo   : anaconda-CentOS-201703281317.x86_64
Summary     : An interpreted, interactive, object-oriented programming language
URL         : http://www.python.org/
License     : Python
Description : Python is an interpreted, interactive, object-oriented programming
            : language often compared to Tcl, Perl, Scheme or Java. Python includes
            : modules, classes, exceptions, very high level dynamic data types and
            : dynamic typing. Python supports interfaces to many system calls and
            : libraries, as well as to various windowing systems (X11, Motif, Tk,
            : Mac and MFC).
            :
            : Programmers can write new built-in modules for Python in C or C++.
            : Python can be used as an extension language for applications that need
            : a programmable interface.
            :
            : Note that documentation for Python is provided in the python-docs
            : package.
            :
            : This package provides the "python" executable; most of the actual
            : implementation is within the "python-libs" package.
[[email protected] home]#
[[email protected] home]# yum search python3  //查询yum源是否有?
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Warning: No matches found for: python3
No Matches found

3、安装python源码:


  •  下载:将安装包上传到linux的家目录下
[[email protected] home]# cd zyj
[[email protected] zyj]# ll
total 31312
drwxr-xr-x. 2 zyj zyj     4096 Apr 14 09:13 Desktop
drwxr-xr-x. 2 zyj zyj     4096 Apr 14 09:13 Documents
drwxr-xr-x. 2 zyj zyj     4096 Apr 14 09:13 Downloads
drwxr-xr-x. 2 zyj zyj     4096 Apr 14 09:13 Music
drwxr-xr-x. 2 zyj zyj     4096 Apr 14 09:13 Pictures
drwxr-xr-x. 2 zyj zyj     4096 Apr 14 09:13 Public
-rw-rw-r--. 1 zyj zyj 22994617 May  1  2018 Python-3.6.5.tgz
drwxr-xr-x. 2 zyj zyj     4096 Apr 14 09:13 Templates
drwxr-xr-x. 2 zyj zyj     4096 Apr 14 09:13 Videos
-rw-rw-r--. 1 zyj zyj  9034460 Apr 27 21:23 mysql-server-5.1.73-8.el6_8.x86_64.rpm
[[email protected]host zyj]# mv Python-3.6.5.tgz ../
[[email protected] home]# ll
total 22472
-rwxrwxrwx.  1 root root       10 Apr 25 11:05 1.txt
-rw-rw-r--.  1 zyj  zyj  22994617 May  1  2018 Python-3.6.5.tgz
-rwxrwxrwx.  1 zyj  zyj        86 Apr 15 09:23 hello.txt
drwxr-xrwx.  2 root root     4096 Apr 15 07:00 x
drwx------. 24 zyj  zyj      4096 May  1 00:00 zyj
  • 查看源码(.c结尾为c语言):在windows下打开压缩包,查看里面文件的后缀。
  • 准备编译环境(检查c语言编译环境,gcc)
[[email protected] home]# rpm -qa | grep gcc
libgcc-4.4.7-18.el6.x86_64
gcc-4.4.7-18.el6.x86_64
[[email protected] home]# yum install gcc-c++ //安装c++编译环境
  • 检查(依赖、兼容),预编译:
[[email protected] home]# tar -zxvf Python-3.6.5.tgz //解压安装包
[[email protected] home]# ls
1.txt  Python-3.6.5  Python-3.6.5.tgz  hello.txt  x  zyj
[[email protected] home]# cd Python-3.6.5 //进入安装包目录下
[[email protected] Python-3.6.5]# ll
total 1036
drwxr-xr-x. 18 sl sl   4096 Mar 28 03:24 Doc
drwxr-xr-x.  2 sl sl   4096 Mar 28 02:19 Grammar
drwxr-xr-x.  2 sl sl   4096 Mar 28 02:19 Include
-rw-r--r--.  1 sl sl  12763 Mar 28 02:19 LICENSE
drwxr-xr-x. 33 sl sl   4096 Mar 28 02:19 Lib
drwxr-xr-x.  8 sl sl   4096 Mar 28 02:19 Mac
-rw-r--r--.  1 sl sl  61032 Mar 28 02:19 Makefile.pre.in
drwxr-xr-x.  2 sl sl   4096 Mar 28 03:24 Misc
drwxr-xr-x. 13 sl sl   4096 Mar 28 02:19 Modules
drwxr-xr-x.  4 sl sl   4096 Mar 28 02:19 Objects
drwxr-xr-x.  6 sl sl   4096 Mar 28 02:19 PC
drwxr-xr-x.  2 sl sl   4096 Mar 28 02:19 PCbuild
drwxr-xr-x.  2 sl sl   4096 Mar 28 02:19 Parser
drwxr-xr-x.  2 sl sl   4096 Mar 28 02:19 Programs
drwxr-xr-x.  3 sl sl   4096 Mar 28 02:19 Python
-rw-r--r--.  1 sl sl   9281 Mar 28 02:19 README.rst
drwxr-xr-x. 23 sl sl   4096 Mar 28 02:19 Tools
-rw-r--r--.  1 sl sl  13335 Mar 28 02:19 aclocal.m4
-rwxr-xr-x.  1 sl sl  44259 Mar 28 02:19 config.guess
-rwxr-xr-x.  1 sl sl  36515 Mar 28 02:19 config.sub
-rwxr-xr-x.  1 sl sl 490243 Mar 28 02:19 configure
-rw-r--r--.  1 sl sl 163178 Mar 28 02:19 configure.ac
-rwxr-xr-x.  1 sl sl   7122 Mar 28 02:19 install-sh
-rw-r--r--.  1 sl sl  42152 Mar 28 02:19 pyconfig.h.in
-rw-r--r--.  1 sl sl 104570 Mar 28 02:19 setup.py

执行可执行文件:
[[email protected] Python-3.6.5]# ./configure --help
`configure‘ configures python 3.6 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...‘ messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache‘
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..‘]

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]
......

Report bugs to <https://bugs.python.org/>.

[[email protected] Python-3.6.5]# ./configure --prefix=/usr/python-3.6.5  //第三方软件安装在/usr/ 目录下。
checking whether gcc -pthread supports computed gotos... yes
checking for build directories... done
checking for -O2... yes
checking for glibc _FORTIFY_SOURCE/memmove bug... no
checking for gcc ipa-pure-const bug... no
checking for stdatomic.h... no
checking for GCC >= 4.7 __atomic builtins... no
checking for ensurepip... upgrade
checking if the dirent structure of a d_type field... yes
checking for the Linux getrandom() syscall... no
checking for the getrandom() function... no
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Modules/Setup.config
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

准备安装依赖包:zlib、openssl。python的pip需要依赖这两个包。

[[email protected] home]# yum install zlib* openssl*  //安装依赖包
[[email protected] home]# cd Python-3.6.5
[[email protected] Python-3.6.5]# ls
Doc      LICENSE  Makefile         Misc     PC       Programs    Tools         config.log     configure     pyconfig.h
Grammar  Lib      Makefile.pre     Modules  PCbuild  Python      aclocal.m4    config.status  configure.ac  pyconfig.h.in
Include  Mac      Makefile.pre.in  Objects  Parser   README.rst  config.guess  config.sub     install-sh    setup.py
[[email protected] Python-3.6.5]# ./configure --prefix=/usr/python-3.6.5 --enable-optimizations  //完整的预编译
...
creating Modules/Setup
creating Modules/Setup.local
creating Makefile  //没有任何报错
[[email protected] Python-3.6.5]# 
  • 编译:make
[[email protected] Python-3.6.5]# make
...
make[1]: Entering directory `/home/Python-3.6.5‘
find . -name ‘*.gc??‘ -exec rm -f {} ‘;‘
find . -name ‘*.profclang?‘ -exec rm -f {} ‘;‘
find . -name ‘*.dyn‘ -exec rm -f {} ‘;‘
rm -f /home/Python-3.6.5/coverage.info
rm -rf /home/Python-3.6.5/lcov-report
make[1]: Leaving directory `/home/Python-3.6.5‘
[[email protected] Python-3.6.5]# //一般检查最后几行有没有error
  • 安装:make install
[[email protected] Python-3.6.5]#make install
......
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-9.0.3 setuptools-39.0.1
[[email protected] Python-3.6.5]#
  • 配置环境变量

原文地址:https://www.cnblogs.com/zhaoyujiao/p/8975669.html

时间: 2024-11-06 07:48:13

linux中python安装的相关文章

Linux 中 Python 安装 (https://www.bilibili.com/video/av22957476/?p=59)

下载——解包——运行configure添加编译参数——编译——安装 Linux中下载安装编译软件(gcc,glibc) Linux root上  写命令: yum  install gcc-* glibc-* -y         安装编译软件 Linux中下载安装开发工具 Linux root上  写命令: yum  groupinstall ‘开发工具’ -y 官网找到安装版本的python源码  复制地址 https://------- Linux root上  写命令: wget htt

linux中编译安装Apache、PHP、MySQL(上)

1.简介 在阿里云买了个云服务器,一直没时间折腾.过了近十天了吧,才有时间好好玩玩这个云服务器.自己是做Web开发的,所以我需要的开发环境是LAMP.之前打算是采用yum安装,不过yum安装apache可以安装到2.4版本,而PHP最高安装版本只能是5.4,这也是yum安装PHP的软肋,因此我这里主要涉及到的安装方式是源码安装.通过源码安装能够更好的管理这些软件,想安装到哪就放在哪. 云服务器: 阿里云CentOS 7.2 64位 阿帕奇版本:apache2.4 PHP版本:PHP5.6 主要的

linux中软件安装方法总结

linux中软件安装方法: 1 rpm -ivh 包名.rpm 有依赖问题,安装A,A需要先安装B,B先安装C等. 2 yum安装,yum包管理器,yum安装解决rpm安装的依赖问题,安装更简单化. 优点:简单,易用,高效 缺点:不能定制 centos切换在线yum源地址为aliyun地址方法: 复制对应版本的切换命令,在centos中输入切换命令即可: [[email protected] tools]# wget -O /etc/yum.repos.d/CentOS-Base.repo ht

linux 中spfvim安装

1. 安装 git 1.1 安装依赖的包: curl          curl-devel     zlib-devel         openssl-devel      perl      cpio      expat-devel getttext-devel 1.2 安装git: wget http://www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.gz tar xzvf git-latest.tar.

Linux中PHP安装与配置(CentOS-6.5:php-5.2.13)

1 PHP简介 PHP(PHP: Hypertext Preprocessor的缩写,中文名:"超文本预处理器")是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点,入门门槛较低,易于学习,使用广泛,主要适用于Web开发领域.PHP的文件后缀名为php. 2 下载地址 1)libmcrpyt ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz 2) php http://ww

Linux中如何安装RAR

在Windows下的winrar几乎一统压缩软件的市场占有率,winrar只是RAR在Windows环境下的图形界面而已,核心功能还是RAR,那么如何在Linux中安装RAR呢? 1.下载RAR下载地址:http://www.rarsoft.com/download.htm,目前最新版为5.0.1. 使用wget下载(32位系统): wget http://www.rarsoft.com/rar/rarlinux-5.0.1.tar.gz 若是64为系统则是: wget http://www.r

云计算学习路线图素材课件,Linux中软件安装的方式

很多初学者感觉云计算就是一个听起来比较高大上的名词,每次想要了解它的时候都像是雾里看花,迷迷糊糊看不真切,至于它是干什么的就更不了解了,其实云计算学起来在IT行业中还是比较容易上手的,接下来我给大家分享Linux中软件安装的方式: 一.源代码形式 绝大多数开源软件都是直接以原码形式发布的,源代码一般会被打包成.tar.gz的归档压缩文件,需要编译成为二进制形式之后才能够运行使用. 源代码基本编译流程: 1).configure 检查编译环境,这里可以通过--prefix等命令配置安装路径(好像)

linux下python安装到指定目录

由于使用公司服务器时没有root权限,只能把python安装到个人文件夹下,使用源码包方式安装,这里记录一下. 1.python下载 cd到目录/users/w,在此目录下安装python.通过wget命令下载python源码包: $ wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz 2.解压python到当前目录 $ tar zxvf Python-2.7.9.tar.xz 3.编译与安装 a)./configure -

Linux下python安装升级详细步骤 | Python2 升级 Python3 转载

Linux下python升级步骤  Python2 ->Python3 多数情况下,系统自动的Python版本是2.x 或者yum直接安装的也是2.x 但是,现在多数情况下建议使用3.x 那么如何升级呢? 下面老徐详细讲解升级步骤: 首先下载源tar包 可利用linux自带下载工具wget下载,如下所示: wget http://www.python.org/ftp/python/3.3.0/Python-3.3.0.tgz 下载完成后到下载目录下,解压 tar -xzvf Python-3.3