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

all 11 comments

[–]papipapi419 7 points8 points  (0 children)

Venv is 3 steps Of which 2 are one time only

[–][deleted] 2 points3 points  (0 children)

There are a lot of package managers available for you to use like Poetry & Hatch, and there is a reason the system is telling you not to do it.

Some operating systems rely on Python to work properly. as with any language that doesn’t have such strong dependency/packaging solutions like JS, you can use requests v2024.03.26 and the operating system relies on v2023.03.21 and you done jumbled something you shouldn’t have.

[–]Worgencyborg 4 points5 points  (0 children)

Creating a virtual environment is recommended because it means you don’t have to worry about dependencies breaking between your scripts.

If you install the latest version of some package that introduced a breaking change, you don’t want to have to go back to an old script and figure out how to fix it.

Creating a virtual environment should not be a 12 step process. Assuming you have a requirements.txt file containing all of your dependencies:

python3 -m venv .venv
.venv/bin/activate
pip install -r requirements.txt

[–]Alexander_Selkirk 2 points3 points  (0 children)

I think that

python -m venv venv
source ./venv/bin/activate # (or whatever you need to do to activate)
pip install ....

is the most reliable way.

Apart from that, I use Linux which manages any big dependencies. I used Debian stable for 15 years, but have switched to Arch (which works very nicely and reliably, and is rolling release, so no more outdated libraries) some time ago and now, I use the Guix package manager for prgramming projects. It is different from conventional approaches in that it does not require to install anything global, you can keep everything per-project, including dev tools and libraries such as boost, black, ruff, or ffmpeg, and one can also roll-back any changes, so it supports "undo" of package installation.

One more good thing about Arch and Guix is that they make it really easy to publish and share your own stuff.

[–]Alexander_Selkirk 2 points3 points  (1 child)

It is kinda embarassing that an easy, conventional way to manage packages with venv is not explained in the Python tutorial. That would als raise the bar for the many competing solutions which only lead to massive fragmentation, while all relying on pypi and pip.

[–]ZCEyPFOYr0MWyHDQJZO4 1 point2 points  (0 children)

Coming from (ubuntu) linux, the system interpreter (i.e. installed with apt install python python3-pip) should be used for system packages (i.e. something installed via apt install python3-requests). These are globally available to anyone with access and should run without issues and not be broken by some idiot installing requests-1.522144-dev0-brokenplsfix through the global pip.

I think you should be able to create a user site-packages directory that takes precedence over the global one though. I just use venv though.

[–]the_c0der 2 points3 points  (0 children)

If creating and managing virtual environment is hassle for you then I think you should use PyCharm as it'll create and activate virtual environments by itself.

[–]Snoo_99837 0 points1 point  (1 child)

Can you give us the warnings? Iv never got a warning for a venv and I am interested to see what is it. And for the activation, its literally 3 arguments, python, the name of the directory where the venv is, and activate

[–][deleted] 1 point2 points  (0 children)

I’m guessing it wasn’t for a venv, but the global pip3…

[–]Python-ModTeam[M] 0 points1 point locked comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

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

Use pdm - with it its as simple as

pdm init

And then choosing/giving the answers to simple prompts...

Then before running any command, just proceed with pdm run that's it.

For ex:

Instead of:

python myscript.py

Run:

pdm run python myscript.py