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:
- add
export PYTHONPATH=/your/custom/path
to~/.bashrc
or/etc/bash.bashrc
- add
PYTHONPATH
toDefaults env_keep += "ENV1 ENV2 ..."
in sudoers file - 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
Converting Epoch Time With Milliseconds to Datetime
How to Detect Collision in Pygame
Actual Meaning of 'Shell=True' in Subprocess
How to Get Keyboard Input in Pygame
How to Concatenate Str and Int Objects
What Are Type Hints in Python 3.5
Why Can a Function Modify Some Arguments as Perceived by the Caller, But Not Others
Why Does Concatenation of Dataframes Get Exponentially Slower
In Python Script, How to Set Pythonpath
Integer Division by Negative Number
What Is the 'Self' Parameter in Class Methods
Input() Error - Nameerror: Name '...' Is Not Defined
Why Doesn't Calling a String Method Do Anything Unless Its Output Is Assigned
A Non-Blocking Read on a Subprocess.Pipe in Python