Python从零开始学习笔记

Python编程入门

本系列笔记准备从零基础开始记录python的技术细节和感想。

环境配置

操作系统:Linux系统
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.7.1908 (Core)
Release: 7.7.1908
Codename: Core

备注:root权限,所有操作都是在root用户下操作。

安装Python 3

Linux系统下有多种安装方式:Anaconda安装、命令行安装和源码安装。根据自己需要自行选择。

这里选择源码安装,安装Python 3.8版本。

  1. 安装编译python源码时,需要一些依赖包:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel
  1. 下载工具wget,用于下载python源码:
yum install wget
  1. 下载对应的python版本:
wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz
  1. 解压压缩包并安装:
# 解压压缩包
tar -zxvf Python-3.8.2.tgz  

# 进入文件夹
cd Python-3.8.2

# 配置安装位置
./configure prefix=/usr/local/python3

# 安装
make && make install

如果需要确认版本编译成功且是否安装正确,可以通过ll或ls命令查看python3目录是否生成。

[root@iZ2ze9ftqv2b85gk7iyhp1Z ~]# cd /usr/local
[root@iZ2ze9ftqv2b85gk7iyhp1Z local]# ll
total 76
drwxr-xr-x   6 root root 4096 Apr 21 21:41 aegis
drwxr-xr-x.  2 root root 4096 Dec 12 18:30 bin
drwxr-xr-x   6 root root 4096 Dec 12 18:22 curl
drwxr-xr-x.  2 root root 4096 Apr 11  2018 etc
drwxr-xr-x   6 root root 4096 Dec 12 18:22 freetype
drwxr-xr-x.  2 root root 4096 Apr 11  2018 games
drwxr-xr-x.  3 root root 4096 Dec 12 18:21 include
drwxr-xr-x.  3 root root 4096 Dec 12 18:21 lib
drwxr-xr-x.  2 root root 4096 Apr 11  2018 lib64
drwxr-xr-x.  2 root root 4096 Apr 11  2018 libexec
drwxr-xr-x   9 root root 4096 Dec 12 18:18 mysql
drwxr-xr-x  11 root root 4096 Dec 12 18:21 nginx
drwxr-xr-x   9 root root 4096 Dec 12 18:18 openssl
drwxr-xr-x   9 root root 4096 Dec 12 18:29 php
drwxr-xr-x   6 root root 4096 May  7 20:14 python3
drwxr-xr-x   5 root root 4096 Dec 12 18:30 redis
drwxr-xr-x.  2 root root 4096 Apr 11  2018 sbin
drwxr-xr-x.  9 root root 4096 Dec 12 18:21 share
drwxr-xr-x.  2 root root 4096 Apr 11  2018 src
  1. 添加软连接:
#添加python3的软链接 
ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3 

#添加 pip3 的软链接 
ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3

测试验证安装结果

当安装过程完成后,在命令行界面下测试python3和pip3是否安装成功:

[root@iZ2ze9ftqv2b85gk7iyhp1Z ~]# python3
Python 3.8.2 (default, May  7 2020, 20:13:40)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@iZ2ze9ftqv2b85gk7iyhp1Z ~]# pip3 -V
pip 19.2.3 from /usr/local/python3/lib/python3.8/site-packages/pip (python 3.8)

如果命令行界面执行以上命令出现上面的提示,证明python3和pip3已经安装成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值