Python--set up and use UV in linux (Raspberry Pi)
12/7/2025 10:26:33 I am running "Trixie" version of Raspberry Pi install lite
========
#hint: to make my SSH terminal not look crap, make sure to use UTF-8 encoding (I use secureCRT9.6 and properties > appearace > encoding default is "automatic" which isn't working)
#install uv
apt update
apt install curl #needed for next command
#install uv using less HD space vs using pip
#alternate/better way (from chatGPT--assumes curl is installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
=====
#SET PATH needed for terminal app to find uv when you try to run it
#put into path--for rpi I could skip this step and just restart bash; not sure w othr distros
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
#for some distros .local above is replaced by .cargo
#restart bash
bash
#is uv working?
uv
#CREATE NEW PROJECT
#cd to ~ you should do the next command from your home dir.
uv init ide-test-uv #replace ide-test-uv with name of your project
#cd to the project folder you just created.
uv run main.py #creates venv and show you successful hello world.cd p
#ACTIVATE NEW PROJECT
#cd to project dir.
#must use source here or term will open
#new term, make change, and pop you back to old one!
source .venv/bin/activate
#INSTALL PYTHON PACKAGES
#in project root folder....
uv add [whatever] # use this instead of pip, faster!
#WHERE DO YOUR FILES .py files GO?
#see what is where in uv
uv tree
#in project root. See below. never edit anything inside the .venv dir and its subdirs.
/home/pi/my_weather_bot/ <-- YOUR PROJECT ROOT (You work here)
├── main.py <-- Your code goes here
├── utils.py <-- Your code goes here
├── data/ <-- Your data folders go here
│ └── weather_log.csv
└── .venv/ <-- THE VIRTUAL ENV (Do not open/edit)
├── bin/
├── lib/
└── pyvenv.cfg
#SAMPLE FLASK PYTHON DOOKIE
#SUPER SIMPLE FLASK EXAMPLE
#good link for flask getting started: https://dev.to/yosi/building-a-python-web-app-with-flask-and-#nginx-5ah3
#to do: modify toml file and main py file for easier startup.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, World!'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
#START PYTHON APP using UV
uv run python3 app.py #if you just use python3 app.py the path gets wacked and it won't work
###what term will show (flask is ready to take GETS and PUTS)
* Serving Flask app 'app'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:5000
* Running on http://192.168.5.200:5000
Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 430-777-572
#if I open browser or curl using PC on
#the same wifi subnet as RPi Zero using port 5000
#I see hello world.
http://192.168.5.200:5000/
Comments
Post a Comment