News for hackers. Stuff that matters.
Re:Why not tell people to “simply” use pyenv, poetry or anac... by jooz on Thursday March 30, 2023 @06:09PM (#35379471)
Ive heard that 'venv' are very problematic, but honestly, Ive never had a problem. And I used them daily. I understand that it can not be enough on some cases... that don't concern me.

I would recommend to 'python -m venv' and thats all.

Re:Why not tell people to “simply” use pyenv, poetry or anac... by abrichr on Thursday March 30, 2023 @06:42PM (#35379853)
Agreed, never had a problem with this approach.

The only limitation I've encountered is when moving the environment or renaming one of the parent directories. In which case it's easy to create a new one:

    # optional: freeze the environment if you don't already have a requirements.txt
    source .venv/bin/activate
    pip freeze > requirements.txt
    deactivate

    # remove the old environment
    rm -rf .venv

    # create a new one
    python3.10 -m venv .venv

    # activate it
    source .venv/bin/activate

    # install the requirements
    pip install -r requirements.txt
Re:Why not tell people to “simply” use pyenv, poetry or anac... by nicoburns on Thursday March 30, 2023 @06:50PM (#35379934)
I've found that venv's work. They're just very inconvenient (having to constantly manage which venv you're in when you change directory). Consider that with NPM, only two of those commands are ever needed:

    # install the requirements
    npm install

    # remove it
    rm -rf node_modules
The rest is unnecessary because NPM uses the equivalent of a venv automatically based on your current working directory and the location of your package.json file.
Re:Why not tell people to “simply” use pyenv, poetry or anac... by sureglymop on Saturday April 01, 2023 @04:09AM (#35398297)
Python has this too, check out PEP 582. There's a package manager called PDM which will just create a __pyoackages__ folder in this style.
Re:Why not tell people to “simply” use pyenv, poetry or anac... by rami3l on Saturday April 01, 2023 @06:54AM (#35399175)
As a PDM enthusiast for quite a while, I'm sorry to inform you that PEP 582 has been officially abandoned (which doesn't mean that it won't be revived someday, just not so easily). https://discuss.python.org/t/pep-582-python-local-packages-d...
Re:Why not tell people to “simply” use pyenv, poetry or anac... by pepa65 on Tuesday April 04, 2023 @04:56AM (#35436918)
This just illustrates that the most recommended solution is not easy to use, many steps one could forget. And I guess if your package manager happens to update your default python, more/other steps will be necessary...
Re:Why not tell people to “simply” use pyenv, poetry or anac... by abrichr on Tuesday April 04, 2023 @08:39AM (#35438661)
Venvs are self contained python environments, no interaction with system python.

For those already familiar with venvs, the above just condenses to “remove the old venv and create a new one”.

Re:Why not tell people to “simply” use pyenv, poetry or anac... by Groxx on Thursday March 30, 2023 @06:39PM (#35379818)
I've heard a lot (a lot) of complaints that are wildly misattributed to venv (like "version X of Y broke my project"), but I've essentially never heard of issues with venv itself.

Aside from needing to know to use it. Which is certainly a problem. But python blessing a single venv-system might be worse in the long run...?

Re:Why not tell people to “simply” use pyenv, poetry or anac... by hobs on Thursday March 30, 2023 @06:36PM (#35379795)
Same no problem, different solution - I use pycharm extensively and it manages my venvs 99% of the time with no issues at all, the only time it took me a minute of head scratching was realizing I needed to install a new system python to make a venv with it, but that would be clear if you were doing it via the shell approach you are using as well.
Re:Why not tell people to “simply” use pyenv, poetry or anac... by bobx11 on Thursday March 30, 2023 @06:35PM (#35379779)
This is also my setup. It has the added benefit of being already included on every python install already so there is nothing extra to use.
Re:Why not tell people to “simply” use pyenv, poetry or anac... by nagonago on Thursday March 30, 2023 @06:48PM (#35379922)
I'm curious what these problems are. The only problem I've had with venv is that sometimes I forget to activate it.

As the article says, I think these days it's pretty safe to just use Python's built-in venv and stay away from everything else.

Re:Why not tell people to “simply” use pyenv, poetry or anac... by tetha on Thursday March 30, 2023 @06:49PM (#35379932)
This is one of the jenga towers that seem to hold up most reliably for me as well. (i) Use python installed via the package manager. (ii) If python is updated, wipe all venvs, because there can be strange interactions between venvs and the installed python and rebuilding venvs is cheap, and (iii) Work in venvs as much as possible.
Re:Why not tell people to “simply” use pyenv, poetry or anac... by BiteCode_dev on Friday March 31, 2023 @03:43AM (#35383928)
That's pretty much the take of the article this one references.

The whole reason I posted this one is to justify the "just use -m pip and -m venv" stance I wrote in the article 4 days ago.

Because you will always have a very vocal minority of people that will fill the threads with counter arguments actually increasing complexity and risks of failure.

Re:Why not tell people to “simply” use pyenv, poetry or anac... by atemerev on Friday March 31, 2023 @03:50PM (#35392542)
How do you manage python versions with venv? E.g. numba still doesn’t run on my system python 3.11, so I want a 3.10 somewhere, but can’t install it through a package manager, etc.
Re:Why not tell people to “simply” use pyenv, poetry or anac... by 0xDEFACED on Saturday April 01, 2023 @05:54PM (#35404484)
If using apt, you can add the deadsnakes repository which allows installing the other versions of python3 not included with your linux distro. Then you can install them with

  sudo apt install python3.X
I also recommend similarly

  sudo apt install python3.X-venv
which allows you to create venvs with whichever python version you have installed

  python3.X -m venv .venv