Live data from Hacker News

A non-magical introduction to pip and virtualenv for Python beginners

dabapps.com

51–60 of 86 posts

Re: A non-magical introduction to pip and virtualenv for Python beginners

#51
post #24

Can someone explain the historical reasons for this problem even existing in the first place? (the problem that virtual env solves)

It also comes in handy when I'm trying to install something finicky that has a million dependencies, each of which also might be finicky (e.g. numba) and I screw something up and just want to start over clean and not muck around uninstalling things. virtualenv makes this easy—I just make a new environment for experimenting and then delete it if I mess up and want to start over, leaving my system configuration clean and other environments intact.

Re: A non-magical introduction to pip and virtualenv for Python beginners

#52
post #37

Man, global system-wide installations that require admin rights by default? That's certainly something! Quite the stark comparison to Node.js and npm, where everything is installed locally into the current directory (under node_modules) by default, and "global" installation is actually a per-user installation. Tricking pip with virtualenv seems to get you pretty close to what you get by default with npm, albeit still…

pip install --user XXX should get you what you want. Not default but not a huge burden either.

...Which would be equivalent to npm install -g XXX, whereas to replicate npm install XXX you'd need virtualenv. I don't think there even is an equivalent to pip install XXX without virtualenv with Node/npm (global system-wide installation for all users that requires admin rights).

Re: A non-magical introduction to pip and virtualenv for Python beginners

#53
post #33

Calling env/bin/python directly, as opposed to `source activate` is very handy for things like: * bash command line * cron * or daemon manager like supervisord

Yep. Years ago I settled on a convention of always installing a virtualenv into a 've' directory in the project so I can just set the shebang line on scripts (eg, django's manage.py) to "#!ve/bin/python". My Django project template sets all that up for me automatically. So now I just have muscle memory for typing "./manage.py ..." etc and I never have to activate virtualenvs, mess around with virtualenvwrapper type hacks or accidently run one project's script with a different project's virtualenv activated.

Re: A non-magical introduction to pip and virtualenv for Python beginners

#55
post #49

> Python actually has another, more primitive, package manager called easy_install, which is installed automatically when you install Python itself. It's actually not, it's part of setuptools/distribute, though some Python distributions (actually just brew that I know of) include distribute alongside Python. Also, while the quick skim of the rest of this looks mostly good, there's some unnecessary advice which compli…

How would you someone who has used pip with sudo undo the mess that has created in his computer? Uninstall everything and start over?

Yeah. You can use 'pip uninstall'.

Re: A non-magical introduction to pip and virtualenv for Python beginners

#56
post #49

> Python actually has another, more primitive, package manager called easy_install, which is installed automatically when you install Python itself. It's actually not, it's part of setuptools/distribute, though some Python distributions (actually just brew that I know of) include distribute alongside Python. Also, while the quick skim of the rest of this looks mostly good, there's some unnecessary advice which compli…

How would you someone who has used pip with sudo undo the mess that has created in his computer? Uninstall everything and start over?

Just start using virtualenv for everything. By default virtualenv starts you with a clean python setup each time and nothing you've installed globally with pip will affect you.

Re: A non-magical introduction to pip and virtualenv for Python beginners

#57

Python actually has another, more primitive, package manager called easy_install, which is installed automatically when you install Python itself. pip is vastly superior to easy_install for lots of reasons, and so should generally be used instead. You can use easy_install to install pip as follows: I found it quite ironic that the author says pip is "vastly superior" to easy_install and then proceeds to install pip u…

Those are two non-related things, unless your only metric of superiority is that it comes pre-bundled.

Re: A non-magical introduction to pip and virtualenv for Python beginners

#59

> Python actually has another, more primitive, package manager called easy_install, which is installed automatically when you install Python itself. It's actually not, it's part of setuptools/distribute, though some Python distributions (actually just brew that I know of) include distribute alongside Python. Also, while the quick skim of the rest of this looks mostly good, there's some unnecessary advice which compli…

As I install/develop my python apps into VMs with a fixed python version, I rarely use virtualenv... don't see the need for the extra complexity. I've eagerly read pieces like this but haven't yet found out the reason this solution is problematic or that I'm doing it wrong. Just that no one else seems to be recommending it. Anyone have an idea? Btw, one of the best discussions of the various deployment options I've s…

Virtualenv is about managing multiple/conflicting versions of libraries, not different versions of Python itself. You're accomplishing the same thing by using a different VM for each app, just with higher overhead and isolation of things other than Python as well.

Re: A non-magical introduction to pip and virtualenv for Python beginners

#60
post #37

Man, global system-wide installations that require admin rights by default? That's certainly something! Quite the stark comparison to Node.js and npm, where everything is installed locally into the current directory (under node_modules) by default, and "global" installation is actually a per-user installation. Tricking pip with virtualenv seems to get you pretty close to what you get by default with npm, albeit still…

npm's default for -g is to install to Node's prefix, which is usually /usr or /usr/local. If you want it to install to your home directory, you can set the prefix to somewhere appropriate in your ~/.npmrc, which gives roughly the same behavior as pip's --user flag.

Edit: perhaps you changed your .npmrc or set the option via npm and forgot about it? I just checked on a fresh user, and 'npm install -g' definitely tries to install to /usr, just like pip.

Post reply on HN