Pebaz / nimporter

Compile Nim Extensions for Python On Import!
MIT License
829 stars 33 forks source link

nimporter.NimporterException: Error importing faster_than_requests.pyd #70

Closed Nqndi closed 1 year ago

Nqndi commented 2 years ago

`std/db_sqlite(184, 1) Warning: Circular dependency detected. 'codeReordering' pragma may not be able to reorder some nodes properly [User] ws.nim(329, 32) Warning: conversion to enum with holes is unsafe: Opcode(b0 and 0x0000000F) [HoleEnumConv] nimpy.nim(557, 32) Warning: Cannot prove that 'arg0timeout' is initialized. This will become a compile time error in the future. [ProveInit] faster_than_requests.nim(293, 132) Warning: Deprecated since v1.5; Use auto instead.; any is deprecated [Deprecated] faster_than_requests.nim(298, 101) Warning: Deprecated since v1.5; Use auto instead.; any is deprecated [Deprecated] Traceback (most recent call last): File "C:\Users\Nandi\AppData\Local\Programs\Python\Python39\lib\site-packages\nimporter.py", line 979, in __validate_spec util.module_from_spec(spec) File "", line 565, in module_from_spec File "", line 1108, in create_module File "", line 228, in _call_with_frames_removed ImportError: DLL load failed while importing faster_than_requests: The specified module could not be found.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\Nandi\Desktop\python\speed.py", line 1, in import faster_than_requests File "C:\Users\Nandi\AppData\Local\Programs\Python\Python39\lib\site-packages\faster_than_requests__init.py", line 7, in from . faster_than_requests import * File "", line 1007, in _find_and_load File "", line 982, in _find_and_load_unlocked File "", line 925, in _find_spec File "C:\Users\Nandi\AppData\Local\Programs\Python\Python39\lib\site-packages\nimporter.py", line 1269, in find_spec return Nimporter.import_nim_code(fullname, path, library=False) File "C:\Users\Nandi\AppData\Local\Programs\Python\Python39\lib\site-packages\nimporter.py", line 957, in import_nim_code cls.__validate_spec(spec) File "C:\Users\Nandi\AppData\Local\Programs\Python\Python39\lib\site-packages\nimporter.py", line 1025, in validate_spec raise NimporterException(error_message) from import_error nimporter.NimporterException: Error importing C:\Users\Nandi\AppData\Local\Programs\Python\Python39\Lib\site-packages\faster_than_requests__pycache__\faster_than_requests.pyd Error Message:

DLL load failed while importing faster_than_requests: The specified module could not be found.

Python Version:

3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]

Nim Version:

Nim Compiler Version 1.6.6 [Windows: amd64]

CC Version:

vccUndefined: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat

Installed CCs:

{'msc': WindowsPath('C:/nim/bin/vccexe.EXE'), 'clang': WindowsPath('C:/Users/Nandi/AppData/Local/Nuitka/Nuitka/gcc/x86_64/10.2.0-11.0.0-8.0.0-r5/mingw64/bin/clang.EXE'), 'gcc': WindowsPath('C:/Users/Nandi/AppData/Local/Nuitka/Nuitka/gcc/x86_64/10.2.0-11.0.0-8.0.0-r5/mingw64/bin/gcc.EXE')}

Please help improve Nimporter by opening a bug report at: https://github.com/Pebaz/nimporter/issues/new and submit the above information along with your description of the issue.`

Pebaz commented 2 years ago

@Nqndi Thank you for opening a bug report. Can you post a code example to reproduce this?

Nqndi commented 2 years ago

I installed faster_than_requests on python 3.9, and when I try to import it using import faster_than_requests, I get this error.

Pebaz commented 2 years ago

Ah interesting, I think this is a clue: nimporter.NimporterException: Error importing C:\Users\Nandi\AppData\Local\Programs\Python\Python39\Lib\site-packages\faster_than_requests_pycache\faster_than_requests.pyd

Nimporter found an existing file and tried to import it but the DLL load failed. This usually happens when one of these things don't match:

Nimporter is a convenience layer on top of Nimpy that allows you to directly import Nim extension modules. Can you verify that doing this by hand works as expected using your configuration by following these short instructions? All you'd need to do is copy their greeter example and see if it compiles/imports. This would tell us a lot about what the underlying issue could be.

Additionally, @juancarlospaco do you have time to test out the Nimporter 2.0 release candidate with fasterthanrequests? It's a major rewrite that helps clear up a lot of issues surrounding Nimporter usage that result in the same sort of errors above by simplifying distribution.

Nqndi commented 2 years ago

It compiles just fine, and I can import it inside test.py

juancarlospaco commented 2 years ago

Awesome!, I think is something missing from Nim and Python ecosystems, Rust-Python has its lib to do this, but not Nim-Python, this is a great tool.

I am interested, I have no time right now and I have to learn the new API from docs, I can accept pull requests if someone is interested tho... 🙂:+1:

Nqndi commented 2 years ago

Do you guys have any idea how to fix this?

Pebaz commented 2 years ago

Sorry @Nqndi it's been a bit hectic lately so I haven't had a chance to look into this again. However, the fact that Nimporter (via Nimpy) successfully builds a .PYD file but then fails to import it is a huge clue.

Both Nimporter (workflow) and faster-than-requests (workflow) test Windows support with coverage for Python 3.9 so this is most likely due to workstation configuration.

Did you install Nim via choosenim_install (the PIP package) or by hand?

I notice in the bug report that you've got many compilers on your system. Could it be possible that there are competing bin directories on your path where Python, Nim, the CC, and separately Nimporter might be auto-discovering binaries with overloaded names?

Additionally, when you install something like Pydantic, and Python calls a C compiler and spits out it's path, can you tell me what CC Python is using to install dependencies with (for instance, sometimes Python uses MinGW somewhere on the system when MSVC should be used instead)? Just trying to cover all the bases I know about.

Lastly, if you step through the Nimporter import process in a debugger, have you noticed anything out of place such as the wrong C compiler path being used or a conditional CLI flag being passed to Nim that is unexpected? Basically just check to see if having multiple CCs installed isn't confusing Nimporter (which it shouldn't) and let me know so I can address it as an official bug.

Thank you for your time and I apologize I haven't had more time to look into this until right now. 🙂

Pebaz commented 1 year ago

Closing this for now but feel free to open again.