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?
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.
Simply copy the folder related to the virtal environment to your other computer or sync the folder using rsyncd to avoid having several different versions. The virtual environment folders can be found in ~/. virtualenvs on a standard Ubuntu installation.
virtualenv is a tool for creating isolated Python environments containing their own copy of python , pip , and their own place to keep libraries installed from PyPI. It's designed to allow you to work on multiple projects with different dependencies at the same time on the same machine.
To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With