views:

82

answers:

3

I have virtualenv and virtualenvwrapper installed on a shared Linux server with default settings (virtualenvs are in ~/.virtualenvs). I have several Python scripts that can only be run when the correct virtualenv is activated.

Now I want to share those scripts with other users on the server, but without requiring them to know anything about virtualenv... so they can run python scriptname or ./scriptname and the script will run with the libraries available in my virtualenv.

What's the cleanest way to do this? I've toyed with a few options (like changing the shebang line to point at the virtualenv provided interpreter), but they seem quite inflexible. Any suggestions?

Thanks,

Marco


Edit: This is a development server where several other people have accounts. However, none of them are Python programmers (I'm currently trying to convert them). I just want to make it easy for them to run these scripts and possibly inspect their logic, without exposing non-Pythonistas to environment details. Thanks.

+3  A: 

I would vote for adding a shebang line in scriptname pointing to the correct virtualenv python. You just tell your users the full path to scriptname (or put it in their PATH), and they don't even need to know it is a Python script.

If your users are programmers, then I don't see why you wouldn't want them to know/learn about virtualenv.

Heikki Toivonen
Actually, I think I agree with this second paragraph. Virtualenv is an awesome tool. If you're trying to convert other programmers, show it to them. It's easy to use, and it does cool things.
jcdyer
+2  A: 

If it's only on one server, then flexibility is irrelevant. Modify the shebang. If you're worried about that, make a packaged, installed copy on the dev server that doesn't use the virtualenv. Once it's out of develepment, whether that's for local users or users in guatemala, virtualenv is no longer the right tool.

jcdyer
+1  A: 

Use the following magic(5) at the start of the script.

'#!/usr/bin/env python'

Change which virtualenv is active and it'll use the python from that virtualenv. Deactivate the virtualenv, it still runs.

Chris Dukes