ImportError about 'lrec.utils.data_utils.data_cython_helpers'(jupyter notebook python匯入不了C檔案)__python

來源:互聯網
上載者:User

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 osfrom setuptools import find_packagesfrom distutils.core import setupfrom distutils.extension import Extensionfrom Cython.Build import cythonizedef 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.成功運行



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.