Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm running Ubuntu Server 10.04 64-bit under VirtualBox, and it seems that everything except easy_install and pip can connect to the Internet. I have set and exported the http_proxy environment variable, and also set up the proxy address in every other location I'm aware of. Yet easy_install always returns "Network is unreachable":

:~$ echo $http_proxy
http://192.168.1.25:80/

:~$ grep "http_proxy" /etc/bash.bashrc
export http_proxy=http://192.168.1.25:80/

:~$ grep "http_proxy" /etc/wgetrc
http_proxy = http://192.168.1.25:80/

:~$ ping pypi.python.org
PING pypi.python.org (82.94.164.168) 56(84) bytes of data.
64 bytes from pypi.python.org (82.94.164.168): icmp_seq=1 ttl=53 time=114 ms
64 bytes from pypi.python.org (82.94.164.168): icmp_seq=2 ttl=53 time=113 ms
64 bytes from pypi.python.org (82.94.164.168): icmp_seq=3 ttl=53 time=113 ms
64 bytes from pypi.python.org (82.94.164.168): icmp_seq=4 ttl=53 time=113 ms
64 bytes from pypi.python.org (82.94.164.168): icmp_seq=5 ttl=53 time=114 ms
64 bytes from pypi.python.org (82.94.164.168): icmp_seq=6 ttl=53 time=113 ms
^C
--- pypi.python.org ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5006ms
rtt min/avg/max/mdev = 113.367/113.871/114.678/0.614 ms

:~$ sudo easy_install virtualenv
Searching for virtualenv
Reading http://pypi.python.org/simple/virtualenv/
Download error: [Errno 101] Network is unreachable -- Some packages may not be found!
Reading http://pypi.python.org/simple/virtualenv/
^Cinterrupted
:~$

I can even connect to the site from within Python:

>>> import urllib
>>> obj = urllib.urlopen('http://pypi.python.org/simple/virtualenv/')
>>> obj.readlines()[0]
'<html><head><title>Links for virtualenv</title></head><body><h1>Links for virtualenv</h1><a href="../../packages/source/v/virtualenv/virtualenv-1.5.1.tar.gz#md5=3daa1f449d5d2ee03099484cecb1c2b7">virtualenv-1.5.1.tar.gz</a><br/>\n'

I have had the same result with packages other than virtualenv. Is easy_install looking somewhere else for connection information, or is there something obvious I'm missing?

share|improve this question
add comment

2 Answers

up vote 24 down vote accepted

It's a problem with sudo. If you use sudo, the variable $http_proxy is unknown in this context.

sudo -i opens up a root shell. There you can set the $http_proxy variable again and then easy_install works - you don't have to use sudo because you are already superuser.

$ sudo -i
# export http_proxy=http://192.168.1.25:80
# easy_install virtualenv

Or you can have your actual environment in sudo context and save the "get root step" via:

$ sudo -E easy_install virtualenv
share|improve this answer
1  
Thank you. Figures that I forget about things like scope when I'm not programming. I must have set up http_proxy in /etc/environment on the other installations where I had no problem. –  robots.jpg May 17 '11 at 20:33
    
Thanks. You saved me some irritation! –  Dilawar Feb 15 '12 at 14:20
add comment

Rather than opening up a root shell with sudo -i you can run the command

$ sudo -E easy_install virtualenv

The -E switch preserves your current environment.

share|improve this answer
    
Another gotcha is that some sudo-like replacements (e.g. dzdo) refuse to preserve these variables even if you tell them to. –  Sam Brightman Sep 14 '11 at 16:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.