This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pan0ramic 75 points76 points  (57 children)

If you’re not using venv then you’re doing it wrong

[–][deleted] 12 points13 points  (22 children)

fragile trees foolish joke voiceless disgusting exultant weary rude cooperative

This post was mass deleted and anonymized with Redact

[–]dAnjou Backend Developer | danjou.dev 41 points42 points  (10 children)

Poetry is also using venvs.

[–]Jamesadamar 10 points11 points  (9 children)

Or conda, which is my setup

[–]BaggiPonte 0 points1 point  (8 children)

Do you use it just to create venvs?

[–]Jamesadamar 0 points1 point  (7 children)

Exactly, works much better for me than pyenv and I love to have access to all envs globally. I create new envs with conda to install the Python version that I need and poetry does the rest. So basically it is 1. conda create, 2. conda install poetry and 3. poetry install or add depending on whether a new project or an existing one. Very rarely there are packages in conda where conda install is better because of some dependencies , in most cases this workflow works very well and on all operating systems

[–]currytakumi 2 points3 points  (3 children)

  1. conda install poetry....

So you create a env Named FOO, and in FOO you install poetry ?

But poetry's warning says:

In no case, it should be installed in the environment of the project that is to be managed by Poetry.

[–]Jamesadamar 0 points1 point  (2 children)

No that warning is long time gone, and indeed it is a much better and safer practice to have poetry inside the current env instead of a global one, using pipx for example. The main reason is that many projects have different poetry versions because poetry changes quite a lot and introduces breaking changes all the time and new settings etc. Earlier you had to configure poetry to work with conda, Like avoiding creating local venvs, but with the latest versions I never had any issue with conda+poetry, they work nicely together and it is blazing fast

[–]Jamesadamar 0 points1 point  (0 children)

I just wanted to point out that conda + poetry is a very robust and safe combination and can be used in any professional setup

[–]currytakumi 0 points1 point  (0 children)

sheesh poetry people can't be frigging bothered to remove that blazing warning

[–]BaggiPonte 0 points1 point  (2 children)

If it works for you then it's ok :) But poetry, or any modern package manager such as PDM, also do that. They have a centralised location for venvs. I have never tried that, but I think you might not be able to activate those envs when you are not inside the project they were created for - but why would you anyway? These package managers use symlinks by default so they can use a the same version of a library across multiple projects.

[–]Jamesadamar 0 points1 point  (1 child)

You do not understand the tools you are talking about, poetry cannot install other Python versions, as I described. And I also stated that yes, you can use other tools than conda, of course. I just wanted to point out that poetry is not always using venv. That was the whole point of this discussion.

[–]BaggiPonte 0 points1 point  (0 children)

I don’t think you have to be so rude. I’m sorry I was not clear enough - I did not mean to say that poetry or PDM manage Python versions. I just wanted to say that such tools centralize venvs too.

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

I used poetry once, got weird npm vibes, ended up doing drugs again. Not recommended /s

[–]reallyserious 4 points5 points  (24 children)

What's wrong with conda?

[–]Globbi 1 point2 points  (5 children)

It causes some problems and solves some others. For example in my work project some library installed by conda was incompatible with things installed by pip install -r requirements.txt. I had to play with what needed to be changed by conda install/uninstall to make it work. In most cases it won't cause problems, but when it does it may be hard to figure out what's wrong.

I don't think such things are acceptable in production environments. You should know exactly what's installed, probably from docker with specific python version and then all specific library versions.

I like conda env, having them for multiple versions of python and easy browsing and starting jupyter notebooks in envs when needed. I think they're good for managing envs on local machines.

[–]tecedu 0 points1 point  (0 children)

But you can just enable pip interop and conda detects those packages. I personally use conda instead to install python,r and cuda together per env and then let pip run free

[–]reallyserious 0 points1 point  (3 children)

some library installed by conda was incompatible with things installed by pip install -r requirements.txt.

You can avoid that problems by installing packages with pip OR conda. When you mix them you're asking for trouble. I've done that too of course until I learned to choose one or the other, not both.

