Skip to content

118 [sw][python][uv][venv] setup venvs for python using uv

windows

Install scoop

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression

Install uv

scoop install uv

In case that you don't want to use scoop:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Or
winget install --id=astral-sh.uv -e

Auto-completion

Add-Content -Path $PROFILE -Value '(& uv generate-shell-completion powershell) | Out-String | Invoke-Expression'
Add-Content -Path $PROFILE -Value '(& uvx --generate-shell-completion powershell) | Out-String | Invoke-Expression'
. $PROFILE

Mirror Config files

New-Item -Path "$env:APPDATA\uv" -ItemType Directory -Force; Set-Content -Path "$env:APPDATA\uv\uv.toml" -Value @"
index-url = "https://mirrors.bfsu.edu.cn/pypi/web/simple"
"@

Make dir

mkdir $env:USERPROFILE\.virtualenvs
cd $env:USERPROFILE\.virtualenvs

Create venv

uv venv --seed -p 3.12 -n instr --preview

Activate

. $env:USERPROFILE\.virtualenvs\instr\Scripts\activate.ps1


Comments

konosubakonoakua · 2024-10-23T08:24:03Z

linux

Install uv

curl -LsSf https://astral.sh/uv/install.sh | sh
SHELL autocompletion
echo 'eval "$(uv --generate-shell-completion bash)"' >> ~/.bashrc
echo 'eval "$(uvx --generate-shell-completion bash)"' >> ~/.bashrc
source ~/.bashrc
Mirror Config files
cat > ~/.config/uv/uv.toml << 'EOF'
index-url = "https://mirrors.bfsu.edu.cn/pypi/web/simple"
EOF
Make dir
mkdir ~/.virtualenvs
cd .virtualenvs
Create venv
uv venv --seed -p 3.12 -n instr --preview
Activate
source ~/.virtualenvs/instr/bin/activate