How to use UV (windows)-- CL notes from Salesforce ticket 8869
UV replaces things like pip and pyenv, it is one tool to do most everything for interpreter management, virtual env, and adding packages--all the basic Python "use venvs and leave your system python alone" necessities.
This ticket goes over installing UV on Windows, working within virtual environments, and using VSCODE as IDE
Your steps will vary if:
--You are not using Windows as OS
--You are not using VSCODE as IDE
--You are not using VENVs
=============
DO THIS FROM ELEVATED CMD PROMPT IN WINDOWS!
3/14/2025 08:41:34 Good link for UV https://www.youtube.com/watch?v=Zn5tmx0ynw8
good vid: https://www.youtube.com/watch?v=AMdG7IjgSPM
**is UV already installed?**
from cmd or terminal run
uv
if it throws up a "here are UV commands you can use" you are good to go. If not, keep reading about how to install.
**INSTALL UV AND ADD TO WINDOWS SYSTEM PATH***
#install uv from "system" python using PIP (not sure if this is the best way to do it but it works)
python -m pip install uv
#add to user path in windows
#first: figure out where system python for a given windows computer is installed.
python -m site --user-base # where is my python installed
#Using a text editor, add \Scripts to the end of the folder that the command prints to STDOUT (e.g.
C:\Users\cl\AppData\Roaming\Python\Python311\Scripts)
#add this string to user path in windows
Windows + R enter sysdm.cpl ("system demon control panel")
advanced > user > path > add the string above.
#Restart windows machine to pick up PATH changes.
#open new cmd prompt and try this, it should now work.
uv --version
#note for python 10 the path to UV lived here.
C:\Users\cl\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts
So this may be different depending on v. of python, how your Windows C drive is laid out, etc.
#aside--if you are using WSL....you can | wsl and use linux commands like greo
PS D:\Dropbox\python> dir | wsl grep ide-test
la--- 3/14/2025 6:58 AM ide-test-pyenv
la--- 3/14/2025 8:32 AM ide-test-uv
#now you can initialize new projects using UV--this will be created as subfolders under current directory
START HERE FOR NEW PROJ CREATION
uv init ide-test-uv--so no need to mkdir new project folders, UV will do this for you.
#set up venv environment.
cd ide-test-uv # cd to uv created proj directory....
#Note--DO THIS STEP before going further or other UV commands may not work/throw an error.
uv run main.py #different than video--where he runs hello.py, older version?
#activate your new .venv --do this each time you restart the system and go back to the project.
.venv\Scripts\activate
#if your venv is working your prompt will change, something like:
(hunyuan3D-2) C:\Users\cl\hunyuan3D-2>
#let's use uv to add pandas; still in proj directory
uv add pandas #note! **not** uv install pandas or uv pip install pandas Use the syntax uv add [blah]
**note, if you are using VSCODE your venv libraries will not seem visible at first even if they are visible in uv tree. See instructions for fixing this in the "VSCODE" at the bottom of this ticket.**
**note if you are using VSCODE and add a library using AV using the steps below, you may have to close and open VSCODE for VSCODE to see the newly added library**
#that seems to have worked, all dependencies etc. are now here:
D:\Dropbox\python\ide-test-uv\.venv\Lib\site-packages
#put yer .py code in the root directory, not in venv, .venv or whatever
D:\Dropbox\python\ide-test-uv\someStupidFile.py
#upgrade a package to current
uv lock --upgrade package pandas
#see your dependencies
uv tree
#I get this--cool.
(venv) PS D:\Dropbox\python\ide-test-uv> uv tree
Resolved 7 packages in 0.68ms
ide-test-uv v0.1.0
└── pandas v2.2.3
├── numpy v2.2.3
├── python-dateutil v2.9.0.post0
│ └── six v1.17.0
├── pytz v2025.1
└── tzdata v2025.1
(venv) PS D:\Dropbox\python\ide-test-uv>
#use uv to install a python in your system (note, you are installing it, but not yet telling UV to use it)
activate your venv if not yet active--see above for how to do that.
(this is not installing "system" python, rather, a version of python in the UV venv.
uv venv --python 3.11.6
#see your system python versions
uv python list
#see what version you are using in your venv
uv python pin
#use a version of python in your current .venv
uv python pin 3.12
#clobber the python.exe in your .venv with this new pinned version
uv sync
5/8/2025 10:30:25
VSCODE INFO! VSCODE INFO! VSCODE INFO! VSCODE INFO! VSCODE INFO! VSCODE INFO!
How the fuck can you make VSCODE work with UV? at first it seemed to me that anything I did in UV was ignored by VSCODE!
*****make VSCODE Python IDE work with UV venv ***
**at onset VSCODE will use Windows, Linux or WSL system python interpreter, not the python in a virtual environment created with UV. That's why VSCODE <> UV <> VENVS don't seem to work together.....we need to fix this**
1. Point VS Code’s Python extension at that interpreter
--Open VSCODE
--Open Command Palette (view > command pallete) → “Python: Select Interpreter.”
Choose “Enter interpreter path.”
Browse to location of python interpreter--you will see a choice in the drop down with a folder icon, click on that.
OK, which one to choose (you might have several versions of Python on a single system)
Here is an example.
in windows, i created a UV venv for Godaddy DNS dumps. The python.exe interpretor I used to make the venv work is not system python, rather the python.exe to use is here:
C:\Users\cl\Dropbox\python\godaddy-dns-ote\.venv\Scripts
**same idea but using settings.json for a VSCODE python project**
if you want this to work for any project, add a settings.json to the given project you have used UV to craft the venv.
This will force certain settings onto VSCODE when you open a script.
CD to project directory.
create this directory:
.vscode
cd to it.
create this file.
settings.json
put this into the file and save
{
// Always use the uv venv
"python.defaultInterpreterPath": "${workspaceFolder}\.venv\scripts\python",
// Auto-activate the venv when you open a terminal
"python.terminal.activateEnvironment": true
}
-------------------
Comments
Post a Comment