[Django]-"ImportError: No module named cv2" when running Django project from PyCharm IDE

10👍

In the end I ended up having to set an environment variable directly in the Pycharm Edit Configurations -> Run/Debug Configurations -> Environment Variables panel. I added the following option after you hit the edit button: set name to PYTHONPATH and value to /usr/local/lib/python2.7/site-packages:$PYTHONPATH which should display in the input box after editing as PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH. Also, I made sure to log out and log back in of osx which also worked for a couple other path related issues.

1👍

I’m not quite sure if this works for you guys but it works for me. In my case, it seems to me that I installed OpenCV to work with the default Python arriving with OS X. I remember I tried to install Python 2.7.5 and Python 3 in my Mac as well, I see them when I chose my Python interpreter for Pycharm. And all of them didn’t let me import module cv2. So I change to the default Python2.7.2 (/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python). Then, in File/DefaultSettings/Project Interpreter/Python Interpreter, click on the Python interpreter that’s been added (Python 2.7.2), click on Paths and locate to “/usr/local/bin/python2.7/site-packages”and add it. Click the blue refresh button, apply and ok. Then it works, both with import and autocompletion.

Regards,

👤tnq177

Leave a comment