简体   繁体   中英

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:

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM