0

I need to set up a lab environment where the audience may not necessarily have internet connectivity at the venue. There are just a few packages that I need to explain to the audience.

I am trying to make use of virtualenv to do all this. So using pip install I have successfully been able to install virtualenv. After this I activate my virtual env. And then while in there I use pip install again to install the other required modules, like requests etc.

Now since my audience may not have internet connectivity during the training, I want to be able to distribute my virtualenv to them, so that they have a fully working environment and they can just get started with the main content of the training.

I am not sure how to distribute my virtualenv to others. From what I understand, I can do

pip freeze > requirements.txt

and then

pip install -r requirements.txt

But the latter above will also need to be done from within a virtualenv to work. Please correct me if I am wrong.

So I tried writing a python script that would automate all of this stuff and given the internet connectivity issue, in my automated script I can not use pip install to install virtualenv. Hence I am instead using setup.py to install virtualenv.

Below is my attempt at the script (which does not work)

import os
import shutil
import sys
from os.path import expanduser
from os.path import join

home = expanduser("~")
newpath = join(home,"newFolder")
print newpath
if not os.path.exists(newpath):
    os.makedirs(newpath)

cwd = os.path.dirname(os.path.abspath(__file__))
print cwd
#virtenv = join(cwd,'virtualenv-13.1.2')
#print virtenv
setupFile = join(cwd,'setup.py')
string = sys.executable + " " + setupFile + " install"
print string
os.system(string)
# isntalling dependencies
string = "pip install -r requirements.txt"
os.system(string)

The idea is - when the user runs the above script (without any internet), there should be a virtualenv set up in a new folder under his home directory. And then inside that virtual env the script should run pip install -r requirements.txt to install all the required modules.

So far the above script does not do what's needed. And I have placed the above script in the same dir as virtualenv setup files.

Am I even thinking straight ? How can I achieve this ?

qre0ct
  • 5,680
  • 10
  • 50
  • 86

1 Answers1

0

I'm pretty sure that what you want to do is to establish your own simple repository with the packages you want to distribute by running a web server on your computer, and then adding your server as a repository to people attending your event - allowing them to access your repository on the local network using a command like:

pip install --extra-index-url https://IP_ADDRESS_OF_YOUR_SERVER/ yourappname

This page has a pretty good guide on how to set that all up.

Zany Cadence
  • 219
  • 2
  • 6
  • yes that's correct. But is there another way of doing it except the above....somewhat in the direction i was trying to proceed ? – qre0ct Nov 07 '15 at 02:19
  • 1
    Yes, set your local repository to have all of the packages you need including virtualenv and the output from `pip freeze > requirements.txt`. Then create a shell script with `pip install --extra-index-url https://YOUR_SERVER/` for both the virtualenv and the requirements for your project. It's almost always easier to run (relatively) simple commands like this in a shell script than an overly complicated python script, but you could also append the flag specifying the location of your simple repository to the commands in your python script. – Zany Cadence Nov 07 '15 at 02:29
  • another question is, what's wrong with my approach above ? Can't setup.py be used instead of pip to install virtualenv ? – qre0ct Nov 07 '15 at 02:47
  • There's nothing wrong with installing virtualenv via setup.py - but if you're going to host your own repo for the requirements to be installed via pip, why wouldn't you add virtualenv to the repo and install it via pip? – Zany Cadence Nov 07 '15 at 02:55
  • sure that makes sense. But I was just curious as to why would the setup.py approach cause any problems. – qre0ct Nov 07 '15 at 03:01
  • Try your script without the last bit trying to install the requirements - does it install virtualenv? Is it being run sudo? I wasn't sure earlier, but on rereading, even if virtualenv successfully installed via setup.py - you don't create a virtualenv with a command like `virtualenv myappenv` and you don't activate it - which you'll want to do before running pip for the requirements. I just went through something similar a couple weeks ago and know that a repo w/pip and a shell script (or clear instructions for windows users) works. Best of luck, – Zany Cadence Nov 07 '15 at 03:13