Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SO module found by Cython not found by Python3

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$ 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?

>Solution :

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?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading