---
# System prepended metadata

title: Python_環境安裝
tags: [環境安裝]

---

<style>
.center{
    display: flex;
    justify-content: center;
}
.txt_color{
    color: #224499;
}
.split_line{
    border-bottom-style: solid;
    border-width: 1px;
    border-color: #999999;

}
.txt_center{
    text-align: center;
}
.bg_hover:hover{
    background-image:url('https://i.imgur.com/C2AvT7s.png');
    background-size: auto;
    background-repeat:no-repeat;
    background-position: center;

}
.large_txt{
    font-size: x-large
}

</style>

# Python_環境安裝

### Python 3.8 安裝

<div class='txt_color split_line'>Ubuntu</div>
<br>

:::spoiler

<div>Terminal 輸入以下內容, 安裝 Python</div>

```script
sudo apt-get install python3.8
```

<div>Terminal 輸入以下內容, 查看 Python 路徑</div>

```script
python3.8

# 進到 python 環境後
import sys
sys.executable
```


<div class="center">Python 環境示意圖</div> 
<div class="center">
    <img src="https://i.imgur.com/C2AvT7s.png"> 
</div>
<br>

### Terminal 輸入以下內容, 調整 Python 執行優先序

```script
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 0
```


:::success
<div class="center">當 Terminal 輸入 python 即進入 Python3.8 環境, 表示設定完成</div>
:::


<div class="center">
    <a href='https://docs.aws.amazon.com/zh_tw/elasticbeanstalk/latest/dg/eb-cli3-install-linux.html'>
    Linux 其他版本安裝補充
    </a>
</div>



<div class='txt_color split_line'>Windows 10</div>
<br>

:::spoiler


<a href="https://i.imgur.com/WrdmlSL.png">下載 Python 3.8</a>
<div class="center">
    <img src="https://i.imgur.com/R89gk9s.png"> 
</div>
<br>

<div class='txt_center'>安裝檔案設定</div>
<div class="center">
    <img src="https://i.imgur.com/wabZu5o.png"> 
</div>
<br>

:::success
<div class="center">當 Terminal 輸入 python 即進入 Python3.8 環境, 表示設定完成</div>
:::



### <a href="https://www.jetbrains.com/pycharm/download/#section=windows">Pycharm 安裝</a>
![](https://i.imgur.com/JRUU8jP.png)

<div class='txt_color split_line'>Ubuntu</div>
<br>

:::spoiler

1. 下載 Pycharm 檔案並將其解壓縮
https://www.jetbrains.com/pycharm/download/download-thanks.html?platform=linux&code=PCC
3. 建立開啟圖示
    ```script
    sudo gedit /usr/share/applications/Pycharm.desktop
    ```
3. 輸入以下內容並存檔
    ```script
    [Desktop Entry]
    Type=Application
    Name=Pycharm
    GenericName=Pycharm3
    Comment=Pycharm3:The Python IDE
    Exec=${放置的路徑}/bin/pycharm.sh
    Icon=${放置的路徑}/bin/pycharm.png
    Terminal=pycharm
    Categories=Pycharm
    ```
:::
<br>
<div class='txt_color split_line'>Windows 10</div>
<br>

:::spoiler

<div>安裝 Pycharm</div>
<div class='txt_center'>除了下圖中的選項需勾選, 其餘皆可直接下一步</div>
<div class="center">
    <img src="https://i.imgur.com/DnFz1re.png"> 
</div>
<br>

:::

### Pycharm 建立專案


:::spoiler
<div class='txt_center'>圖中紅色框部分可以設定程式碼執行使用的環境</div>
<div class="center">
    <img src="https://i.imgur.com/qEbL2L4.png
"> 
</div>
<br>

<div class='txt_center'>等待 Pycharm 建立虛擬環境</div>
<div class="center">
    <img src="https://i.imgur.com/Wr5zXC1.png"> 
</div>

:::

### Pycharm 通用設定
<div class="txt_center">Ctrl + 滑鼠滾輪調整字體大小</div>
<div class="center">
    <img src="https://i.imgur.com/cGAtLe9.png"> 
</div>
<br>


<div class="txt_center">調整 Pycharm 運行使用記憶體, 改完記得存檔</div> 
<div class="center">
    <img src="https://i.imgur.com/WhlafBv.png"> 
</div>

<br>
<div class="txt_center">如果 Pycharm 不能打中文</div> 

開啟 Edit Custom VM Options
加入以下內容並存檔:
```
-Drecreate.x11.input.method=true
```

<br>
<div class="txt_center">如果 Pycharm Debugger 會卡住</div>

https://stackoverflow.com/questions/39371676/debugger-times-out-at-collecting-data

[調整 Pycharm 界面大小](https://blog.csdn.net/qq_15698613/article/details/86520410)

### Python [Miniconda](https://docs.conda.io/en/latest/miniconda.html) 虛擬環境安裝


<div class='txt_color split_line'>Ubuntu</div>
<br>

1. 下載 Miniconda
    ```script
    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
    -O ~/Desktop/Miniconda3.sh
    ```
2. 查看 Miniconda 安裝說明
    ```script
    sh Miniconda3.sh -h
    ```
    <div class="center">
        <img src="https://i.imgur.com/ckixs9f.png"> 
    </div>

3. 安裝 Miniconda 
    ```script
    sh Miniconda3.sh -b -u -p ~/miniconda
    ```
4. 將 Miniconda 加到環境變數中
    ```script
    vim ~/.bashrc 
    
    # 在內容的最後一行加上 miniconda安裝路徑 [i]進入輸入模式
    export PATH=$PATH:/home/{username}/miniconda/bin 
    # 存檔並關閉 [:wq] 
    ```
5. 更新環境變數
    ```script
    source ~/.bashrc       
    ```
    
    <div class="txt_center large_txt">
        <a href='https://zhuanlan.zhihu.com/p/126538251'>
        apt-get /var/lib/dpkg/lock-frontend 異常狀況排除
        </a>
    </div>

<div class='txt_color split_line'>Windows 10</div>
<br>

[安裝步驟](https://www.1989wolfe.com/2019/07/miniCONDAwithPython.html)

###### tags: `環境安裝`
