Install Virtualenv without internet connectivity

2019-09-12 04:23发布

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 ?

1条回答
做个烂人
2楼-- · 2019-09-12 04:53

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.

查看更多
登录 后发表回答