Live data from Hacker News

You don't really need a virtualenv

frostming.com

11–20 of 148 posts

Re: You don't really need a virtualenv

#11
post #9
post #7

Earlier quoted context omitted.

A virtualenv is just a bunch of packages, you end up with the same thing whatever you want to call it. It is probably a more roundabout solution that it needs to be, but I don't find many problems myself (also using poetry).

He also said virtual envs install their own copy of Python. No need for that either. Coming from other languages the whole virtual env thing seems alien especially the way it messes with your shell.

A virtualenv (venv) does not install its own copy of Python. Instead, when you create the venv it puts symlinks for the calling python in the /bin directory. When you activate the venv the /bin is added to the front of your PATH so that any "python" commands use the symlink'ed version of Python corresponding to your venv.

Re: You don't really need a virtualenv

#12
post #9
post #7

Earlier quoted context omitted.

A virtualenv is just a bunch of packages, you end up with the same thing whatever you want to call it. It is probably a more roundabout solution that it needs to be, but I don't find many problems myself (also using poetry).

He also said virtual envs install their own copy of Python. No need for that either. Coming from other languages the whole virtual env thing seems alien especially the way it messes with your shell.

Activating the venv is completely optional. I never do it, but some people seem to like it.

Re: You don't really need a virtualenv

#13
post #6

As a Ruby and Python developer I often wonder why Ruby doesn't need a virtual env. What did Ruby get right that Python didn't?

well, a lot of "system" utilities are implemented in Python and I'm not aware of many in Ruby (they must exist? I just checked to see what on my system depends on Ruby and it seems like the only things are a screenruler utility, some texlive packages I've never heard of and gnome-code-assistance, whatever that is). Pip installing random crap is a great way to completely break some Linux systems.

Re: You don't really need a virtualenv

#14
post #6

As a Ruby and Python developer I often wonder why Ruby doesn't need a virtual env. What did Ruby get right that Python didn't?

For development, the "install everything locally" that virtual env provides. This avoids conflicting, incompatible versions of packages being installed in a global or per-user location.

Python isn't at all the only language to suffer this problem. e.g. "DLL hell" and its variations like Haskell's "cabal hell". With Ruby, if its packages are installed with bundler, then these packages are installed locally in the project directory.

Re: You don't really need a virtualenv

#17
post #7
post #5

Earlier quoted context omitted.

As the authors said - no more virtual envs.

A virtualenv is just a bunch of packages, you end up with the same thing whatever you want to call it. It is probably a more roundabout solution that it needs to be, but I don't find many problems myself (also using poetry).

I haven't used Poetry and most of my workplaces have done their own thing with versioning Python packages. So my virtualenv experience has been on my own or with toy projects.

I really like writing one-off or sporadically used commandline tools. Loading a virtualenv or navigating to a directory before executing kind of sucks. Generally, I install into my homedir. I haven't read through or tried this out, but it seems like it might better address this use case.

You're right, this seems to be very similar. To me, it looks like it removes one abstraction layer of pushing-popping the environment.

Re: You don't really need a virtualenv

#19
I recommend virtualenv and virtualenvwrapper. I usually set up a new venv like this:

$ mkvirtualenv -a $(pwd) new_venv

$ pip install -r requirements.txt

When you want to activate this env and cd to the directory where you created it, you can simply do:

$ workon new_venv

That's all you need to know. It just works.

Re: You don't really need a virtualenv

#20
post #17
post #7

Earlier quoted context omitted.

A virtualenv is just a bunch of packages, you end up with the same thing whatever you want to call it. It is probably a more roundabout solution that it needs to be, but I don't find many problems myself (also using poetry).

I haven't used Poetry and most of my workplaces have done their own thing with versioning Python packages. So my virtualenv experience has been on my own or with toy projects. I really like writing one-off or sporadically used commandline tools. Loading a virtualenv or navigating to a directory before executing kind of sucks. Generally, I install into my homedir. I haven't read through or tried this out, but it seems…

I have recently found Golang to be a good alternative. I too like Python and still write lots of scripts in it merely out of familiarity.
Post reply on HN