SO module found by Cython not found by Python3

Question:

I have a simple pyx file:

$ cat helloworld.pyx
print("hello world in pyx file to be converted to so file by cython.")

I have created an .so module using Cython. The directory contains following files:

$ ls -ltrh
total 140K
-rw-r--r-- 1 cardio cardio  177 Jul  3  2018 setup.py
-rw-r--r-- 1 cardio cardio   73 Jul  3  2018 helloworld.pyx
-rw-r--r-- 1 cardio cardio  74K Jul  3  2018 helloworld.c
-rwxr-xr-x 1 cardio cardio  52K Jul  3  2018 helloworld.cpython-35m-x86_64-linux-gnu.so
drwxr-xr-x 2 cardio cardio 4.0K Sep 10 20:21 __pycache__

However, when I try to import this module, I get error:

$ python3 -c "import helloworld"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'helloworld'

Where is the problem and how can it be solved?

Edit:
The .so file was created in 2018! On recreating it again, everything is working perfectly! Probably there was some version conflict between Cython and Python.

Asked By: rnso

||

Answers:

Most commonly the reason why you can’t import a module is that python doesn’t see it in the location it is looking at sys.path.

You can verify this by going to the same location as the produced helloworld module, or by including it in the paths by force sys.path.insert(0,os.getcwd()) can be a current directory or a relative/absolute path.

I seem to notice a setup.py, have you tried installing this with pip install . while being in that folder, after which trying to use it?

Answered By: Warkaz
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.