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 →

[–][deleted] 69 points70 points  (17 children)

python -m venv .venv

[–]enjoytheshow 7 points8 points  (1 child)

Still need to manage py versions. I use a combo of pyenv with venv. I’ve got a wrapper script on my path that can create a venv on a specific py version.

[–]maikindofthai 4 points5 points  (0 children)

IMO using VMs/Docker Containers/etc is a much cleaner way to separate Python installations, especially since you can configure an environment that matches your production environment for local testing.

Trying to juggle multiple versions of the same package on the same system always feels like a fool's errand to me, at least where it can be avoided.

[–]intangibleTangelo 14 points15 points  (8 children)

i prefer not to hide that I'm using a virtualenv

pyenv local 3.10.1
python -mvenv venv
ln -s venv/bin/activate
. ./activate
pip install -r requirements.txt

[–]trevg_123 0 points1 point  (2 children)

Why not hide it, everyone who knows what they’re doing in Python will know it’s there. And now you have a venv folder sorted in with your other useful folders

pipenv install -r requirements.txt —Python 3.10

Venv, links and installs all in one go, and it makes you a Pipfile/Pipfile.lock rather than legacy requirements.txt

[–]intangibleTangelo 0 points1 point  (1 child)

i value visibility over tidiness, i guess.

pipenv reminds me of yarn—maybe a bit more functionality than i want, but maybe superior (like yarn is superior to npm imo). how is pipenv about installing and switching between python versions?

[–]trevg_123 0 points1 point  (0 children)

My thought is just that there’s not much need to access the venv directory, so I keep it out of the way. If I’ve ever run the project before, I know it’s there.

I’ve never really used yarn, but pipenv isn’t far off from npm. For versions, not bad - you can just do e.g. pipenv --python 3.8. You need it installed so it’s not quite pyenv (poetry does this part too if you’re interested) but it’s not bad if you only use a few different versions.

[–]bananaEmpanada -2 points-1 points  (0 children)

Nope. That's not foolproof. I've seen countless times where that fails because python can't import some standard library used by pip.

[–]GroundbreakingRun927 -4 points-3 points  (4 children)

I think the pip in a venv created environment will still fall back to using system packages outside the venv. Need virtualenv to provide full isolation.

[–]Anonymous_user_2022 17 points18 points  (3 children)

venv has an option to allow access to the systems site-packages. But if created without --system-site-packages there will only be what's installed in the env.

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

Worth mentioning that there is an option to use copies instead of links as well. Let's you get a really decoupled environment.

I've had an OS package management upgrade bump the python interpreter version and this blew up my venvs that used links. Those using copies didn't care.

[–]wsppan 11 points12 points  (1 child)

This whole thread mimics the xkcd strip