Install Virtualenv without internet connectivity

旧城冷巷雨未停 提交于 2019-12-12 06:23:51

问题


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:


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.



来源:https://stackoverflow.com/questions/33577225/install-virtualenv-without-internet-connectivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!