'Cython & tox - ModuleNotFoundError on 3.9, but not 3.8

I'm converting some of my scripts in my package to cython to try and speed up execution time, and I'm having some trouble getting it to work with tox.

The tests are passing on 3.8, but on 3.9 I get the error:

E   ModuleNotFoundError: No module named 'package.subpackage.module'

Upon investigating the build folder, the 3.9 build has both module_cpython-38-darwin.so and module_cpython-39-darwin.so (whereas the 3.8 build only has the 3.8 .so file). Manually deleting the 3.8 .so file doesn't change anything, but it's still strange that its included in one and not the other.

This is my project structure:

Project
|
|-pyproject.toml
|-setup.py
|-setup.cfg
|-MANIFEST.in
|-tox.ini
|
|-src
| |
| |-package
|   |
|   |-subpackage
|     |-module.c
|     |-module_cpython-38-darwin.so
|     |-module.pyx
|
|-tests
| |-test_package.py

What I've done so far to accomodate cython is add the following to pyproject.toml, setup.cfg, setup.py, and MANIFEST.IN

# pyproject.toml
[build-system]
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4", "cython"]
# setup.cfg
[options]

setup_requires =
    setuptools_scm
    cython
# setup.py
from setuptools import setup, Extension
from Cython.Build import cythonize

ext = Extension('package.subpackage.module', sources=['./src/package/subpackage/module.pyx'])

if __name__ == "__main__":
    setup(use_scm_version=True, ext_modules=cythonize([ext]))
# MANIFEST.in

global-include *.so

I'm not sure if .so files should be included in the manifest - but removing them from the manifest doesn't change anything.

Any idea why it's not working? Have I done something wrong with my project config?

Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source