What should I do if I can import a module when I run python, but not when I run sudo python?
For example:
whoami
rose
python
>>> import mymodule
>>>
.
sudo python
>>> import mymodule
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mymodule
I had run sudo chown -R rose:rose on the package containing this module.
sudo which python and which python both print /usr/bin/python.
I'm running Linux.
$PYTHONPATHis different, or not even set, for your root user. - Code-Apprentice$PYTHONPATH, butecho $PYTHONPATHandsudo echo $PYTHONPATHprint the same thing. - Rose Perronesudothe environment variables are the same. That is for linux, and only if the command is run from the same shell process. - MrAliasDefaults env_keep += "PYTHONPATH"to/etc/sudoersand now it works. - Rose Perrone