I'm not sure this can be really fixed with Python 3, maybe we just have to hope for Python 4
Programming
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
It's fixed, and the python version had nothing to do with it. Just use hatch
Just out of curiosity, I haven't seen anyone recommend miniconda... Why so, is there something wrong I'm not aware of?
I'm no expert, but I totally feel you, python packages, dependencies and version matching is a real nightmare. Even with venv
I had a hard time to make everything work flawlessly, especially on MacOS.
However, with miniconda everything was way easier to configure and worked as expected.
Python's packaging is not great. Pip and venvs help but, it's lightyears behind anything you're used to. My go-to is using a venv for everything.
It's something of a "14 competing standards" situation, but uv seems to be the nerd favourite these days.
I still do the python3 -m venv venv && source venv/bin/activate
How can uv help me be a better person?
And pip install -r requirements.txt
You re not stupid, python's packaging & versionning is PITA. as long as you write it for yourself, you re good. As soon as you want to share it, you have a problem
as long as you write it for yourself, you re good. As soon as you want to share it, you have a problem
A perfect summary of the history of computer code!
Python never had much of a central design team. People mostly just scratched their own itch, so you get lots of different tools that do only a small part each, and aren't necessarily compatible.
everyone focuses on the tooling, not many are focusing on the reason: python is extremely dynamic. like, magic dynamic you can modify a module halfway through an import, you can replace class attributes and automatically propagate to instances, you can decompile the bytecode while it's running.
combine this with the fact that it's installed by default and used basically everywhere and you get an environment that needs to be carefully managed for the sake of the system.
js has this packaging system down pat, but it has the advantage that it got mainstream in a sandboxed isolated environment before it started leaking out into the system. python was in there from the beginning, and every change breaks someone's workflow.
the closest language to look at for packaging is probably lua, which has similar issues. however since lua is usually not a standalone application platform it's not a big deal there.
The reason you do stuff in a venv is to isolate that environment from other python projects on your system, so one Python project doesn’t break another. I use Docker for similar reasons for a lot of non-Python projects.
A lot of Python projects involve specific versions of libraries, because things break. I’ve had similar issues with non-Python projects. I’m not sure I’d say Python is particularly worse about it.
There are tools in place that can make the sharing of Python projects incredibly easy and portable and consistent, but I only ever see the best maintained projects using them unfortunately.
I agree. Python is my language of choice 80% or so of the time.
But my god, it does packaging badly! Especially if it's dependent on linking to compiled code!
Why it is like that, I couldn't tell. The language is older than git, so that might be part of it.
However, you're installing python libraries from github? I very very rarely have to do that. In what context do you have to do that regularly?
Python is hacky, because it hacks. There’s a bunch of ways you can do anything. You can run it on numerous platforms, or even on web assembly. It’s not maintained centrally. Each “app” you find is just somebodies hack project they’re sharing with you for fun.
Python is the new Perl
On that note, I'm hesitant between writing my scripts in perl or python right now. Bash prevent sharing with Windows peoples... I just want to provide easy wrappers tools that are usually aroud 10 lines of shell, but testers ain't on linux so they cannot use them.
I don't know perl, but each time I interract with pyton's projects I have a different venv/poetry/... to setup. Forget adout it the next time and nothing is kept easy to reuse.
With all the hype surrounding Python it's easy to forget that it's a really old language. And, in my opinion, the leadership is a bit of a mess so there hasn't been any concerted effort on standardizing tooling.
Some unsolicited advice from somebody who is used more refined build environments but is doing a lot of Python these days:
The whole venv
thing isn't too bad once you get the hang of it. But be prepared for people to tell you that you're using the wrong venv for reasons you'll never quit understand or likely need to care about. Just use the bundled "python -m venv venv" and you'll be fine despite other "better" alternatives. It's bundled so it's always available to you. And feel free to just drop/recreate your venv whenever you like or need. They're ephemeral and pretty large once you've installed a lot of things.
Use "pipx" to install python applications you want to use as programs rather than libraries. It creates and manages venvs for them so you don't get library conflicts. Something like "pip-tools" for example (pipx install pip-tools).
Use "pyenv" to manage installed python versions - it's a bit like "sdkman" for the JVM ecosystem and makes it easy to deal with the "specific versions of python" stuff.
For dependencies for an app - I just create a requirements.txt and "pip install -r requirements.txt" for the most part... Though I should use one of the 80 better ways to do it because they can help with updating versions automatically. Those tools mostly also just spit out a requirements.txt in the end so it's pretty easy to migrate to them. pip-tools is what my team is moving towards and it seems a reasonable option. YMMV.
venv nonsense
I mean, the fact that it isn't more end-user invisible to me is annoying, and I wish that it could also include a version of Python, but I think that venv is pretty reasonable. It handles non-systemwide library versioning in what I'd call a reasonably straightforward way. Once you know how to do it, works the same way for each Python program.
Honestly, if there were just a frontend on venv that set up any missing environment and activated the venv, I'd be fine with it.
And I don't do much Python development, so this isn't from a "Python awesome" standpoint.
pyenv and uv let you install and switch between multiple Python versions.
As for uv, those come from the Python build standalone project, if I remember correctly, pyenv also installs from there, but don't quote me on that.
Yeah the tooling sucks. The only tooling I've liked is Poetry, I never have trouble installing or packaging the apps that use it.
Downside: "^1.2.3"
as default versioning for libraries. You just pinned a version? Oh great, now I can't upgrade another library because you had to pin something in yours...
That non-standard syntax has been a PITA for the last few years. That being said: They created that syntax for regular applications (and not for libs) in a time when the pyproject.toml
syntax was not anywhere near finalization.
Personally, I've found Poetry somewhat painful for developing medium-sized or larger applications (which I guess Python really isn't made for to begin with, but yeah).
Big problem is that its dependency resolution is probably a magnitude slower than it should be. Anytime we changed something about the dependencies, you'd wait for more than a minute on its verdict. Which is particularly painful, when you have to resolve version conflicts.
Other big pain point is that it doesn't support workspaces or multi-project builds or whatever you want to call them, so where you can have multiple related applications or libraries in the same repo and directly depending on each other, without needing to publish a version of the libraries each time you make a change.
When we started our last big Python project, none of the Python tooling supported workspaces out of the box. Now, there's Rye, which does so. But yeah, I don't have experience yet, with how well it works.
This is exactly how I feel about python as well... IMHO, it's good for some advanced stuff, where bash starts to hit its limits, but I'd never touch it otherwise
It... depends. There is some great tooling for Python -- this was less true only a few years ago, mind you -- but the landscape is very much in flux, and usage of the modern stuff is not yet widespread. And a lot of the legacy stuff has a whole host of pitfalls.
Things are broadly progressing in the right direction, and I'd say I'm cautiously optimistic, although if you have to deal with anything related to conda then for the time being: good luck, and sorry.
Docker might be solution here.
But from my experience most python scripts are absolute junk. The barrier for entry is low so there's a massive disparity in quality.