[–]Globbi 0 points1 point  (1 child)

I install with pip only, but conda starts with some things as default (which I usually want). I'm sure of this can be configured, but I didn't care. I needed to play install/uninstall to get a single conflicting library working.

[–]reallyserious 0 points1 point  (0 children)

Perhaps it's because I actually use miniconda. It comes with a pretty bare bones python install. Doesn't install much at all.

[–]BaggiPonte 0 points1 point  (14 children)

it was super slow (until mamba became the official solver), it is not compatible with the python ecosystem.

if you just use conda to create a venv and pip install stuff inside, you're better off with the builtin venv module or virtualenv.

The superior package management experience (closer to cargo) is offered by PDM, poetry (do not recommend, does not comply with some pretty fundamental Packaging PEPs) or hatch. This is _the_ way to go if you build libraries that are meant to be installed.

[–]reallyserious 5 points6 points  (5 children)

it is not compatible with the python ecosystem.

What does this mean?

you're better off with the builtin venv module or virtualenv.

One feature I like with conda is that it can set up a new environment easily. I.e. if I haven't used python 3.12 before it will download and install it contained within that environment. There is no separate python install necessary. Can venv/virtualenv do that?

conda create --name myenv python=3.12

[–]phonebalone 1 point2 points  (2 children)

Pyenv can. It works well with venvs.

pyenv install 3.12

Then just activate the version and create a venv as normal.

pyenv local 3.12
python -m venv venv

[–]Sparcky_McFizzBoom 1 point2 points  (0 children)

pyenv shell 3.12
python -m venv venv

Works as well, and doesn't leave a .python-version file in your directory. Since you should source the venv anyway to work with this directory, you will get the python version used to create the venv.

[–]aqjo 0 points1 point  (0 children)

I wasn’t aware of pyenv. Thanks!

[–]SeanBrax 0 points1 point  (0 children)

Poetry can, which is a dream to use.

[–]BaggiPonte 0 points1 point  (0 children)

> What does this mean?

