为什么我只能在具有管理员权限的情况下在Python中导入某些模块? [英] Why can I import certain modules in Python only with administrator rights?

查看:306
本文介绍了为什么我只能在具有管理员权限的情况下在Python中导入某些模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python 2.7中遇到一些奇怪的问题.我写了一个很长的工具,用于导入不同的模块,必须先使用 pip 安装.该工具将在公司内部共享,其中不同的用户在其特定计算机上拥有不同的权限. 当另一个用户登录到我的计算机(我在那里拥有管理员权限)并尝试使用该工具时,发生了问题.他无法运行它,因为由于其为非管理员"身份而无法导入特定的模块.

I'm struggling with some strange issues in Python 2.7. I wrote a very long tool where I import different modules, which I had to install first using pip. The tool is to be shared within the company, where different users have different rights on their specific machines. The problem occurred when another user logged into my machine (I'm having administrator rights there) and tried to use the tool. He was unable to run it, because specific modules could not be imported because of his status as a "non-admin".

错误消息只是没有名为XY的模块". 当我们查看文件系统时,我们发现我们无法查看模块安装目录,这仅仅是因为系统拒绝了访问. 当尝试从 cmd 运行 pip 时,我们也收到此错误消息;它会显示访问被拒绝",并且不会执行任何操作.

The error message is simply "No module named XY". When we looked into the file system, we found that we were not able to look into the folder where the module had been installed, simply because the access was denied by the system. We also got this error message when trying to run pip from the cmd; it prints "Access denied" and won't do anything.

怎么可能某些模块可以被任何人访问,而另一些模块则不能?我该如何解决这个问题?

How is it possible, that some modules can be accessed by anyone, while others can't? And how can I get around this problem?

具体地说,我说的是 sqlalchemy pyodbc .

Specifically, I'm talking about sqlalchemy and pyodbc.

非常感谢.

编辑1 :哦,我们在这里谈论的是Windows,而不是Linux ...

EDIT 1: Oh, and we're talking about Windows here, not Linux...

编辑2 :由于公司政策的原因,无法为所有用户设置管理员权限.我按照建议进行了尝试,但没有成功,我了解到在公司内部这是不可能的.

EDIT 2: Due to company policy it is not possible to set administrator permissions to all users. I tried, as suggested, but it didn't work and I learned that it's not possible within the company.

推荐答案

知道了...

按照Nabeel Ahmed的建议,我首先从管理员帐户中卸载了导致问题的软件包.然后我将脚本更改为

Following the advice of Nabeel Ahmed, I first uninstalled the packages which caused the issues from my admin account. Then I changed the script to

pip install --user {module_name}

瞧,它现在适用于所有用户.

and voila... it works for all users now.

非常感谢您的帮助,伙计们!

Thanks a lot for you help, guys!

这篇关于为什么我只能在具有管理员权限的情况下在Python中导入某些模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