pleiszenburg / zugbruecke

Calling routines in Windows DLLs from Python scripts running under Linux, MacOS or BSD
https://zugbruecke.readthedocs.io/en/latest/
GNU Lesser General Public License v2.1
108 stars 11 forks source link

Permission Error #89

Closed hunkus closed 1 year ago

hunkus commented 1 year ago

Currently, I am using the latest image(September 22nd 2022) on Raspberry Pi 4B. After installing the latest version(0.1.0) and running the example code as shown below, the following error message appears.

I installed it using pip, is there anything else I need to configure? However, the older version(0.0.15) is working fine in the current environment.

import zugbruecke.ctypes as ctypes
dll_pow = ctypes.cdll.msvcrt.pow
dll_pow.argtypes = (ctypes.c_double, ctypes.c_double)
dll_pow.restype = ctypes.c_double
print(f'You should expect "1024.0" to show up here: "{dll_pow(2.0, 10.0):.1f}".')

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.9/dist-packages/zugbruecke/ctypes/init.py", line 44, in _session = _CtypesSession() File "/usr/local/lib/python3.9/dist-packages/zugbruecke/core/session.py", line 129, in init self._current_session = SessionClient(config=Config(**kwargs)) File "/usr/local/lib/python3.9/dist-packages/zugbruecke/core/session_client.py", line 117, in init env.ensure() File "/usr/local/lib/python3.9/dist-packages/wenv/_core/env.py", line 233, in ensure self.setup_wineprefix() File "/usr/local/lib/python3.9/dist-packages/wenv/_core/env.py", line 343, in setup_wineprefix os.makedirs( File "/usr/lib/python3.9/os.py", line 225, in makedirs mkdir(name, mode) PermissionError: [Errno 13] Permission denied: '/usr/share/wenv/win32'

s-m-e commented 1 year ago

You likely installed zugbruecke system-wide, e.g. with sudo (sudo pip install zugbruecke). As a result, zugbruecke tries to place its Wine prefix under /usr/share/wenv/win32 where your user account likely does not have write permissions.

There are at least two ways forward.

1) You can install zugbruecke into a virtual environment where your user has full write permissions, e.g.

python -m venv env
source env/bin/activate
pip install zugbruecke

2) You can instead leave zugbruecke where it is and tell it to place its Wine prefix somewhere else. zugbruecke delegates this task to a separate package called wenv, which can be told where to put the Wine prefix. One option is to do this via a environment variable when starting the Python interpreter:

WENV_WINEPREFIX=/home/user/some/folder python

Alternatively, the Wine prefix path can also be set at runtime by manually initializing a session as follows:

from zugbruecke import CtypesSession
ctypes = CtypesSession(wineprefix = '/home/user/some/folder')
s-m-e commented 1 year ago

However, the older version(0.0.15) is working fine in the current environment.

Yes, the mechanism for creating and managing Wine prefixes was changed from 0.0.15 to 0.1.0. Before, they were automatically placed under /home/user/.zugbruecke. Unfortunately, this created it own set of issues, so now, the default location is {sys.prefix}/share/. As in your case, this can result in problems if the package is installed system-wide, i.e. {sys.prefix} == '/usr'.

s-m-e commented 1 year ago

Can this issue be marked as resolved?

hunkus commented 1 year ago

Can this issue be marked as resolved?

Thank you, your kind and detailed answer helped me a lot.