Permission errors on Windows when installing new modules
Since the 3.2.8 I am experiencing some weird PermissionErrors on Windows when trying to install packages through the Python Package Manager. For instance, I tried to install the package Faker.
When attempting to install this via the GUI of the PPM, a notification shows up that the installation failed.
When trying to install the module via pip.main(['install','Faker']), the following is output to the debug window:
In [8]: pip.main(['install','Faker'])
Collecting Faker
Using cached https://files.pythonhosted.org/packages/44/ae/1dc34e68b968a154ddf109c33489c17a415857fb3e39002c07f4dbb7af5a/Faker-2.0.0-py2.py3-none-any.whl
Collecting text-unidecode==1.2 (from Faker)
Using cached https://files.pythonhosted.org/packages/79/42/d717cc2b4520fb09e45b344b1b0b4e81aa672001dd128c180fabc655c341/text_unidecode-1.2-py2.py3-none-any.whl
Collecting ipaddress; python_version < "3.3" (from Faker)
Using cached https://files.pythonhosted.org/packages/fc/d0/7fc3a811e011d4b388be48a0e381db8d990042df54aa4ef4599a31d39853/ipaddress-1.0.22-py2.py3-none-any.whl
Requirement already satisfied: six>=1.10 in c:\program files (x86)\opensesame\lib\site-packages (from Faker)
Requirement already satisfied: python-dateutil>=2.4 in c:\program files (x86)\opensesame\lib\site-packages (from Faker)
Installing collected packages: text-unidecode, ipaddress, Faker
Exception:
Traceback (most recent call last):
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\pip\req\req_set.py", line 784, in install
**kwargs
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\pip\req\req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\pip\req\req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\pip\wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\pip\wheel.py", line 316, in clobber
ensure_dir(destdir)
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\pip\utils\__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "C:\Program Files (x86)\OpenSesame\lib\os.py", line 157, in makedirs
mkdir(name, mode)
WindowsError: [Error 5] Access is denied: 'C:\\Program Files (x86)\\OpenSesame\\Lib\\site-packages\\text_unidecode'
The installation does succeed when OpenSesame is run in elevated mode (e.g. as an Administrator). Any idea what causes this?
This is simply due to the fact of OpenSesame not having write permission in its own folder, unless it's run as Administrator. That's one of the many things that's not ideal about the Python package manager.
What happens if you install it locally? If that works, perhaps that should be the default behavior.
pip.main(['install','Faker', '--user']
PS. The package manager lives in https://github.com/smathot/python-qtpip
I expected the first one to be the case. However, I once went as far as reinstalling OpenSesame to Program Files, and tried again afterwards to install a package with qt-pip and then it worked. It seems that the permission 'lock-up' happens some period after the installation. Additionally, on my main PC this problem occurs, while on a Windows laptop on which I tested this too it didn't. I also suspect virus scanners being the culprit here.
This is also related to the problem that Simona described some time ago about OpenSesame not running on some (but not all) of their lab PCs. These were also permission-related errors.
I understand that there is little you can do about this, as this is all up to the OS on which OpenSesame needs to run. Still it's good to keep an eye out for the ways these permission error manifest themselves on various systems.
Oh! And I'll try again using the --user flag. I think that is the recommended way of installing pip packages now anyway, although they may end up outside of the OpenSesame folder when installed like that.
Installing with the --user flag gives no errors, but the package does not get picked up by OpenSesame. If you try to import the installed package afterwards, it says it hasn't been installed.