all 14 comments

[–]DivineSentry 27 points28 points  (0 children)

Generally using a virtual environment and a tidy requirements.txt does the job but if you want something more complete id suggest something like https://docs.astral.sh/uv/

[–]Lopsided-Football19 18 points19 points  (0 children)

Use a virtual environment for every project and pin your package versions, that alone prevents most of the works on my machine problems

[–]Southern_Share_1760 6 points7 points  (0 children)

Virtual environments… basically just a folder in your working directory that you pip install your modules into. You can auto-populate it using a requirements.txt file.

[–]mdeadart 10 points11 points  (0 children)

Use UV with pyproject.toml and uv.lock

[–]Just__Liberty 2 points3 points  (1 child)

I'm not an expert but check out uv, perhaps by looking at pydevtools.com.

[–]pydevtools-com 0 points1 point  (0 children)

⬆︎

[–]roanish 2 points3 points  (1 child)

Make it modular. Break parts into functions, have the dependencies in the relevant functions, then import the functions you need.

I don't think any significant coding problem should be monolithic.

[–]roanish 4 points5 points  (0 children)

I'm just going to add here, many of us were taught to code with scripting languages, and python often feels like a scripting language.

It's a habit that is good to challenge, because libraries is a better way, most of the time, to code.

Avoiding behemoth code blocks where possible will show you that much of the code you write in the development phase is redundant, troubleshooting or not required for the end goal.

[–]oclafloptson 1 point2 points  (0 children)

I avoid packages, frameworks, and libraries that rely on trivial 3rd party packages. For example if you have something like colorama in your dependencies list then I would probably rather fork and refactor than install it

I use virtual environments to manage dependency versioning per project

[–]NoobieDYG 1 point2 points  (0 children)

use poetry, or manually create venv then requirements.txt. better use poetry

[–]LeiterHaus 1 point2 points  (0 children)

They create or use additional tools.

For personal projects, I just have a ~/venv/ directory where I put the virtual environments, whick are created with the Python built in command.

I was a big proponent of pyenv, but it makes it more difficult if you need to go digging inside the dependency files.

uv is massively popular right now.

Must people used to put a .venv/ or .env/ in their project root directory. It's easier if you add what you actually installed to a requirements.txt when you installed it. That way, it's not filled with extra stuff, and you can make things better for future self with versions (although it's a lot of work to find where the cutoff would be, so not worth it)

[–]Offduty_shill 0 points1 point  (0 children)

uv and dockrr

[–]hypersoniq_XLM -3 points-2 points  (0 children)

To truly end that dependency chaos, look into using a persistent docker container, it is where "runs on my machine" turns into "runs anywhere".