Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip does not honor PIP_INDEX_URL with sudo

According to the doc I can direct pip to use my private pypi repository instead of the official one:

For pip this can be done by setting the environment variable PIP_INDEX_URL in your .bashrc/.profile/.zshrc:
export PIP_INDEX_URL=http://localhost:8080/simple/

So I added my private repository(e.g., http://pypi.mycompany.com/simple ) into /etc/profile on my Debian server. However pip still raises error:

john@server:~$ sudo pip install ipython
Downloading ...
    Cannot fetch index base URL https://pypi.python.org/simple/
    ...

Looks like pip ignores the environment variable PIP_INDEX_URL I've set. Why?

Update:

Following @Ivo's direction, I found my Python didn't see the variable at all:

john@server:~$ sudo python -c "import os; print(os.getenv('PIP_INDEX_URL'))"
None
like image 300
John Wang Avatar asked Jun 10 '14 08:06

John Wang


1 Answers

Found it. It's simple: sudo by default will not use the environment variables for security reasons. To tell sudo preserve env variables, -E option can be used, e.g.

sudo -E pip install ipython
like image 166
John Wang Avatar answered Sep 23 '22 14:09

John Wang