this post was submitted on 06 Nov 2024
134 points (97.9% liked)

Programming

17343 readers
334 users here now

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



founded 1 year ago
MODERATORS
 

So I'm no expert, but I have been a hobbyist C and Rust dev for a while now, and I've installed tons of programs from GitHub and whatnot that required manual compilation or other hoops to jump through, but I am constantly befuddled installing python apps. They seem to always need a very specific (often outdated) version of python, require a bunch of venv nonsense, googling gives tons of outdated info that no longer works, and generally seem incredibly not portable. As someone who doesn't work in python, it seems more obtuse than any other language's ecosystem. Why is it like this?

top 50 comments
sorted by: hot top controversial new old
[–] nucleative@lemmy.world 5 points 38 minutes ago* (last edited 35 minutes ago)

Python developer here. Venv is good, venv is life. Every single project I create starts with

python3 -m venv venv

source venv/bin/activate

pip3 install {everything I need}

pip3 freeze > requirements.txt

Now write code!

Don't forget to update your requirements.txt using pip3 freeze again anytime you add a new library with pip.

If you installed a lot of packages before starting to develop with virtual environments, some libraries will be in your OS python install and won't be reflected in pip freeze and won't get into your venv. This is the root of all evil. First of all, don't do that. Second, you can force libraries to install into your venv despite them also being in your system by installing like so:

pip3 install --ignore-installed mypackage

If you don't change between Linux and windows most libraries will just work between systems, but if you have problems on another system, just recreate the whole venv structure

rm -rf venv (...make a new venv, activate it) pip3 install -r requirements.txt

Once you get the hang of this you can make Python behave without a lot of hassle.

This is a case where a strength can also be a weakness.

[–] N0x0n@lemmy.ml 0 points 43 minutes ago* (last edited 28 minutes ago)

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.

[–] FizzyOrange@programming.dev 14 points 4 hours ago (1 children)

Yes it's terrible. The only hope on the horizon is uv. It's significantly better than all the other tooling (Poetry, pip, pipenv, etc.) so I think it has a good chance of reducing the options to just Pip or uv at least.

But I fully expect the Python Devs to ignore it, and maybe even make life deliberately difficult for it like they did for static analysers. They have some strange priorities sometimes.

[–] flubba86@lemmy.world 1 points 4 minutes ago* (last edited 3 minutes ago)

I like the idea of uv, but I hate the name. Libuv is already a very popular C library, and used in everything from NodeJS to Julia to Python (through the popular uvloop module). Every time I see someone mention uv I get confused and think they're talking about uvloop until I remember the Astral project, and then reconfirm to myself how much I disapprove of their name choice.

[–] vext01@lemmy.sdf.org 10 points 5 hours ago (1 children)

The venv stuff is pretty annoying, I agree.

[–] Lettuceeatlettuce@lemmy.ml 2 points 3 hours ago (1 children)

As a baby Python Dev, I'm glad it's not just me.

[–] flubba86@lemmy.world 1 points 1 minute ago

I've been full time writing python professionally since 2015. You get used to it. It starts to just make sense and feel normal. Then when you move to a different language environment you wonder why their tooling doesn't use a virtualenv.

[–] moonpiedumplings@programming.dev 7 points 6 hours ago (1 children)
[–] flying_sheep@lemmy.ml 2 points 5 hours ago (1 children)

No it's not. E.g. nobody who starts a new project uses setup.py anymore

OP seems to be trying to install older projects, rather than creating a new project.

[–] Jocker@sh.itjust.works 7 points 7 hours ago

I've started using poetry and the experience has improved.

[–] WolfLink@sh.itjust.works 13 points 9 hours ago* (last edited 9 hours ago)

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.

[–] antlion@lemmy.dbzer0.com 13 points 10 hours ago (1 children)

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.

[–] bhamlin@lemmy.world 7 points 9 hours ago (1 children)
[–] AnUnusualRelic@lemmy.world 2 points 1 hour ago (1 children)

After using python, I'm of the opinion that perl was much cleaner.

[–] bhamlin@lemmy.world 1 points 18 minutes ago

Yes. Its line noise was of a much higher quality. 😉

[–] vin@lemmynsfw.com 2 points 6 hours ago

Yep, they are not portable, every app should come bundled with its own interpreter. As to why, I think historically it didn't target production grade application development.

[–] Die4Ever@programming.dev 1 points 7 hours ago (1 children)

I'm not sure this can be really fixed with Python 3, maybe we just have to hope for Python 4

[–] flying_sheep@lemmy.ml 0 points 5 hours ago (1 children)

It's fixed, and the python version had nothing to do with it. Just use hatch

[–] Tja@programming.dev 5 points 5 hours ago (1 children)

Ah yes, the 15th standard we've been waiting for!

[–] flying_sheep@lemmy.ml 1 points 4 hours ago

It's not a standard, it's built on standards.

You can also use Poetry (which recently grew standard metadata support) or plain uv venv if you want to do things manually but fast.

[–] nickwitha_k@lemmy.sdf.org 50 points 17 hours ago

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.

[–] solrize@lemmy.world 45 points 16 hours ago (4 children)

It's something of a "14 competing standards" situation, but uv seems to be the nerd favourite these days.

[–] iii@mander.xyz 18 points 16 hours ago (2 children)

I still do the python3 -m venv venv && source venv/bin/activate

How can uv help me be a better person?

[–] PartiallyApplied@lemmy.world 3 points 5 hours ago

If you’re happy with your solution, that’s great!

uv combines a bunch of tools into one simple, incredibly fast interface, and keeps a lock file up to date with what’s installed in the project right now. Makes docker and collaboration easier. Its main benefit for me is that it minimizes context switching/cognitive load

Ultimately, I encourage you to use what makes sense to you tho :)

[–] GBU_28@lemm.ee 7 points 15 hours ago (1 children)

And pip install -r requirements.txt

[–] BeardedGingerWonder@feddit.uk 7 points 13 hours ago (1 children)

Fuck it, I just use sudo and live with the consequences.

[–] flying_sheep@lemmy.ml 2 points 5 hours ago
load more comments (3 replies)
[–] lime@feddit.nu 17 points 14 hours ago

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.

[–] kSPvhmTOlwvMd7Y7E@programming.dev 35 points 17 hours ago (1 children)

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

[–] MajorHavoc@programming.dev 12 points 16 hours ago

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!

[–] Rogue@feddit.uk 3 points 11 hours ago

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.

[–] Ephera@lemmy.ml 18 points 17 hours ago

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.

[–] atzanteol@sh.itjust.works 11 points 16 hours ago

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.

[–] iii@mander.xyz 14 points 17 hours ago

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?

[–] tal@lemmy.today 7 points 17 hours ago* (last edited 17 hours ago) (1 children)

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.

[–] scrion@lemmy.world 1 points 11 hours ago

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.

[–] priapus@sh.itjust.works 4 points 16 hours ago (1 children)

Yeah the tooling sucks. The only tooling I've liked is Poetry, I never have trouble installing or packaging the apps that use it.

[–] Ephera@lemmy.ml 1 points 8 hours ago

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.

load more comments
view more: next ›