Live data from Hacker News

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

dabapps.com

21–30 of 86 posts

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

#21
Thanks for the article! I recently spent some time going through the process of learning VirtualEnv / Pip; after looking at several tutorials, agreed that this is one of the better ones out there. A few other things I saw in other articles that you might like to clarify (though I understand there's a tradeoff with simplicity/clarity).

(1) specifically state that `pip freeze` is how to create requirements file (as folks have said in comments already) (2) add "further reading" link on VirtualEnvWrapper, as it adds some convenience methods to ease use of VirtualEnv (3) the "yolk" package shows you what's currently installed; it can be helpful to `pip install yolk` then run `yolk -l` to view the different packages installed in each of your envs. (4) when installing a package, you can specify the version, e.g. `pip install mod==1.1`, whereas `pip install mod` will simply install the latest

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

#22

Want to make life even easier? Check out virtualenvwrapper. http://virtualenvwrapper.readthedocs.org/en/latest/ Lots of benefits, but trading 'cd path/to/my/project && source env/bin/activate' for 'workon project_env' (with autocomplete) is alone easily worth the five seconds it takes to check it out.

I find it's really useful for beginners to clearly understand what's actually happening under the covers before they start adding magical stuff on top. They can always add magic later, if they prefer that approach.

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

#25

> 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…

> What beginners (and even some more experienced programmers) need to learn about is --user. You install packages with `pip install --user thing`, and they become per-user installed (be sure to add `~/.local/bin` to your `$PATH`). This is enough to not require sudo and for 99% of cases is actually sufficient.

Is this relevant advice for packages needed by your web server account, e.g. www-data?

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

#26
post #24

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

Did... did you read the article? Separation of environments for projects with different dependencies.

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

#27

Want to make life even easier? Check out virtualenvwrapper. http://virtualenvwrapper.readthedocs.org/en/latest/ Lots of benefits, but trading 'cd path/to/my/project && source env/bin/activate' for 'workon project_env' (with autocomplete) is alone easily worth the five seconds it takes to check it out.

The only problem with virtualenvwrapper is setting it up can and does cause problems for beginning developers new to the shell. Otherwise it's really awesome. :-)

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

#28
post #20

VertualEnv seems less like a brilliant tool than it does a workaround for an architectural problem in Python and pip. That said, dependency hell is always tricky, and I've had to deal with some far uglier solutions in other platforms.

you aren't implying that dependency hell is a problem unique to python/pip are you?

dealing with dependencies is always step 2 for me when learning a new language and dependency hell seems like a universal problem. I could be wrong though.

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

#29

Some of the mentioned problems with the traditional method are partially solved with `pip install requests --user` but I understand that the bigger problem/main reason for virtualenv isn't helped by this. However, I was very surprised that the author didn't mention venv ( http://docs.python.org/3.3/library/venv.html ) at all since it is basically virtualenv but part of the Python standard library.

i tried pyvenv last week. and it was pretty useless without pip + distribute. So virtualenv still wins IMO.
Post reply on HN