linux中python安装
1、查看当前环境中是否存在python安装包
[zyj@localhost ~]$ rpm -qa | grep python
gnome-python2-gnome-2.28.-.el6.x86_64
python-slip-0.2.-.el6_2.noarch
python-iniparse-0.3.-2.1.el6.noarch
python-pycurl-7.19.-.el6.x86_64
gnome-python2-gconf-2.28.-.el6.x86_64
gnome-python2-extras-2.25.-.el6.x86_64
gnome-python2-libegg-2.25.-.el6.x86_64
notify-python-0.1.-.el6.x86_64
python-libs-2.6.-.el6_8.x86_64
python-ethtool-0.6-.el6.x86_64
python-mako-0.3.-.el6.noarch
abrt-python-2.0.-.el6.centos.x86_64
gnome-python2-gnomekeyring-2.28.-.el6.x86_64
gnome-python2-bonobo-2.28.-.el6.x86_64
python-meh-0.12.-.el6.noarch
python-2.6.-.el6_8.x86_64
libuser-python-0.56.-.el6_7.x86_64
2、在官网上查看最新的版本;也可以通过yum install 安装python安装包,但是有可能yum源上面没有最新的python版本,所以采用下载的方式安装最新的安装包。
https://www.python.org/downloads/source/
[root@localhost 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.
Release : .el6_8
Size : k
Repo : installed
From repo : anaconda-CentOS-.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.
[root@localhost home]#
[root@localhost 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的家目录下
[root@localhost home]# cd zyj
[root@localhost zyj]# ll
total
drwxr-xr-x. zyj zyj Apr : Desktop
drwxr-xr-x. zyj zyj Apr : Documents
drwxr-xr-x. zyj zyj Apr : Downloads
drwxr-xr-x. zyj zyj Apr : Music
drwxr-xr-x. zyj zyj Apr : Pictures
drwxr-xr-x. zyj zyj Apr : Public
-rw-rw-r--. zyj zyj May Python-3.6..tgz
drwxr-xr-x. zyj zyj Apr : Templates
drwxr-xr-x. zyj zyj Apr : Videos
-rw-rw-r--. zyj zyj Apr : mysql-server-5.1.-.el6_8.x86_64.rpm
[root@localhost zyj]# mv Python-3.6..tgz ../
[root@localhost home]# ll
total
-rwxrwxrwx. root root Apr : .txt
-rw-rw-r--. zyj zyj May Python-3.6..tgz
-rwxrwxrwx. zyj zyj Apr : hello.txt
drwxr-xrwx. root root Apr : x
drwx------. zyj zyj May : zyj
- 查看源码(.c结尾为c语言):在windows下打开压缩包,查看里面文件的后缀。
- 准备编译环境(检查c语言编译环境,gcc)
[root@localhost home]# rpm -qa | grep gcc
libgcc-4.4.-.el6.x86_64
gcc-4.4.-.el6.x86_64
[root@localhost home]# yum install gcc-c++ //安装c++编译环境
- 检查(依赖、兼容),预编译:
[root@localhost home]# tar -zxvf Python-3.6..tgz //解压安装包
[root@localhost home]# ls
.txt Python-3.6. Python-3.6..tgz hello.txt x zyj
[root@localhost home]# cd Python-3.6. //进入安装包目录下
[root@localhost Python-3.6.]# ll
total
drwxr-xr-x. sl sl Mar : Doc
drwxr-xr-x. sl sl Mar : Grammar
drwxr-xr-x. sl sl Mar : Include
-rw-r--r--. sl sl Mar : LICENSE
drwxr-xr-x. sl sl Mar : Lib
drwxr-xr-x. sl sl Mar : Mac
-rw-r--r--. sl sl Mar : Makefile.pre.in
drwxr-xr-x. sl sl Mar : Misc
drwxr-xr-x. sl sl Mar : Modules
drwxr-xr-x. sl sl Mar : Objects
drwxr-xr-x. sl sl Mar : PC
drwxr-xr-x. sl sl Mar : PCbuild
drwxr-xr-x. sl sl Mar : Parser
drwxr-xr-x. sl sl Mar : Programs
drwxr-xr-x. sl sl Mar : Python
-rw-r--r--. sl sl Mar : README.rst
drwxr-xr-x. sl sl Mar : Tools
-rw-r--r--. sl sl Mar : aclocal.m4
-rwxr-xr-x. sl sl Mar : config.guess
-rwxr-xr-x. sl sl Mar : config.sub
-rwxr-xr-x. sl sl Mar : configure
-rw-r--r--. sl sl Mar : configure.ac
-rwxr-xr-x. sl sl Mar : install-sh
-rw-r--r--. sl sl Mar : pyconfig.h.in
-rw-r--r--. sl sl Mar : setup.py 执行可执行文件:
[root@localhost 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/>. [root@localhost 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需要依赖这两个包。
[root@localhost home]# yum install zlib* openssl* //安装依赖包
[root@localhost home]# cd Python-3.6.
[root@localhost Python-3.6.]# 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
[root@localhost Python-3.6.]# ./configure --prefix=/usr/python-3.6.5 --enable-optimizations //完整的预编译
...
creating Modules/Setup
creating Modules/Setup.local
creating Makefile //没有任何报错
[root@localhost Python-3.6.]#
- 编译:make
[root@localhost Python-3.6.]# make
...
make[]: Entering directory `/home/Python-3.6.'
find . -name '*.gc??' -exec rm -f {} ';'
find . -name '*.profclang?' -exec rm -f {} ';'
find . -name '*.dyn' -exec rm -f {} ';'
rm -f /home/Python-3.6./coverage.info
rm -rf /home/Python-3.6./lcov-report
make[]: Leaving directory `/home/Python-3.6.'
[root@localhost Python-3.6.]# //一般检查最后几行有没有error
- 安装:make install
[root@localhost Python-3.6.]#make install //安装
......
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-9.0. setuptools-39.0.
[root@localhost Python-3.6.]# [root@localhost Python-3.6.]# cd /usr/python-3.6./
[root@localhost python-3.6.]# ls
bin include lib share
[root@localhost python-3.6.]# pwd //python安装后的目录
/usr/python-3.6. [root@localhost python-3.6.]# cd /home/Python-3.6.
[root@localhost Python-3.6.]# pwd //python源码目录,可以删除掉
/home/Python-3.6. [root@localhost Python-3.6.]# cd /usr/python-3.6.5/
[root@localhost python-3.6.]# ls
bin include lib share
[root@localhost python-3.6.]# ll
total
drwxr-xr-x. root root May : bin
drwxr-xr-x. root root May : include
drwxr-xr-x. root root May : lib
drwxr-xr-x. root root May : share
[root@localhost python-3.6.]# cd bin
[root@localhost bin]# ll
total
lrwxrwxrwx. root root May : 2to3 -> 2to3-3.6
-rwxr-xr-x. root root May : 2to3-3.6
-rwxr-xr-x. root root May : easy_install-3.6
lrwxrwxrwx. root root May : idle3 -> idle3.
-rwxr-xr-x. root root May : idle3.
-rwxr-xr-x. root root May : pip3
-rwxr-xr-x. root root May : pip3.
lrwxrwxrwx. root root May : pydoc3 -> pydoc3.
-rwxr-xr-x. root root May : pydoc3.
lrwxrwxrwx. root root May : python3 -> python3.6
lrwxrwxrwx. root root May : python3-config -> python3.-config
-rwxr-xr-x. root root May : python3.
lrwxrwxrwx. root root May : python3.-config -> python3.6m-config
-rwxr-xr-x. root root May : python3.6m
-rwxr-xr-x. root root May : python3.6m-config
lrwxrwxrwx. root root May : pyvenv -> pyvenv-3.6
-rwxr-xr-x. root root May : pyvenv-3.6 [root@localhost bin]# python
Python 2.6.6 (r266:, Aug , ::)
[GCC 4.4. (Red Hat 4.4.-)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()
[root@localhost bin]#
[root@localhost bin]# python3 //需要设置环境变量,如果命令找不到,则此命令的执行文件不在系统的环境变量(PATH)中。
bash: python3: command not found
- 配置环境变量:让系统自动找到命令执行文件路径。PATH的值是一堆目录,之间通过冒号隔开。
[root@localhost bin]# printenv //查看环境变量或使用echo $PATH查看
HOSTNAME=localhost.localdomain
SELINUX_ROLE_REQUESTED=
SHELL=/bin/bash
TERM=xterm
HISTSIZE=
SSH_CLIENT=192.168.166.1
SELINUX_USE_CURRENT_RANGE=
SSH_TTY=/dev/pts/
USER=zyj
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/zyj/bin 目录之间的分隔使用冒号隔开。
MAIL=/var/spool/mail/zyj
PWD=/usr/python-3.6./bin
LANG=en_US:.UTF-
SELINUX_LEVEL_REQUESTED=
HISTCONTROL=ignoredups
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
HOME=/root
SHLVL=
LOGNAME=zyj
SSH_CONNECTION=192.168.166.1 192.168.166.128
LESSOPEN=||/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=
OLDPWD=/usr/python-3.6.
_=/usr/bin/printenv
[root@localhost bin]#
设置环境变量:
[root@localhost bin]# vi ~/.bash_profile
[root@localhost bin]# vi ~/.bashrc
# .bashrc # User specific aliases and functions alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i' # Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
PATH=$PATH:/usr/python-3.6.5/bin //在原有PATH下追加新的路径。
#第二种修改环境变量的方式
PYTHON_HOME=/usr/python-3.6.5
PATH=$PATH:$PYTHON_HOME/bin
:wq
[root@localhost bin]# source ~/.bashrc //执行生效,只要PATH修改,均需要source生效。
[root@localhost ~]# echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/zyj/bin:/usr/python-3.6.5/bin [root@localhost bin]# python3
Python 3.6. (default, May , ::)
[GCC 4.4. (Red Hat 4.4.-)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
注意:一般遵守改变自己用户的配置文件,不要改整个系统的配置文件。
/etc/profile :整个系统的环境变量配置文件
~/.bashrc:当前用户的环境变量配置文件,推荐使用。
补充:安装一个python工具,ipython3,这个工具可以在python中执行linux的命令,比较好用,推荐安装。
[root@localhost bin]# pip3 install ipython3
Collecting ipython
[root@localhost bin]# ipython3
/usr/python-3.6./lib/python3./site-packages/IPython/core/history.py:: UserWarning: IPython History requires SQLite, your history will not be saved
warn("IPython History requires SQLite, your history will not be saved")
Python 3.6. (default, May , ::)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.3. -- An enhanced Interactive Python. Type '?' for help. In []: ls
2to3@ idle3@ iptest3* pip3* pydoc3.* python3-config@ python3.6m* pyvenv-3.6*
2to3-3.6* idle3.* ipython* pip3.* pygmentize* python3.* python3.6m-config*
easy_install-3.6* iptest* ipython3* pydoc3@ python3@ python3.-config@ pyvenv@
In []: cd /home
linux中python安装的更多相关文章
- linux中编译安装Apache、PHP、MySQL(上)
1.简介 在阿里云买了个云服务器,一直没时间折腾.过了近十天了吧,才有时间好好玩玩这个云服务器.自己是做Web开发的,所以我需要的开发环境是LAMP.之前打算是采用yum安装,不过yum安装apach ...
- Linux中redis安装配置及使用详解
Linux中redis安装配置及使用详解 一. Redis基本知识 1.Redis 的数据类型 字符串 , 列表 (lists) , 集合 (sets) , 有序集合 (sorts sets) , 哈 ...
- Linux中Nginx安装与配置详解
转载自:http://www.linuxidc.com/Linux/2016-08/134110.htm Linux中Nginx安装与配置详解(CentOS-6.5:nginx-1.5.0). 1 N ...
- Linux中如何安装Apache服务器
Linux中如何安装Apache服务器 由于学习的需要,所有手动安装了一下Apache源码包,安装过程中的问题千奇百怪,但是如果弄清楚了问题出在哪里,那么也不是太难.如果有学习者出现安装中的问题,可仔 ...
- Linux课程---11、Linux中软件安装和调试
Linux课程---11.Linux中软件安装和调试 一.总结 一句话总结: 启动过程:1.安装软件,2.修改配置文件,3.启动服务 查看过程:4.查看进程,5.查看端口 关闭过程:6.关闭软件,7. ...
- linux中Nginx安装
linux中Nginx安装 编译安装 Nginx的优点太多,这里不再赘述,详情请看这篇博客深入理解nginx. Nginx的安装有rpm包安装.编译安装和docker安装.本文将介绍编译安装方 ...
- linux中RabbitMQ安装教程
linux中RabbitMQ安装教程 在做一个微服务项目时候用到消息队列,于是深入了解了消息队列知识,并在linux上安装了Rabbitmq,本博客介绍Rabbitmq的安装教程,想要深入了解消息队列 ...
- linux中rpm安装
目录 一:linux中rpm安装 1.rpm简介 2.区别 3.RPM命令五种基本模式 二:RPM安装全面解析 1,下载软件包 2, 安装软件包 3, 尝试卸载 4, 更新(升级) 5,软件包名称: ...
- linux中Python源码安装和配置
安装 首先获取安装包,此处版本为3.7 wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz 解压 tar xvf Python- ...
随机推荐
- VIM命令图---可定制版
近期闲来无事,便自己用PS制作了一份VIM命令助记图,之前看到网上有类似的图片,可是有些解释感觉不太好,并有一些错误的地方,所以就自己做了一份,并且保留了PS源文件,为了方便会PS的网友可以对本图进行 ...
- 反射实现增删改查(DAO层)——删除数据
先贴出代码,后续补充自己的思路.配置文件.使用方式: /** * * 删除数据 */ @Override public void deleteObject(List<Map<String, ...
- MySQL主从配置实战笔记
其实网上已经有关于MySQL主从复制的很丰富全面的资料了,这里写点东西主要是为了给自己加深印象. 复制原理 MySQL主从复制是内建的非常强大的功能,主要应用于数据备份,负载均衡等方面.因为配置相对比 ...
- 括号序列(区间dp)
括号序列(区间dp) 输入一个长度不超过100的,由"(",")","[",")"组成的序列,请添加尽量少的括号,得到一 ...
- 洛谷P1979 华容道(70分 暴力)
P1979 华容道 题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果能完成, 最少 ...
- CF70D Professor's task(动态凸包)
题面 两种操作: 1 往点集S中添加一个点(x,y); 2 询问(x,y)是否在点集S的凸包中. 数据保证至少有一个2操作, 保证刚开始会给出三个1操作, 且这三个操作中的点不共线. 题解 动态凸包板 ...
- ALSA声音编程
1. ALSA设备驱动将ALSA设备描述分为四层,从上到下为: default default:0 plughw:0,0 hw:0,0 不同的层次,对设备的控制权限不同,比如hardware para ...
- MCP|DYM|Quantitative mass spectrometry to interrogate proteomic heterogeneity in metastatic lung adenocarcinoma and validate a novel somatic mutation CDK12-G879V (利用定量质谱探究转移性肺腺瘤的蛋白质组异质性及验证新体细胞突变)
文献名:Quantitative mass spectrometry to interrogate proteomic heterogeneity in metastatic lung adenoca ...
- Pod中spec的字段常用字段及含义
一.Pod中spec的字段常用字段及含义 1.pod.spec.containers ² spec.containers.name <string> #pod的名称,必须字段,名称唯一 ...
- Java基础--常用API--java.lang.Object
一.简述 1.Object类是所有类的父类,即直接或间接的继承java.lang.Object类.省略了extends Object. 2.方法 (1)protected native Object ...