Pythonpath Not Working For Sudo on Gnu/Linux (Works For Root)

PYTHONPATH not working for sudo on GNU/Linux (works for root)

The fix in my case was to remove Defaults !env_reset from sudoers.

But, I had to keep Defaults env_keep += "PYTHONPATH" in sudoers.

I've actually added Defaults env_reset (which resets environment variables), but it still works because of env_keep.

It seems that env_keep and !env_reset conflict with eachother, but that's just a guess.


So, the whole process:

  1. add export PYTHONPATH=/your/custom/path to ~/.bashrc or /etc/bash.bashrc
  2. add PYTHONPATH to Defaults env_keep += "ENV1 ENV2 ..." in sudoers file
  3. remove Defaults !env_reset from sudoers file if present

ImportError: No module named pyaudio with sudo

I just used sudo su to gain root access and everything worked fine.

Permanently add a directory to PYTHONPATH?

You need to add your new directory to the environment variable PYTHONPATH, separated by a colon from previous contents thereof. In any form of Unix, you can do that in a startup script appropriate to whatever shell you're using (.profile or whatever, depending on your favorite shell) with a command which, again, depends on the shell in question; in Windows, you can do it through the system GUI for the purpose.

superuser.com may be a better place to ask further, i.e. for more details if you need specifics about how to enrich an environment variable in your chosen platform and shell, since it's not really a programming question per se.

Python 'keyboard' module working as non-root but not working in sudo (linux)

Try running the following command and see if it helps.

sudo python3 -m pip install keyboard

Unable to import a module that is definitely installed

In my case, it is permission problem. The package was somehow installed with root rw permission only, other user just cannot rw to it!



Related Topics



Leave a reply



Submit