Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wenv init reports ModuleNotFoundError: No module named '_socket' #18

Open
nukemiko opened this issue Dec 16, 2022 · 4 comments
Open

wenv init reports ModuleNotFoundError: No module named '_socket' #18

nukemiko opened this issue Dec 16, 2022 · 4 comments
Labels

Comments

@nukemiko
Copy link

OS: Arch Linux
WINE version: wine-7.22 (Staging)
wenv version: 0.4.1
No WINEPREFIX settings.

$ > wenv init
Traceback (most recent call last):
  File "<stdin>", line 32207, in <module>
  File "<stdin>", line 135, in main
  File "<stdin>", line 111, in bootstrap
  File "<stdin>", line 92, in monkeypatch_for_cert
  File "C:\users\miketsu\Temp\tmp1imro7nl\pip.zip\pip\_internal\commands\__init__.py", line 9, in <module>
  File "C:\users\miketsu\Temp\tmp1imro7nl\pip.zip\pip\_internal\cli\base_command.py", line 5, in <module>
  File "D:\obj\windows-release\37win32_Release\msi_python\zip_win32\config.py", line 30, in <module>
  File "D:\obj\windows-release\37win32_Release\msi_python\zip_win32\handlers.py", line 26, in <module>
  File "D:\obj\windows-release\37win32_Release\msi_python\zip_win32\socket.py", line 49, in <module>
ModuleNotFoundError: No module named '_socket'
@N-Coder
Copy link

N-Coder commented Jan 1, 2023

This message comes from the get-pip.py installer failing. Note that the command still returns successfully, so wenv python will be useable, but wenv pip unfortunately not. Also, the python installation is not fully useable, as the socket module cannot be imported (which also causes the pip installation to fail):

$ wenv python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import _socket
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named '_socket'

This is weird as the _socket.pyd file in .venv/share/wenv/win32/drive_c/python-3.7.4.stable/ (Z:\tmp\wenv-6a8e72be in the wine env) is on PYTHONPATH and can be loaded when giving the path explicitly:

>>> import sys, os
>>> print(sys.path)
['', 'Z:\\tmp\\wenv-6a8e72be\\Lib', 'Z:\\tmp\\wenv-6a8e72be', 'Z:\\tmp\\wenv-6a8e72be\\lib\\site-packages']
>>> os.listdir(sys.path[2])
['Lib', 'libcrypto-1_1.dll', 'libssl-1_1.dll', 'LICENSE.txt', 'pyexpat.pyd', 'python.exe', 'python3.dll', 'python37.dll', 'python37._pth', 'python37._pth.backup', 'pythonw.exe', 'select.pyd', 'sqlite3.dll', 'unicodedata.pyd', 'vcruntime14
0.dll', 'winsound.pyd', '_asyncio.pyd', '_bz2.pyd', '_ctypes.pyd', '_decimal.pyd', '_elementtree.pyd', '_hashlib.pyd', '_lzma.pyd', '_msi.pyd', '_multiprocessing.pyd', '_overlapped.pyd', '_queue.pyd', '_socket.pyd', '_sqlite3.pyd', '_ssl.
pyd']
>>> import importlib.util
>>> s = importlib.util.spec_from_file_location("_socket", "Z:\\tmp\\wenv-6a8e72be\\_socket.pyd")
>>> importlib.util.module_from_spec(s)
<module '_socket' from 'Z:\\tmp\\wenv-6a8e72be\\_socket.pyd'>
>>> import _socket
>>> # success

The reason why the automatic finding doesn't work seems to be that this directory can only be stated when appending a backslash...

>>> sys.path_importer_cache
{'Z:\\tmp\\wenv-6a8e72be\\Lib': FileFinder('Z:\\tmp\\wenv-6a8e72be\\Lib'), 'Z:\\tmp\\wenv-6a8e72be\\Lib\\encodings': FileFinder('Z:\\tmp\\wenv-6a8e72be\\Lib\\encodings'), 'Z:\\tmp\\wenv-6a8e72be': None, 'Z:\\tmp\\wenv-6a8e72be\\lib\\site-
packages': FileFinder('Z:\\tmp\\wenv-6a8e72be\\lib\\site-packages')}
>>> sys.path_hooks
[<class 'zipimport.zipimporter'>, <function FileFinder.path_hook.<locals>.path_hook_for_FileFinder at 0x0166F858>]
>>> sys.path_hooks[1]('Z:\\tmp\\wenv-6a8e72be')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen importlib._bootstrap_external>", line 1448, in path_hook_for_FileFinder
ImportError: only directories are supported
>>> sys.path_hooks[1]('Z:\\tmp\\wenv-6a8e72be\\Lib')
FileFinder('Z:\\tmp\\wenv-6a8e72be\\Lib')
>>> sys.path_hooks[1]('Z:\\tmp\\wenv-6a8e72be\\')
FileFinder('Z:\\tmp\\wenv-6a8e72be\\')
>>> os.stat('Z:\\tmp\\wenv-6a8e72be')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [WinError 87] Invalid parameter: 'Z:\\tmp\\wenv-6a8e72be'
>>> os.stat('Z:\\tmp\\wenv-6a8e72be\\Lib')
os.stat_result(st_mode=16895, st_ino=17023097, st_dev=1124073472, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1672601334, st_mtime=1672601334, st_ctime=1672601334)
>>> os.stat('Z:\\tmp\\wenv-6a8e72be\\')
os.stat_result(st_mode=16895, st_ino=17023095, st_dev=1124073472, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1672601322, st_mtime=1672601322, st_ctime=1672601322)

So appending the backslash in PYTHONPATH seems to fix this issue:

$ wenv python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path[2] += "\\"
>>> import _socket
>>> # success

Unfortunately, setting this via the env variable doesn't really seem to work:

$ PYTHONPATH="Z:\\tmp\\wenv-6a8e72be\\" wenv python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\obj\windows-release\37win32_Release\msi_python\zip_win32\socket.py", line 49, in <module>
ModuleNotFoundError: No module named '_socket'
>>> import sys, os
>>> sys.path
['', 'Z:\\tmp\\wenv-6a8e72be\\Lib', 'Z:\\tmp\\wenv-6a8e72be', 'Z:\\tmp\\wenv-6a8e72be\\lib\\site-packages']
>>> os.environ["PYTHONPATH"]
'Z:\\tmp\\wenv-6a8e72be\\'

So I guess there is no really nice workaround and we'd better somehow fix that OSError: [WinError 87] Invalid parameter: 'Z:\\tmp\\wenv-6a8e72be'.

PS: my system python is Python 3.11.1 (main, Dec 7 2022, 00:00:00) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)] on linux / Fedora 37

