"ImportError: without cv2 module" when starting a Django project from PyCharm IDE

I am running a Django project from PyCharm with a configuration setting using the Python interpreter from virtualenv, which has an opencv dependency. The site works fine locally when I run django-admin.py runserver , however, I continue to get the " ImportError: No module named cv2 " ImportError: No module named cv2 when I try to start the project directly from PyCharm.

Has anyone else had a problem with PyCharm and opencv?

+3
source share
2 answers

In the end, I had to set the environment variable directly in the "Pycharm Edit → Run / Debug Configurations → Environment" panel. After clicking the edit button, I added the following parameter: set the name PYTHONPATH and the value /usr/local/lib/python2.7/site-packages:$PYTHONPATH , which should appear in the input field after editing as PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH . In addition, I made sure that we exit the osx system and go into a system that also worked for a couple of other path-related issues.

+9
source

I'm not quite sure if this works for you, but it works for me. In my case, it seems to me that I installed OpenCV to work with Python by default, coming from OS X. I remember I tried installing Python 2.7.5 and Python 3 on my Mac, I see them when I select my Python translator for Pycharm . And they all did not allow me to import the cv2 module. So I am moving to Python2.7.2 by default (/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python). Then, in the "File / DefaultSettings / Project Interpreter / Python Interpreter" program, click on the Python interpreter that was added (Python 2.7.2), click on "Paths" and find "/usr/local/bin/python2.7/site-packages "and add it. Press the blue update button, apply and good. Then it works with both import and completion.

Hi,

+1
source

All Articles