@Python3环境安装(Linux OS)

阅读: 评论:0

@Python3环境安装(Linux OS)

@Python3环境安装(Linux OS)

文章目录

    • 1.Python基础概述(Linux)
    • 2.Python3依赖环境
    • 3.Python3环境安装
    • 4.Setuptools安装
    • 5.Python3环境检查测试
    • 6.Python3模块安装测试

1.Python基础概述(Linux)

目前python的最热的两大版本,python2与python3;
做数据分析,常用的是python3,用python3开发的程序部署到服务器上时,要求服务器上的python环境也是python3。
Linux服务器一般默认自带python2,建议不要做卸载

2.Python3依赖环境

gcc是一个用于linux系统下编程的编译器
linux下的python3需要使用编译安装,所以我们需要安装gcc
查看一下系统中gcc:

#常用编译安装所需要的依赖包
[root@zeny ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel#python版本确认
[root@zeny ~]# python --version
Python 2.7

3.Python3环境安装

#python3安装包下载
[root@zeny ~]# cd opt/
[root@zeny ~]# wget .7.1/Python-3.#创建安装目录
[root@zeny ~]# mkdir -p /usr/local/python3#安装包python3解压
[root@zeny ~]# cd /opt/
[root@zeny opt]# tar -zxvf Python-3.
[root@zeny opt]# ll  |grep Python
drwxr-xr-x  19  501   501     4096 Aug  6 01:43 Python-3.7.1
-rw-r--r--   1 root root  22802018 Oct 20  2018 Python-3.#编译安装Python3
[root@zeny ~]# cd /opt/Python-3.7.1
[root@zeny Python-3.7.1]# ll
total 56660
-rw-r--r--  1  501  501    10953 Oct 20  2018 aclocal.m4
drwxr-xr-x  6 root root      107 Aug  6 01:39 build
-rw-r--r--  1  501  501      631 Oct 20  2018 CODE_OF_CONDUCT.rst
-rwxr-xr-x  1  501  501    44166 Oct 20  2018 config.guess
-rw-r--r--  1 root root   908527 Aug  6 01:35 config.log
-rwxr-xr-x  1 root root    40763 Aug  6 01:35 config.status
-rwxr-xr-x  1  501  501    36251 Oct 20  2018 config.sub
-rwxr-xr-x  1  501  501   495052 Oct 20  2018 configure
-rw-r--r--  1  501  501   165352 Oct 20  2018 configure.ac
drwxr-xr-x 18  501  501     4096 Oct 20  2018 Doc
drwxr-xr-x  2  501  501       21 Oct 20  2018 Grammar
drwxr-xr-x  3  501  501     4096 Oct 20  2018 Include
-rwxr-xr-x  1  501  501     7122 Oct 20  2018 install-sh
drwxr-xr-x 34  501  501     8192 Aug  6 01:37 Lib
-rw-r--r--  1 root root 39914012 Aug  6 01:37 libpython3.7m.a
-rw-r--r--  1  501  501    12763 Oct 20  2018 LICENSE
drwxr-xr-x  2  501  501       33 Oct 20  2018 m4
drwxr-xr-x  8  501  501      160 Oct 20  2018 Mac
-rw-r--r--  1 root root    71234 Aug  6 01:35 Makefile
-rw-r--r--  1 root root    62294 Aug  6 01:35 Makefile.pre
-rw-r--r--  1  501  501    62613 Oct 20  2018 Makefile.pre.in
drwxr-xr-x  2  501  501     4096 Aug  6 01:35 Misc
drwxr-xr-x 13  501  501     8192 Aug  6 01:39 Modules
drwxr-xr-x  4  501  501     4096 Aug  6 01:37 Objects
drwxr-xr-x  3  501  501     4096 Aug  6 01:40 Parser
drwxr-xr-x  6  501  501     4096 Oct 20  2018 PC
drwxr-xr-x  2  501  501     4096 Oct 20  2018 PCbuild
-rw-r--r--  1 root root        0 Aug  6 01:35 profile-clean-stamp
-rw-r--r--  1 root root        0 Aug  6 01:39 profile-gen-stamp
drwxr-xr-x  2  501  501      179 Aug  6 01:47 Programs
-rw-r--r--  1 root root       26 Aug  6 01:
-rw-r--r--  1 root root    45191 Aug  6 01:10 pyconfig.h
-rw-r--r--  1  501  501    43134 Oct 20  2018 pyconfig.h.in
-rwxr-xr-x  1 root root 15798928 Aug  6 01:37 python
drwxr-xr-x  3  501  501     8192 Aug  6 01:37 Python
-rw-r--r--  1 root root     3097 Aug  6 01:39 python-config
-rw-r--r--  1 root root     2042 Aug  6 01:39 python-config.py
-rw-r--r--  1 root root    64614 Aug  6 01:14 python-gdb.py
-rw-r--r--  1  501  501    10097 Oct 20  2018 README.rst
-rw-r--r--  1  501  501   101855 Oct 20  2018 setup.py
drwxr-xr-x 23  501  501      322 Oct 20  2018 Tools
#「指定安装目录,设置启用ssl功能,直接添加参数:--with-ssl」
[root@zeny Python-3.7.1]# ./configure --prefix=/usr/local/python3
[root@zeny Python-3.7.1]#  make && make install#测试Pthon3是否成功
[root@zeny Python-3.7.1]# /usr/local/python3/bin/python3.7#创建软连接(-f,如创建不成功,可以添加此参数直接强制覆盖)
[root@zeny Python-3.7.1]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@zeny Python-3.7.1]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

