操作系统环境:
##查看系统版本
$ cat /etc/issue
Ubuntu 18.04.5 LTS \n \l
##查看系统版本
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic
## 查看内核版本
$ cat /proc/version
Linux version 5.4.0-42-generic (buildd@lgw01-amd64-023) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) ##46~18.04.1-Ubuntu SMP Fri Jul 10 07:21:24 UTC 2020
## 查看内核版本
$ uname -a
Linux ubuntu 5.4.0-42-generic ##46~18.04.1-Ubuntu SMP Fri Jul 10 07:21:24 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
安装一些软件包,脚本实现
##!/usr/bin/python3
import os
## store packages name
packages = [
'build-essential',
'libsqlite3-dev',
'libreadline6-dev',
'libgdbm-dev',
'libbz2-dev',
'sqlite3',
'tk-dev',
'libreadline-dev',
'zlib1g-dev',
'libssl-dev',
'llvm',
'libncursesw5-dev',
'xz-utils',
'libxml2-dev',
'libxmlsec1-dev',
'libffi-dev',
'liblzma-dev',
'curl'
]
for i in packages:
os.system("sudo apt-get -y install "+i)
Virtualenv 安装和使用
## 安装Virtualenv
$ pip3 install virtualenv
## 查看Virtualenv 安装版本
$ virtualenv --version
virtualenv 20.4.6 from /usr/local/lib/python3.6/dist-packages/virtualenv/__init__.py
## 搭建 Virtualenv 环境
$ mkdir ~/work
$ cd ~/work
$ virtualenv venv
## 启动 virtualenv 环境
$ source venv/bin/activate
(venv) username@ubuntu:~/work$
## 退出 virtualenv 环境
(venv) username@ubuntu:~/work$ deactivate
安装 Python的其他版本
# 下载源码包
wget -P 要存放的路径 https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
# 解压缩
tar -zxvf Python-3.7.2.tgz
# 设置安装路径
./configure --prefix=/opt/python3.7.2
# 编译
make
# 测试
make test # test 可能有失败,请自行百度
# 安装
make install
Installing From Source
On a side note if your looking to develop Python apps for systems other than the one your using, installing from source is the only way to go.
There are many good reasons to compile from tar.gz.
most Linux distros use Python internally so are linked to a version.
you can get conflicts between modules that you import.
you can test your code against different versions of python.
参考文档:
Ubuntu如何查看系统版本
Getting errors / failing tests when installing Python3.4.3 on Lubuntu 14.04
《python 项目开发实战第二版》