Live data from Hacker News

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

dabapps.com

81–86 of 86 posts

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

#81
post #3

a good introduction - I would like to hear more about deployment with virtualenv though - is it expected that you just document any packages with requirements.txt and then you would create the virtualenv in the deployment target and set everything up again? Or can you "package" a virtualenv for deployment?

Deployment/distribution can be handled by bundling the app. For Python 2.x, there's PyInstaller[0], Py2App[1], Py2Exe[2] all of which do much the same thing: make a single binary out of a python app and all its dependencies including the interpreter. Then you distribute that and don't worry about what the user has or hasn't got.

[0]http://www.pyinstaller.org/ [1]https://pypi.python.org/pypi/py2app/ [2]https://pypi.python.org/pypi/py2exe/0.6.9

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

#82
post #73
post #61

Earlier quoted context omitted.

I use Windows as my main OS, and by default npm -g installs packages to %AppData%, which is user-specific. I guess it's different on *nix, then.

That sounds broken to me. Then it's no longer -g for global. You do run your app under a different account than your user-account, right? Something like "nodeuser"?

>You do run your app under a different account

No, why would I do something like that on a development box? (Or run web stuff on Windows servers for that matter.) And pretty much the only things I install with -g are useful CLI tools - any code I write will have its dependencies installed locally and listed in package.json for 'npm install'.

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

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

Are you trolling? The primary use case of npm is quite different. No one installs system-wide npm packages. Virtualenv solves a different problem (create a complete Python environment inside a directory) so you can replicate the various production setups in your machine and develop. It's not a way to avoid admin-privileges to install system software, for that you can just pip install --user, use homebrew, whatever.

>Virtualenv solves a different problem

Based on the article I'd say the main reason to use it is so that you can have what amounts to local packages instead of having to rely on global packages (be they system-wide or user-specific). This is what npm does by default - packages are installed locally to node_modules.

And for replicating production setups I'd rather take it a step further and use something like Vagrant instead of replicating just one part of the setup (Python).

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

#84
post #82
post #73

Earlier quoted context omitted.

That sounds broken to me. Then it's no longer -g for global. You do run your app under a different account than your user-account, right? Something like "nodeuser"?

>You do run your app under a different account No, why would I do something like that on a development box? (Or run web stuff on Windows servers for that matter.) And pretty much the only things I install with -g are useful CLI tools - any code I write will have its dependencies installed locally and listed in package.json for 'npm install'.

It wasn't clear (to me) that this was a development box. And it certainly wasn't something npm could know -- so my point still stands. If there's a way to install packages globally, then they should be globally available -- also on windows. But perhaps this is documented somewhere.

As for why you would run stuff on windows, perhaps you were writing an ajax gateway to a legacy system and it made more sense to run the node server on the same machine as the legacy system?

(To be clear, I would pity you if that was the case, but you never know ;-)

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

#86
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.

java does not have virtual envs, and i can have projects with different dependancies. clearly this is a python problem. I was asking why it exists.
Post reply on HN