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

dynamic module does not define module export function (PyInit_commands) #62

Closed
neroist opened this issue Feb 12, 2022 · 1 comment
Closed

Comments

@neroist
Copy link

neroist commented Feb 12, 2022

I'm trying to make a simple program using Python and Nim where the Python file calls a procedure that opens YouTube from the Nim file. And I get this error when importing the Nim file:

commands.nim:

import browsers

proc youtube* =
  openDefaultBrowser("https://www.youtube.com/")

main.py:

import nimporter
from commands import youtube

youtube()

And I get this error when importing the Nim file:

Error Message:

dynamic module does not define module export function (PyInit_commands)

Python Version:

3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]

Nim Version:

Nim Compiler Version 1.6.2 [Windows: amd64]

CC Version:

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

Installed CCs:

{'msc': WindowsPath('C:/Nim/nim-1.6.2/bin/vccexe.EXE'), 'gcc': WindowsPath('C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.EXE')}

Also, if I just call something simple like an echo, or anything else, it throws the same error! In addition, this might not be important but I installed pipwin before running this code and nimporter used to work before so i wonder if those two are connected.

@Pebaz
Copy link
Owner

Pebaz commented Feb 12, 2022

Hello @nonimportant, thanks for submitting this!

If you add the the {.exportpy.} to the function signature, it will be properly exported during the Nim compilation step:

import browsers

proc youtube* {.exportpy.} =
    openDefaultBrowser("https://www.youtube.com/")

Nimporter builds upon Nimpy to expose Nim to the Python interpreter. There's a lot of useful unit tests that show the full capabilities of Nimpy!

I'll close this for now but please let me know if you encounter any other issues! 🙂

@Pebaz Pebaz closed this as completed Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants