I've tried to import a module from a fat jar file and got a ModuleNotFoundError: No module named ... error.
I checked that the jar file had more than 65k files and was created using Zip64. When I unzip the file, Python is capable of importing the modules.
I was able to reproduce the error on a simple project, such as:
simplePackage/
__init__.py
a/
__init__.py
moduleA.py
where
- I'm using Python 3.9.4
- __init__.py files are empty
- moduleA.py only has a printA() function
I ran the following tests:
1. When importing from the folder, it works
python
>>> import sys
>>> sys.path.append('C:\\Users\\...\\simplePackage')
>>> from a.moduleA import printA
>>> printA()
I'm module a
2. When zipping the folder, it works
python
>>> import sys
>>> sys.path.append('C:\\Users\\...\\simplePackage.zip')
>>> from a.moduleA import printA
>>> printA()
I'm module a
3. When forcing to zip with Zip64 it doesn't work
On linux: zip -fzr simple64Package.zip .
python
>>> import sys
>>> sys.path.append('C:\\Users\\...\\simple64Package.zip')
>>> from a.moduleA import printA
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'a'
Is this an expected behavior? Am I missing something?
Thanks!
|