sudo not using $PYTHONPATH

I’ve come across this problem before, but today I was trying to install some Python packages after downloading the newest version of STSCI_PYTHON. Using easy_install requires root access to write the install files, so one would have to use, for example:

sudo easy_install pip

I got an error like ImportError: No module named pkg_resources, which resulted from the fact that the “sudo” account wasn’t using the PYTHONPATH that was setup in the ~/.bashrc file. You could see this by running:

sudo python
>>> import os
>>> os.getenv('PYTHONPATH')
()

I found a fix for this here:

Edit /etc/sudoers (with sudo) to add the following line:

Defaults env_keep += "PYTHONPATH"

Now the PYTHONPATH variable should be preserved when you invoke sudo and sudo easy_install ... should work.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s