Pyenv

chocolatey

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
  1. pip install -r .\requirements\base.txt
  2. pip install -r .\requirements\base.txt -r .\requirements\gpu.txt