问题
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".
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?
Specifically, I'm talking about sqlalchemy and pyodbc.
Thanks a lot in advance.
EDIT 1: Oh, and we're talking about Windows here, not Linux...
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.
回答1:
Got it...
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!
回答2:
You should either use virtualenv as stated before or set the proper permissions to the site-packages
folder. I should be in C:\Python27\Lib
.
回答3:
One simply solution is set permissions for site-package directory (where the packages gt installed) as per usable by all i.e. read and execute permission for all on the directory:
sudo chmod -Rv ugo+rX /usr/lib/python2.7/site-packages/
Also for the lib64
packages - the path to site-packages
may vary for various Linux distros.
Edit 1: For windows look into this 'File and Folder Permissions' for setting Read & Execute permissions for all, for a file or folder (i.e. site-packges)
The path 'd be - C:\Python27\Lib\site-packages
Edit 2: in apropos of:
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.
if so, simply install sqlalchemy (or any other package) for specific user using pip
:
pip install --user {module_name}
Source: Per user site-packages directory.
来源:https://stackoverflow.com/questions/41240754/why-can-i-import-certain-modules-in-python-only-with-administrator-rights