-1

I have a Cython module compiled from pyx files to c files that I am trying to import and use in a python module. I'm running python 3.6 on a Mac. When I run gcc -v the output is:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr - -with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1 Apple LLVM version 10.0.1 (clang-1001.0.46.4) Target: x86_64-apple-darwin18.7.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Running python setup.py build and python setup.py install gives no errors, and the .so and .c files for the corresponding files appear in the right directory, which is on the path.

When I try to import the module, I get an error in the init file, from a line that tries to import another submodule:

from . import subModule

I've tried updating python and Cython, and I've made sure that gcc is in user/lib.

This is my setup.py file:

from Cython.Build import cythonize


  setupArgs = dict(
  name="module",
  version="1.1.0",
  description=description,
  url="https://github.com/XXXX/XXXXX/module",
  author="CTcue",
  author_email="info@XXXXXX.com",
  ext_modules=cythonize(["module/*.pyx"]),
)


# Use distutils setup
from distutils.core import setup

setup(**setupArgs)

This is the error message:

 File "module/subModule.pyx", line 4, in init module.subModule
ModuleNotFoundError: No module named 'thirdModule'

The thirdModule in question has a .c file and a .so file that correspond to the .pyx file, and as far as I can tell everything is order there.

module's init.py:

__title__     = 'Pseudonomizer'
__version__   = '1.0.2'
__author__    = 'CTcue'
__license__   = 'Proprietary'
__copyright__ = 'Copyright 2016 CTcue'

from . import subModule

subModule:

import thirdModule

thirdModule.doSomething()

third module:

import re
from . import anotherModule

def doSomething:
    #code that does something

Edit : In an attempt to see if the compiler is at fault, I tried to manually compile the .c file of thirdModule with "gcc thirdModule", and got the following error:

Undefined symbols for architecture x86_64:

This seems to suggest that the issue is compiler-related, but I still haven't found the solution.

Any help would be much appreciated.

Boris
  • 716
  • 1
  • 4
  • 25
  • 1
    Please add a [mcve]. – hoefling Aug 22 '19 at 16:49
  • @hoefling I've added a minimal example and one further lead, in case you can think of something. – Boris Aug 22 '19 at 18:16
  • 1
    Your problem has nothing to do with Cython, but with Python3 disabling implicit relative import (see https://stackoverflow.com/q/12172791/5769463). That means subModule should use `from . import thirdModule` instead of `import thirdModule` which only works with implicit relative import (i.e. Python2) – ead Aug 23 '19 at 05:47
  • @ead I changed the import but now `I'm getting the same error as before. I forgot to mention there is this at the bottom of the stack trace : implicit entry/start for main executable (maybe you meant: ___pyx_module_is_main_pseudonymizer__address) ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status – Boris Aug 23 '19 at 07:39
  • And where is the `thirdModule.so` relatively to `subModule.so`, in the same directory? – ead Aug 23 '19 at 08:00
  • Yes, thirdModule.so and subModule.so are in the same directory, setup.py is in the enclosing directory one step above them – Boris Aug 23 '19 at 08:19

1 Answers1

0

It turns out @ead was right, and the problem was that the module had implicit relative imports which are no longer allowed in python 3.

Boris
  • 716
  • 1
  • 4
  • 25