Skip to content

Instantly share code, notes, and snippets.

@s-m-e
Created December 28, 2022 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-m-e/84d5fbf5663825a46d9ae98e4636d8ec to your computer and use it in GitHub Desktop.
Save s-m-e/84d5fbf5663825a46d9ae98e4636d8ec to your computer and use it in GitHub Desktop.
Trigger Python import "module not found" when importing submodule from linked package on Wine 7.22 staging
#!/bin/bash
# 3.7.9 triggers the bug, 3.10.9 does not
MAJOR=3
MINOR=7
MAINTANANCE=9
PYTHONARCH=amd64 # options: win32, amd64
export WINEARCH=win64 # options: win32, win64
export WINEPREFIX=$PWD/localprefix # dedicated wine prefix for test
export WINEDLLOVERRIDES="mscoree=d" # avoid mono
export WINEDEBUG=-all # change debug level here
export VIRTUAL_ENV="" # in case this runs in a virtual environment
VERSION=$MAJOR.$MINOR.$MAINTANANCE
if [ ! -f python-$VERSION-embed-$PYTHONARCH.zip ]
then
wget https://www.python.org/ftp/python/$VERSION/python-$VERSION-embed-$PYTHONARCH.zip &> /dev/null
fi
if [ -d install ]
then
rm -r install # remove old install
fi
unzip python-$VERSION-embed-$PYTHONARCH.zip -d install > /dev/null
STDLIB=$MAJOR$MINOR
unzip install/python$STDLIB.zip -d install/Lib > /dev/null # unpack stdlib
rm install/python$STDLIB.zip # remove packed stdlib
printf "Lib\n.\n\n# Uncomment to run site.main() automatically\nimport site\n" > install/python$STDLIB._pth # point to unpacked stdlib
if [ -d $WINEPREFIX ]
then
rm -r $WINEPREFIX # remove old prefix
fi
wine install/python.exe -m platform # create and check the prefix
if [ -d temp ]
then
rm -r temp # remove temp module folder
fi
for NAME in foo bar # create two python modules with submodules and relative imports
do
mkdir -p temp/$NAME/sub$NAME
printf "from .sub$NAME import func$NAME" > temp/$NAME/__init__.py
printf "from .mod$NAME import func$NAME" > temp/$NAME/sub$NAME/__init__.py
printf "def func$NAME():\n print('mod$NAME running')\n" > temp/$NAME/sub$NAME/mod$NAME.py
done
mv temp/foo install/Lib/site-packages/ # move module "foo" to site-packages
ln -s $PWD/temp/bar install/Lib/site-packages/bar # link module "bar" to site-packages
wine install/python.exe -c "from foo import funcfoo; funcfoo()" # works
wine install/python.exe -c "from bar import funcbar; funcbar()" # triggers the bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment