|
3 | 3 | This project is a template UV project
|
4 | 4 |
|
5 | 5 | - create project by UV, because UV is so fast
|
| 6 | + |
| 7 | +``` |
| 8 | +As a python Beginer, use UV to management Python Dev evnironment, key points for basic usage: |
| 9 | +
|
| 10 | +- How to use uv to create a virtual environment with different python version |
| 11 | +
|
| 12 | +- How to use uv to add/remove python packages |
| 13 | +
|
| 14 | +- How to use uv to Build/Run python project |
| 15 | +
|
| 16 | +- How to use uv to manage different scripts like package.json in Node.js |
| 17 | +
|
| 18 | +Please replay as simple as possible in markdown format, and use code block to show the commands, please make sure as simple as possible, and one question then another. |
| 19 | +
|
| 20 | +Don't explain too much, just focus on how to use uv to manage a python project without any advanced knowledge or skill. |
| 21 | +``` |
| 22 | + |
| 23 | +# UV for Python Beginners |
| 24 | + |
| 25 | +## Creating a Virtual Environment |
| 26 | + |
| 27 | +Create a virtual environment with the default Python version: |
| 28 | + |
| 29 | +```bash |
| 30 | +uv venv .venv |
| 31 | +``` |
| 32 | + |
| 33 | +Create with a specific Python version: |
| 34 | + |
| 35 | +```bash |
| 36 | +uv venv .venv --python=3.10 |
| 37 | +``` |
| 38 | + |
| 39 | +Activate the environment: |
| 40 | + |
| 41 | +```bash |
| 42 | +source .venv/bin/activate |
| 43 | +``` |
| 44 | + |
| 45 | +## Managing Python Packages |
| 46 | + |
| 47 | +Add packages: |
| 48 | + |
| 49 | +```bash |
| 50 | +uv pip install requests |
| 51 | +``` |
| 52 | + |
| 53 | +Add multiple packages: |
| 54 | + |
| 55 | +```bash |
| 56 | +uv pip install requests pandas matplotlib |
| 57 | +``` |
| 58 | + |
| 59 | +Add with specific version: |
| 60 | + |
| 61 | +```bash |
| 62 | +uv pip install requests==2.31.0 |
| 63 | +``` |
| 64 | + |
| 65 | +Remove packages: |
| 66 | + |
| 67 | +```bash |
| 68 | +uv pip uninstall requests |
| 69 | +``` |
| 70 | + |
| 71 | +List installed packages: |
| 72 | + |
| 73 | +```bash |
| 74 | +uv pip list |
| 75 | +``` |
| 76 | + |
| 77 | +## Building/Running Python Projects |
| 78 | + |
| 79 | +Run a Python script: |
| 80 | + |
| 81 | +```bash |
| 82 | +uv python script.py |
| 83 | +``` |
| 84 | + |
| 85 | +Install project dependencies from requirements.txt: |
| 86 | + |
| 87 | +```bash |
| 88 | +uv pip install -r requirements.txt |
| 89 | +``` |
| 90 | + |
| 91 | +## Managing Scripts (like package.json) |
| 92 | + |
| 93 | +Create a pyproject.toml file: |
| 94 | + |
| 95 | +```toml |
| 96 | +[tool.uv.scripts] |
| 97 | +start = "python app.py" |
| 98 | +test = "pytest" |
| 99 | +lint = "flake8" |
| 100 | +``` |
| 101 | + |
| 102 | +Run scripts: |
| 103 | + |
| 104 | +```bash |
| 105 | +uv run start |
| 106 | +``` |
| 107 | + |
| 108 | +```bash |
| 109 | +uv run test |
| 110 | +``` |
| 111 | + |
| 112 | +```bash |
| 113 | +uv run lint |
| 114 | +``` |
0 commit comments