Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: How to create virtualenv without internet connection

I have trouble creating a virtualenv on a server that blocks all internet access. Has anybody successfully done that before? I searched but doesn't show up anything helpful. I have no problem transferring data back and forth, but I don't know what packages need to be downloaded and what options I need to have for the installation.

If you are curious what I got by trying to create one, here's the backtrace:

netops@netops1 /spare/local/latency $virtualenv -p /usr/bin/python2.6 latency
Running virtualenv with interpreter /usr/bin/python2.6
New python executable in latency/bin/python2.6
Also creating executable in latency/bin/python
Installing setuptools.....................
  Complete output from command /spare/local/latency/latency/bin/python2.6 -c "#!python
\"\"\"Bootstra...sys.argv[1:])






" --always-copy -U setuptools:
  Downloading http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg
Traceback (most recent call last):
  File "<string>", line 279, in <module>
  File "<string>", line 211, in main
  File "<string>", line 159, in download_setuptools
  File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib64/python2.6/urllib2.py", line 391, in open
    response = self._open(req, data)
  File "/usr/lib64/python2.6/urllib2.py", line 409, in _open
    '_open', req)
  File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.6/urllib2.py", line 1181, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib64/python2.6/urllib2.py", line 1156, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 110] Connection timed out>

Thanks for any help.

like image 586
Shang Wang Avatar asked Jan 21 '16 16:01

Shang Wang


1 Answers

If you update virtualenv to a version >= 1.10, then it will never connect to the internet regardless of any flag (see the "Changes & News" section here)


The internet connection is used to install the setuptools and pip packages in the virtual environment. Older versions of virtualenv will try to download these two packages, while newer versions ship with them and will just unpack them when necessary.

Since your virtualenv version (1.7.2) is lower than 1.10, you can use the --never-download flag in order to avoid connecting to the internet. Later on, you can install (offline) what you need.

Here (section "The --extra-search-dir Option") it's explained how to bootstrap setuptools and pip without an internet connection. You basically need to get the .egg files for these packages and put them somewhere local, and then you need to do:

$ virtualenv --extra-search-dir=/path/to/eggs --never-download ENV
like image 194
William Avatar answered Nov 12 '22 19:11

William