配置PATH

#加入环境变量(PATH)
[root@zeny Python-3.7.1]# vim /etc/profile (直接添加如下内容即可)if [ -f ~/.bashrc ]; then. ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/bin:/usr/local/python3/binexport PATH#配置快速生效
[root@zeny Python-3.7.1]# source ~/.bash_profile

4.Setuptools安装

#安装setuptools
[root@zeny ~]# cd /opt/
[root@zeny opt]# wget --no-check-certificate  .--no-check-certificate :意味着以不安全的方法连接
##下载文件的md5校验码:c607dd118eae682c44ed146367a17e26#解压安装
[root@zeny opt]# tar -zxvf setuptools-19.
[root@zeny opt]# cd /opt/setuptools-19.6/#编译并安装
[root@zeny setuptools-19.6]# python3 setup.py build
[root@zeny setuptools-19.6]# python3 setup.py install#软连接创建
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

5.Python3环境检查测试

Python3环境检查

#查看Python版本
[root@zeny ~]# python3 -V
Python 3.7.1[root@zeny ~]# pip3 -V
pip 10.0.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

6.Python3模块安装测试

Python3模块: requests

#直接使用python安装库pip安装requests(出现以下错需要更新到最新的pip版本即可)
[root@zeny ~]# pip install requests
Collecting requestsDownloading .28.1-py3-none-any.whl (62kB)100% |████████████████████████████████| 71kB 966kB/s 
Collecting urllib3<1.27,>=1.21.1 (from requests)Downloading .26.11-py2.py3-none-any.whl (139kB)100% |████████████████████████████████| 143kB 1.7MB/s 
Collecting charset-normalizer<3,>=2 (from requests)Downloading .1.0-py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)Downloading .6.15-py3-none-any.whl (160kB)100% |████████████████████████████████| 163kB 6.0MB/s 
Collecting idna<4,>=2.5 (from requests)Downloading .3-py3-none-any.whl (61kB)100% |████████████████████████████████| 61kB 8.6MB/s 
Installing collected packages: urllib3, charset-normalizer, certifi, idna, requests
Successfully installed certifi-2022.6.15 charset-normalizer-2.1.0 idna-3.3 requests-2.28.1 urllib3-1.26.11
You are using pip version 10.0.1, however version 22.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.#更新pip版本
[root@zeny ~]# pip install --upgrade pip
Collecting pipDownloading .2.2-py3-none-any.whl (2.0MB)100% |████████████████████████████████| 2.0MB 724kB/s 
Installing collected packages: pipFound existing installation: pip 10.0.1Uninstalling pip-10.0.1:Successfully uninstalled pip-10.0.1
Successfully installed pip-22.2.2#继续安装requsts模块
[root@zeny ~]# pip install requests
Requirement already satisfied: requests in /usr/local/lib/python3.7/site-packages (2.28.1)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.7/site-packages (from requests) (3.3)
Requirement already satisfied: charset-normalizer<3,>=2 in /usr/local/lib/python3.7/site-packages (from requests) (2.1.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.7/site-packages (from requests) (1.26.11)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from requests) (2022.6.15)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: 

Python3模块: xlrd
注:使用python3进行执行脚本,由于xlrd新的模块(2.0.1版本)已不支持.xlsx文件,我们就需要卸载当前版本的xlrd库,安装就版本的1.2.0版本。

#卸载删除新版xlrd模块
[root@zabbix01 zeny]# pip uninstall xlrd
WARNING: Skipping xlrd as it is not installed.
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: 
[root@zabbix01 zeny]# pip install xlrd==1.2.0
Collecting xlrd==1.2.0Downloading xlrd-1.2.0-py2.py3-none-any.whl (103 kB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 103.3/103.3 kB 1.1 MB/s eta 0:00:00
Installing collected packages: xlrd
Successfully installed xlrd-1.2.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: 

本文发布于:2024-01-30 03:38:04,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170655708818959.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:环境   OS   Linux
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23