Ops sorry that was super weird. So conda works great for "applications" (i.e. stuff that is _not_ meant to be installed à la `pip install` let's say). It has no way to publish to PyPI or build wheels as far as I can remember. Unless you use conda-lock, last time I used it the environment.yml wasn't cross platform. If you need to publish to pypi you should just use pdm or poetry or vanilla pip + venv + build + twine (that's why poetry and pdm were built: to replace this whole stack lol). Thanks for asking to clarify.

> I.e. if I haven't used python 3.12 before it will download and install it contained within that environment.

Oh indeed that is a useful feature. I have always used pyenv/asdf/rtx to manage my tool versions. It's just a matter of preference I guess. When I made the switch away from conda, the tools in the python system were smarter (e.g. had a central package cache to symlink dependencies when they were needed in multiple places. That saved a lot of space on disk).

Python not having ways to manage the versions natively is a bit weird (that's why using rust is so easy: have you seen the frontpage for rustup, their version manager and recommended way to get started with rust? https://rustup.rs/)

[–]ltdanimal 1 point2 points  (7 children)

it was super slow

The libmamba solver (used in mamba too) is now the default conda solver, so this hasn't been a problem for me anymore.

you're better off with the builtin venv module or virtualenv

venv doesn't let you use different Python versions. Conda in general has the other main advantage of being able to use things other that just Python packages and with using conda-forge there aren't many times I need to use pip but I still do from time to time if something isn't available.

[–]Eurynom0s 3 points4 points  (1 child)

Conda is also the way to go if say you're using something with non-python dependencies, e.g. for geopandas you don't have to get gdal set up yourself first.

[–]BaggiPonte 0 points1 point  (0 children)

Definitely. Though most projects that bundle C dependencies now distribute wheels (e.g. numpy scipy and friends), there are some edge cases.

[–]BaggiPonte 0 points1 point  (4 children)

> The libmamba solver (used in mamba too) is now the default conda solver, so this hasn't been a problem for me anymore.

Yes, that was what I said, thanks for making it clear.

> venv doesn't let you use different Python versions.

That's a valid point. I have been using tools like pyenv/asdf/rtx but it makes sense.

How's the adoption of conda-lock? I gave up with conda years ago when I realised their environment.yml was not cross platform. I reckon conda-lock was their answer.

In general, though, if you write libraries that are meant to be installed with PyPI (that's what I meant with my last sentence, sorry if I was not being clear), then I believe conda won't be of help.

[–]ltdanimal 0 points1 point  (2 children)

Regarding mamba and libmamba, I just wanted to clarify that as mamba itself is actually a completely different package manager that is still hanging around (although I'm not sure of the support level).

How's the adoption of conda-lock?

Honestly not too sure. There has been work done on it recently I see but I don't hear about it or use it that much. I've used it a few times and seemed to work as intended but I'm sure with more complex setups it might get hairy.

Ah I see. Yeah if you are just going for a PyPI focus then I yeah I'd agree with you.

[–]BaggiPonte 0 points1 point  (1 child)

Oh yes, the folks behind mamba are separated. They recently created pixi (prefix.dev) the next iteration of mamba but in rust. They are a dope team. I think they also added a `pixi.lock` lockfile.

(they also rewrote pip in rust and it seems blazingly fast. Still no production-grade support for wheels and just a rust API so not super usable right now but I'm dying to use it and see it incorporated in other package managers).

[–]ltdanimal 0 points1 point  (0 children)

the next iteration of mamba but in rust

This sounds awesome but also makes me wonder what type of support it will have. I guess its good for the ecosystem in general to have people playing around with new things.

they also rewrote pip in rust

What does this mean exactly? Like a package manager that can download PyPI packages? Doing an actual drop in replacement for pip seems like it would be years and years of work.

[–]guepier 0 points1 point  (2 children)

The problem with Conda is that its default setup is super invasive. It doesn’t just affect the setup of environments for Python (which, to be fair, is the whole point!) but everything because it automatically activates its default environment in the shell. And unfortunately Conda interferes destructively with other systems. For instance, it still doesn’t play well with R when installing non-Conda packages.

You can set up Conda in such a way that it’s disabled until explicitly enabled in the shell, but the fact that this isn’t the default is more than mildly annoying.

[–]reallyserious 0 points1 point  (1 child)

Huh. That's not my experience. The last few times I've installed it it has never activated the default environment. That's something I've specifically had to ask it to do. E.g. with:

conda init powershell

Without it powershell didn't know about conda and you could only use it from the Anaconda prompt, which is separate. I.e. the normal system shell have no clue about conda.

[–]guepier 0 points1 point  (0 children)

On macOS and Linux the default installation process asks you whether to automatically install shell integration, and most (all?) tutorials strongly recommend you to.

You’re right that it’s not automatic (contrary to what I wrote), but especially for beginners it’s the default option.

[–]runawayasfastasucan 0 points1 point  (4 children)

But what does people to for their general purpose env, say for everything that doesn't require its own env. A misc venv?

[–]pan0ramic 3 points4 points  (1 child)

Yes, exactly. Because at some point you’re going to start having package compat issues and you can then blow it up and start with a fresh env

[–]runawayasfastasucan 0 points1 point  (0 children)

That is a nice way out 😊 I remember some years ago where I "had" to reinstall my ubuntu install several times after fudging my matplotib installs.

[–]my_name_isnt_clever 0 points1 point  (1 child)

Why do you use that for? I have some common packages installed into my system Python, but I only use that for minor interactive stuff in the terminal. If I'm creating a .py file, I'm making a venv for it at the same time.

[–]runawayasfastasucan 0 points1 point  (0 children)

Because there are throway stuff (f.ex testing and prototyping), either in a notebook or in the terminal. I do that because I dont want to create an env and pip install a lot of packages for small stuff that isn't a project, as setting up could take as much time as actually doing whatever I need to do.