---
# System prepended metadata

title: 'Python , pip 安裝'
tags: [Linux, python]

---

# Python , pip 安裝
###### tags: `Linux`、`python`

## Python 安裝 -- Linux

在 Linux 安裝 Python

### 1. 先在Linux 進行軟體更新
```
sudo apt update
sudo apt upgrade
```

### 2. 安裝python 依賴套件
```
sudo apt install build-essential zlib1g-dev libbz2-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
```

### 3. 安裝 Python

可以先看需要哪個 Python 版本
[https://www.python.org/ftp/python/](https://)

![](https://i.imgur.com/riL3KGW.png)

選擇好後下載壓縮檔，並且解壓縮
```
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
tar -zxvf Python-3.8.0.tgz
```

### 4. 編譯和安裝
```
cd Python-3.8.0
./configure --prefix=/usr/local/src/python3  # 配置安装位置
sudo make
sudo make install
```

### 5. 建立軟連結
```
sudo ln -s /usr/local/src/python3/bin/python3.8 /usr/bin/python3.8
sudo ln -s /usr/local/src/python3/bin/pip3.8 /usr/bin/pip3.8
```

### 6. 安裝 pip
```
sudo apt install python3-pip
```

### 7. 自訂指令別名
在 `.bashrc` 或 `.zshrc` 新增以下這段並儲存
```
# python
alias python=python3
alias pip=pip3
```

儲存後執行
```
source .zshrc
```

### 8. 完成
```
$ python
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
```
```
$ pip -V
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
```