ImportError about 'lrec.utils.data_utils.data_cython_helpers'(jupyter notebook python导入不了C文件)

1.刚开始不会用才导致.


2.首先了解一下基本知识。要写 either make a setup.py for the module, as described at this page, or use pyximport to automatically compile and build your module with just an import.我选第一个。

set.py如下详解解释参考

#!/usr/bin/env python

# import os
from setuptools import find_packages

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize


def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

ext_modules = []
ext_modules += [
    Extension("lrec.evaluate.cy_ranking_metric", [
              "lrec/evaluate/cy_ranking_metric.pyx"]),
    Extension("lrec.utils.data_utils.data_cython_helpers", [
        "lrec/utils/data_utils/data_cython_helpers.pyx"]),
]

setup(
    name="LRec",
    version="0.1",
    author="Zhougongyu",
    packages=find_packages(),
    include_package_data=True,
    zip_safe=False,
    package_dir={'': '.'},
    ext_modules=cythonize(ext_modules),
).
3.使用命令pyx文件生成build文件找到c和pdy文件
python setup.py   install 


4.把这三个放在一个文件夹下如图:


5.成功运行



猜你喜欢

转载自blog.csdn.net/dongyanwen6036/article/details/80026434
今日推荐