rochacbruno / rust-python-example

Example of using Rust to Extend Python
https://developers.redhat.com/blog/2017/11/16/speed-python-using-rust/
789 stars 63 forks source link

Does not work on Windows OS #22

Open pydemo opened 4 years ago

pydemo commented 4 years ago
import os
import sys
from ctypes import *

lib = cdll.LoadLibrary(r'myrustlib.dll')
val='tesTTanotheRRtesTTtest'
lib.count_doubles(val)

errors out:


    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'count_doubles' not found
szabolcsdombi commented 4 years ago

just rename myrustlib.dll to myrustlib.pyd and import should work by name.

bindy commented 4 years ago

just rename myrustlib.dll to myrustlib.pyd and import should work by name.

Can you paste your code here? I also get the same error result. Thanks.

szabolcsdombi commented 4 years ago

pyd files can be imported by name

>>> import myrustlib
>>> dir(myrustlib)
[...]

make sure myrustlib is on pythonpath, if not just put it next the the py file that imports it.

szabolcsdombi commented 4 years ago

move myrustlib.pyd to the project's root in this case. the Makefile does this for the .so file on linux. On windows the the so equivalent is dll but it must be renamed to pyd.