Search code examples
pythoncythonpython-wheel

Wheel built with MSVC Cython extension cannot find module


I'm attempting to switch from a GNU + mingwpy to an MSVC toolchain to build my wheel, which includes a Cython wrapper around a binary.

I've built the external DLL with an MSVC toolchain in Appveyor, and, also in Appveyor, I've got the wheel build step working. After the build step completes, I'm testing by doing the following:

  • installing and activating a clean virtualenv
  • installing dependencies
  • installing the wheel I just built
  • running nosetests wheelname

However, this is now failing:

======================================================================
ERROR: Failure: ImportError (No module named cutil)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Miniconda\envs\test_env\lib\site-packages\nose\loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "C:\Miniconda\envs\test_env\lib\site-packages\nose\importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "C:\Miniconda\envs\test_env\lib\site-packages\nose\importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "C:\projects\simplification\simplification\test\test.py", line 5, in <module>
    from simplification.cutil import simplify_coords as csimplify_coords
ImportError: No module named cutil
----------------------------------------------------------------------

see full traceback

Running dumpbin /dependents on cutil.pyd seems to show what I expected:

Dump of file simplification/cutil.pyd
File Type: DLL
  Image has the following dependencies:
    rdp.dll
    python27.dll
    MSVCR90.dll
    KERNEL32.dll
  Summary
        4000 .data
        2000 .rdata
        3000 .reloc
       12000 .text

Where rdp.dll is the external binary I'm wrapping with Cython. What's going wrong here?

Update: My module can also import the binary using Ctypes, and when I disable the Cython-specific imports and tests in my test script, everything works. So I know my external binary is OK. I'm still confused as to why the import is failing, especially as the Cython build step of cutil.pyd completes, and dumpbin says it's looking for its rdp.dll dependency in the right place (i.e. in the same directory).

Update 2: Running dumpbin on cutil.pyd that's been built with a GNU toolchain gives the following:

Dump of file simplification/cutil.pyd
File Type: DLL
  Image has the following dependencies:
    msvcr90.dll
    python27.dll
    KERNEL32.dll
    USER32.dll
    rdp.dll
  Summary
        1000 .CRT
        1000 .bss
        3000 .data
        1000 .edata
        2000 .idata
        1000 .pdata
        4000 .rdata
        1000 .reloc
        1000 .rsrc
       1E000 .text
        1000 .tls
        1000 .xdata

But I have no idea whether the dependency order is significant or whether the metadata in the Summary section matters


Solution

  • This seems to be an issue with the virtualenv installed by Conda. I have no idea how to fix it, so I stopped using a virtualenv installed by conda.