简体   繁体   English

Cython 找到的 SO 模块没有被 Python3 找到

[英]SO module found by Cython not found by Python3

I have a simple pyx file:我有一个简单的pyx文件:

$ 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.我使用 Cython 创建了一个.so模块。 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.编辑: .so 文件是在 2018 年创建的,在重新创建它时。 everything is working perfectly!一切正常! Probably there was some version conflict between Cython and Python. Cython 和 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 .无法导入模块的最常见原因是 python 在它查看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 .您可以通过转到与生成的 helloworld 模块相同的位置来验证这一点,或者通过强制将其包含在路径中sys.path.insert(0,os.getcwd())可以是current directoryrelative/absolute path .

I seem to notice a setup.py , have you tried installing this with pip install.我似乎注意到了setup.py ,您是否尝试过使用pip install. while being in that folder, after which trying to use it?在该文件夹中,然后尝试使用它?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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