[英]python3 package cannot be imported as non-root user
I'm trying to import a python3 module using pip3 as root user.我正在尝试以 root 用户身份使用 pip3 导入 python3 模块。 I could import the same installed python3 module as root user.
我可以以 root 用户身份导入相同的已安装 python3 模块。 Now when I try to import that module after exiting from sudo and as normal user, I cannot import it.
现在,当我退出 sudo 并以普通用户身份尝试导入该模块时,我无法导入它。 I added the PYTHONPATH variable with installed module path.
我添加了带有已安装模块路径的 PYTHONPATH 变量。 Still I could not figure out the issue.
我仍然无法弄清楚这个问题。
Basically I need the installed python3 library to be used by any user who logs in to the machine.基本上我需要安装的 python3 库供任何登录机器的用户使用。
[root@mymachine /home/user]
pip3 install kubernetes
The command was successsful as you can see below:命令成功,如下所示:
[root@mymachine /home/user]
python3 -c "import kubernetes"
Now I exited from root user and got logged in as "user" and tried to import kube.netes
here.现在我从 root 用户退出并以“用户”身份登录并尝试在此处
import kube.netes
。 It failed.它失败了。
[user@mymachine]
$ python3 -c "import kubernetes"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'kubernetes'
It seems you have a file permission issue.看来您有文件权限问题。 try uninstall the package, make sure
umask
is 022
and reinstall it with root
user or via sudo
again.尝试卸载 package,确保
umask
为022
,然后使用root
用户或再次通过sudo
重新安装。 something like:就像是:
sudo pip uninstall kubernetes
umask 022
sudo pip install kubernetes
as user
run:作为
user
运行:
python3 -m pip install kubernetes
and then try running your code again然后再次尝试运行您的代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.