ubuntu python 源码安装

操作系统环境:
##查看系统版本
$ 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)

sudo 不输入密码设置

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 项目开发实战第二版》

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值