0

I am trying to call image display code of python from C using cython.

I had followed the procedure for creating .c and .h from .pyx and adding these into the C code in visual studio.

I had checked the python version on command prompt and it is Python 3.6.3 |Anaconda custom (64-bit). I am able to import cv2 there on command prompt.

But when I call this .c and .h file into C code I am getting error

NameError: name 'cv2' is not defined
Exception ignored in: 'read.readImage'
NameError: name 'cv2' is not defined

I had checked for python path is set in the environment. Still I am getting the error.

The code for read.pyx is

import numpy as np
import cv2
cdef public void readImage():
 img = cv2.imread('dog.jpeg')
 print('reading')
 cv2.imshow('image',img)
 cv2.waitKey(0)
 cv2.destroyAllWindows()

The code for souce.cpp in visual studio is

#include "Python.h" 
# include "read.h"
using namespace cv;
int main(void) {
 Py_Initialize(); 
 PyInit_read();
 readImage();
 Py_Finalize(); 
 return 0;
}
asked May 24, 2018 at 11:57
3
  • That might be your issue, but it is impossible to say without code stackoverflow.com/q/50382755/5769463 Commented May 24, 2018 at 13:42
  • Compare the results of import sys; print(sys.path) in your python installation and in the standalone exe. I wouldn’t be surprised if they differ. You said the python path is set, to which value? Commented May 25, 2018 at 8:56
  • Thanks a lot. It was issue of python path only. It is resolved now. Commented May 31, 2018 at 5:37

1 Answer 1

1

The same python version is installed twice at different location. The issue was regarding python path.

answered Sep 11, 2018 at 5:17

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.