简体   繁体   中英

Cython module not found when called by other python files

I am using cpython to detect all cameras attached to the computer, and return the device information. I have successfully run the program in below by simply calling its file name in terminal. ( device is the C++ file I generated through setup.py):

import device

def get_device_dict():
    print("hello")
    res = {}

    device_list = device.getDeviceList()
    index = 0

    for name in device_list:
        res[index] = name
        index += 1
    return res

get_device_dict()

However, when I try to call the function from another file (camera.py based on the directory structure shown in below) by importing it, problem occurs as it says there is a failure to import the C++ generated package.

ModuleNotFoundError: No module named 'device'

Here is my directory:

在此处输入图像描述

Just made some attempts and find it is running properly from outer directory. The problem is about me running the django framework. The django framework cannot detect the cython module.

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