Issue importing in windows
realratchet opened this issue · comments
Hello,
I seem to be having trouble importing PYD
under windows platform, I've tried the suggested flags but github pipeline for windows keeps failing.
Compilation arguments
nim c --app:lib -d:release -d:danger --tlsEmulation:off --passL:-static --out:app.pyd app.nim
Error in python when importing the module
ImportError: DLL load failed while importing app: A dynamic link library (DLL) initialization routine failed.
PYD
dependencies:
Dump of file app.pyd
File Type: DLL
Image has the following dependencies:
KERNEL32.dll
api-ms-win-crt-convert-l1-1-0.dll
api-ms-win-crt-environment-l1-1-0.dll
api-ms-win-crt-filesystem-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-locale-l1-1-0.dll
api-ms-win-crt-private-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll
Summary
1000 .CRT
1000 .bss
1000 .data
1000 .debug_abbrev
1000 .debug_aranges
1000 .debug_frame
3000 .debug_info
1000 .debug_line
1000 .debug_line_str
1000 .debug_loclists
1000 .debug_rnglists
1000 .debug_str
1000 .edata
2000 .idata
3000 .pdata
D000 .rdata
1000 .reloc
4C000 .text
1000 .tls
3000 .xdata
Please make sure python and your dll's architectures match
I'll check, but would there be any parameters to compile under different architecture? I assume it would default to same architecture as host. The machine that built it is the one attempting to import it.
Please make sure python and your dll's architectures match
How do you recommend that I'd do that?
Machine: x64
Python: x64
PYD: x64
based on the instruction on troubleshooting-qa it also looks to me like the virtual environment isn't being read. e.g. nimpy uses default users venv
instead.
Can we fund somebody to get this issue dealt with?
The first step would be to teach me to reproduce it. Provide smallest possible source code of app.nim
and test.py
. Describe your python installation, version, venv, etc. What are the paths to your pyd
and main.py
files. Windows version, nim version, mingw version. Whether you tried reinstalling all of it (surprisingly this helps quite often).
I solved the issue that was plaguing Windows.
import nimpy
let
builtins = pyBuiltinsModule() # specifically this line was problematic
PyNoneClass = builtins.None.getattr("__class__")
proc isNone*(py: PyObject): bool {.inline.} =
return builtins.isinstance(py, PyNoneClass).to(bool)
I tracked it down to this particular snippet and changed it to this
import nimpy
var
isInit = false
builtins: PyObject
PyNoneClass: PyObject
proc isNone*(py: PyObject): bool {.inline.} =
if not isInit:
builtins = pyBuiltinsModule()
PyNoneClass = builtins.None.getattr("__class__")
isInit = true
return builtins.isinstance(py, PyNoneClass).to(bool)
You may close the issue.