Hacker News new | ask | show | jobs
by bdarnell 3207 days ago
You can use virtualenv without `bin/activate`. Just refer to `bin/python` (and other scripts in `bin/`) explicitly. Don't bring in the magic until you need it. And when you need it, consider what kind of magic you need. If you're typing `bin/` too much, do you need something that adds `bin/` to your path, or do you need to write a script for this task that saves you from having to type both `bin/` and a bunch of other command-line flags?

(I do add my virtualenv's `bin/` directory to my path, but mainly so my editor can find the right tools, so I do it from elisp instead of bin/activate in a shell)

1 comments

How do you manage dependencies? One of the best parts about virtualenv (to me at least) is that I can do pip install without infecting the rest of the system.

I guess I've never looked, does virtualenv provides a bin/pip which already knows the path of the virtualenv? Does the bin/python in there come with a path that uses the project pip install?

There is a bin/pip you could call directly and have it install packages to the correct path. Even commands installed from packages work that way.

I would only use 'bin/python' directly from scripts called from cron, or other similar places.

./venv/bin/pip install package

Best part is you can't accidentally install a package in the wrong venv this way.

I hate modal systems...

Yes, exactly. bin/pip inside the virtualenv installs into that virtualenv.