## Pyenv - Windows: https://github.com/pyenv-win/pyenv-win - Linux/Mac: https://github.com/pyenv/pyenv ## chocolatey - https://chocolatey.org/install - 使用 Powershell(以系統管理者執行) ``` Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) ``` ## pyenv-win 安裝 1. 使用 cmd 命令提示字元(以系統管理者執行) 2. `choco install pyenv-win` 3. 使用 Powershell(以系統管理者執行) 4. 依序ㄧ行ㄧ行執行以下指令: ``` [System.Environment]::SetEnvironmentVariable('PYENV',$env:USERPROFILE + "\.pyenv\pyenv-win\","User") [System.Environment]::SetEnvironmentVariable('PYENV_ROOT',$env:USERPROFILE + "\.pyenv\pyenv-win\","User") [System.Environment]::SetEnvironmentVariable('PYENV_HOME',$env:USERPROFILE + "\.pyenv\pyenv-win\","User") [System.Environment]::SetEnvironmentVariable('path', $env:USERPROFILE + "\.pyenv\pyenv-win\bin;" + $env:USERPROFILE + "\.pyenv\pyenv-win\shims;" + [System.Environment]::GetEnvironmentVariable('path', "User"),"User") ``` ## pyenv-win 使用 1. 開啟 cmd 命令提示字元 2. `pyenv versions` 3. `pyenv install --list` 列出所有可安裝的 python 版本 4. `pyenv install 3.10.5` 5. `pyenv versions` 列出本機已安裝的所有 python 版本 6. `pyenv global 3.10.5` 設定預設 python 版本 7. `cd` 到專案目錄 8. `pyenv local 3.8.10` 設定當前目錄使用 python 3.8 9. `python -V` ## windows 基本指令 - `dir` 對應 Linux `ls` ## Python 虛擬環境 1. 確認 python 版本 `python -V` 2. 建立虛擬環境 `python -m venv .venv` 3. 進入虛擬環境 `.venv\Scripts\activate` ## Python 套件管理 ### 基本用法 1. 新增`requirements.txt` 2. 新增套件寫進 requirements.txt ``` requests==2.31.0 ``` ### 進階用法 1. `mkdir requirements` 2. `cd requirements` 3. 新增檔案 base.txt ``` requests==2.31.0 ``` 4. `pip install -r .\requirements\base.txt` 5. `pip install -r .\requirements\base.txt -r .\requirements\gpu.txt`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up