6

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.

Shang Wang
  • 24,909
  • 20
  • 73
  • 94

2 Answers2

12

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
William
  • 2,695
  • 1
  • 21
  • 33
  • That's some progress, at least it created something. But how can I install the `pip` locally? – Shang Wang Jan 21 '16 at 17:13
  • See https://pypi.python.org/pypi/virtualenv/1.7.2 section "The --extra-search-dir Option"... I also updated the answer – William Jan 21 '16 at 17:22
  • Sounds promising. Is there an easy way to grab all .egg files? – Shang Wang Jan 21 '16 at 18:18
  • For setuptools you can use the URL you posted in the error log (http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg) – William Jan 21 '16 at 18:22
  • I've already had that. I meant other python packages that I also tried to install. – Shang Wang Jan 21 '16 at 18:23
  • Once you have setuptools, you don't need eggs anymore. You can just download the archives, extract it, cd into it, and then run `python setup.py install` :) – William Jan 21 '16 at 18:25
-1
mkdir .mypypi  
pip install --download $HOME/.mypypi ipython ipdb django  

Now transfer the contents from .mypypi to your server. Let's say you copied it to your $HOME Then do this:

pip install --no-index --find-links=file:/$HOME/.mypypi ipython

This should work for requirements.txt file too.

masnun
  • 11,635
  • 4
  • 39
  • 50