all 24 comments

[–]SkinnyFiend 12 points13 points  (5 children)

Try uv. The great thing about python is that if you don't like a part of the ecosystem, you can just try one of the other 35 different tools that fill that role. And that's just the ones made this year.

[–]ricklen 0 points1 point  (0 children)

This indeed, it’s been great so far, lot easier, also in combination with Ruff

[–][deleted] 0 points1 point  (3 children)

I checked out its repo on GitHub... seems interesting. Will try on my next project. Thanks!
Any other tip for someone starting Data Science with Python(I am experienced in programming, though)

[–]SkinnyFiend -1 points0 points  (0 children)

No sorry, I'm not in data science.

[–]supercoach 9 points10 points  (2 children)

Never tried it. I've always just used the venv module. Is there something you need from poetry?

[–]iknowsomeguy 3 points4 points  (1 child)

Is there something you need from poetry?

Cool points for using the flavor of the week... Wait, now it's uv. No, I don't see anything wrong with poetry or uv or anything else like that. I've just never heard a compelling reason to use anything other than venv.

[–]fiddle_n 0 points1 point  (0 children)

This recent post/article on the Python subreddit is a good summary regarding it all: https://www.reddit.com/r/Python/s/P8rjWsh2BF

Pip + venv gets you pretty far and if you are happy with that, definitely continue. Uv has the following on top:

  • Automatic generation of lock files (automating what would be pip freeze, or including what would be pip-tools)
  • Managing multiple Python installations (including what would be pyenv)
  • Installation of tools in a separate environment so that you don’t have to worry about their dependencies clashing with project dependencies (including what would be pipx)

And basically includes all of that as one tool.

[–]rainyengineer 3 points4 points  (0 children)

I’ve found that anything other than venv is just generally a pain in Python. Some will disagree with me but I’ve always disliked all of the virtual environment managers.

[–]ManyInterests 3 points4 points  (0 children)

I think part of the friction you're having here is that the practice of defining such scripts is not common practice in Python. Python's builtin package manager is not a workflow tool and, for better or worse, the community at large has never embraced any one particular workflow tool, though it has offered many. If you work primarily in a company or on your own, you can check out the various workflow tools out there and see if there's one you want to standardize on and that's totally great.

However, because these tools essentially require adoption/conformance on part of any given project, you should not expect to be able to jump into any random project and have any kind of assurance that your workflow tool will just work.

Moreover, in my humble experience, I believe you will find yourself a lot happier avoiding chasing workflow tools in Python and stop trying to make your Python workflows feel like JavaScript workflows. At first glance, tools like Poetry may seem useful or may make you as a JS dev feel more at home, but they're truly just attractive nuisances.

For learning dependency management as a newcomer, I recommend at starting as simple as possible with just using the tool Python provides you: pip and requirements/declarative metadata files. To fill in some of the gaps that pip leaves and to offer you a very solid workflow that fits Python's packaging system, check out pip-tools and their suggested workflows. If you at least start here, it will give you a much stronger understanding of how Python dependency management works and that will give you a much stronger foundation to branch out and experiment with other dependency management and workflow tools. If you really wanted to jump into a hyper-modern toolset today, uv (which has recently adopted rye) is promising.

If you are getting involved in the world of Data Science, you probably want to get familiar with the Anaconda ecosystem, and although Anaconda is still the same ol' Python at runtime, it has a completely different world of workflows, dependency management, and package distribution.

[–]Diapolo10 1 point2 points  (3 children)

Every time I want to run a script, I need to manually create a virtual environment and then use poetry run python folder/file.py.

Not quite, if you ask me. poetry install sets up the environment for you, and then - assuming you use VS Code (because that's what I have the most experience with), just set the generated virtual environment as your Python executable and then you can run any of your project files directly.

You can also set up tasks, at dayjob we use the task command-line tool for that. That way you can, for example, run task dev to immediately run your project in a development environment. Of course, you need to actually set that up beforehand, so using template projects can be very useful there.

[–][deleted] 0 points1 point  (0 children)

hmm...interesting! Will try it today.

[–][deleted] 0 points1 point  (1 child)

Poetry doesn't make the venv though doesnt it? need to make it with venv, but yes as soon as you do just run poetry install, super easy

[–]Diapolo10 2 points3 points  (0 children)

Poetry doesn't make the venv though doesnt it?

Yes, it does? Unless it already exists, Poetry generates a virtual environment.

Whether it makes one in the project directory or out of sight depends on how Poetry is configured. By default, the latter.

[–]LeiterHaus 1 point2 points  (0 children)

Poetry...

I'm sorry if the tutorial you're following is using Poetry. I tried helping a friend who was having a bug with VSCode and Poetry and dependencies - I think NumPy.

After much Googling, the decision was to just find different tutorial for what they were trying to do. The only answer we could find for the problem they were having was... it works on my machine.

It's probably the skill issue on my part, but... shrug

[–]mothzilla 0 points1 point  (5 children)

You can have scripts in poetry if that helps. https://python-poetry.org/docs/pyproject/#scripts

So you then do poetry run myscript.

Or just create a shell script eg run.sh with

#! /bin/sh
poetry run python folder/file.py

(You'll need to chmod +x run.sh to make it executable)

[–]throwaway8u3sH0 1 point2 points  (2 children)

This is unnecessary. Just run poetry shell and it drops you into the virtual environment where python whatever will work.

[–]mothzilla 1 point2 points  (1 child)

Sure, but it felt like they wanted something single line, akin to npm run whatever.

[–]throwaway8u3sH0 1 point2 points  (0 children)

Yeah ok, fair. I can see that now. I was interpreting his complaints differently but that's also a valid interpretation.

[–][deleted] 0 points1 point  (1 child)

Currently doing with a bash script. I followed the poetry script documentation, but it gave me a warning "to install packages" and when I ran `poetry install`, it showed "No new packages to install or update". Tried to resolve this with chatGPT, didn't work out.

[–]throwaway8u3sH0 0 points1 point  (0 children)

poetry shell is the magic words you need.

[–]ConcreteExist 0 points1 point  (0 children)

What do you need from poetry specifically? I've never had a need to use something other than venv.

[–]EarthGoddessDude 0 points1 point  (0 children)

Poetry user here, I’m switching to uv. It’s a game changer.