如何在Raspbian中将pyinstaller与opencv一起使用?

时间:2020-03-10 02:03:32

标签: python opencv pyinstaller raspbian

我用raspbian编写了这个python脚本“ mycv.py”:

void displayMenu();


int multiply(int, int);
void drawRect();

int main()
{
    int userChoice = 0;
    do
    {
        displayMenu();

        cout << "Enter your choice: ";
        cin >> userChoice;

        switch (userChoice)
        {
        // display the area of a rectangle
            case 1:
            {
                int length, width;
                cout << "Enter a length: ";
                cin >> length;
                cout << "Enter a width: ";
                cin >> width;
                cout << "The area of the rectangle is: " << multiply(length, width) << endl << endl;
                drawRect(length, width);
                break;
            }
    }


int multiply(int x, int y)
{
    int product = x * y;
    return product;
}
void drawRect(int length, int width)
{
    // draw the top row
    cout << setfill('*') << setw(width) << endl;

    // draw the middle rows

    // draw the bottom row
    cout << setfill('*') << setw(width) << endl;
}


,它将调试并正常运行。然后我用pyinstaller制作可执行文件。 但是在终端中运行文件时。它有错误:

import cv2 as cv

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

经过大量调试,我找到了以下解决方案:

  1. 获取OpenCV的路径

    导入cv2 print(cv2。文件)#/usr/local/lib/python3.6/dist-packages/cv2/python-3.6/cv2.so

  2. 在通过pyinstaller进行编译时添加此路径

    pyinstaller main.py -n myApp --paths =“ / usr / local / lib / python3.6 / dist-packages / cv2 / python-3.6”

我希望这对其他人也有帮助