@N-Coder
Copy link

N-Coder commented Jan 1, 2023

There actually is a workaround: it seems that moving the .pyd (and also .dll) files to a location that can be found and then also creating a further directory makes things work:

$ wenv init
wine: configuration in L"/home/finksim/GitLab/ogdf/ogdf-wheel/.venv/share/wenv/win32" has been updated.
Traceback (most recent call last):
  File "<stdin>", line 32207, in <module>
  File "<stdin>", line 135, in main
  File "<stdin>", line 111, in bootstrap
  File "<stdin>", line 92, in monkeypatch_for_cert
  File "C:\users\finksim\Temp\tmpz_2hrraq\pip.zip\pip\_internal\commands\__init__.py", line 9, in <module>
  File "C:\users\finksim\Temp\tmpz_2hrraq\pip.zip\pip\_internal\cli\base_command.py", line 5, in <module>
  File "D:\obj\windows-release\37win32_Release\msi_python\zip_win32\config.py", line 30, in <module>
  File "D:\obj\windows-release\37win32_Release\msi_python\zip_win32\handlers.py", line 26, in <module>
  File "D:\obj\windows-release\37win32_Release\msi_python\zip_win32\socket.py", line 49, in <module>
ModuleNotFoundError: No module named '_socket'
$ cp .venv/share/wenv/win32/drive_c/python-3.7.4.stable/*.{pyd,dll} .venv/share/wenv/win32/drive_c/python-3.7.4.stable/Lib
$ wenv init
Collecting pip
  Downloading pip-22.3.1-py3-none-any.whl (2.1 MB)
     ---------------------------------------- 2.1/2.1 MB 11.1 MB/s eta 0:00:00
Collecting setuptools
  Downloading setuptools-65.6.3-py3-none-any.whl (1.2 MB)
     ---------------------------------------- 1.2/1.2 MB 12.0 MB/s eta 0:00:00
Collecting wheel
  Downloading wheel-0.38.4-py3-none-any.whl (36 kB)
Installing collected packages: wheel, setuptools, pip
  WARNING: Failed to write executable - trying to use .deleteme logic
ERROR: Could not install packages due to an OSError: [WinError 3] Path not found: 'Z:\\tmp\\wenv-6a8e72be\\Scripts\\wheel.exe' -> 'Z:\\tmp\\wenv-6a8e72be\\Scripts\\wheel.exe.deleteme'
$ mkdir .venv/share/wenv/win32/drive_c/python-3.7.4.stable/Scripts
$ wenv init
Collecting pip
  Using cached pip-22.3.1-py3-none-any.whl (2.1 MB)
Collecting setuptools
  Using cached setuptools-65.6.3-py3-none-any.whl (1.2 MB)
Installing collected packages: setuptools, pip
Successfully installed pip-22.3.1 setuptools-65.6.3

@s-m-e
Copy link
Member

s-m-e commented Jan 1, 2023

@nukemiko How did you install wenv? Into a virtual environment, into the user account ... ? Besides, can you try to downgrade Wine from 7.22 staging to at least 7.17 staging or older (e.g. 7.0 stable) and see if the observed behavior changes?

@N-Coder What version of Wine is this? See wine --version. I have recently seen similar issues, caused by bugs introduced into path handling in Wine. In case you are running anything younger than a stable 7.0 release, specifically 7.18 staging or younger, please try downgrading Wine and check if (how) the problem differs. Besides, RedHat / Fedora / CentOS and friends do a lot of unusual customizations to their system for security reasons, including patching Python and Wine in odd ways, breaking compatibility with the rest of the world. It would not be the first time in this project to see issues coming down to RedHat's patches. Added to my to-do list, trying to reproduce this on a clean install of any Debian/Ubuntu or SuSE based system. Besides, if you are running on an distribution build of Wine, you may try alternative builds from the Wine project itself for comparison - the usually behave differently.

@N-Coder
Copy link

N-Coder commented Jan 2, 2023

I can report that it worked without needing the workaround on a downgraded wine 7.12, my comments above were based on 7.22.

@s-m-e s-m-e added the upstream label Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants