ImportError: No module named cv2. But running apt-get command shows that python-opencv is already installed
<p>Even though I tried out the solutions given for the same type of questions concerning the same error, nothing worked. When I try to run the script it gives this import error. But surprisingly when I try </p>

<blockquote>
  <p>apt-get install python-opencv </p>
</blockquote>

<p>I get this message:</p>

<blockquote>
  <p>python-opencv is already the newest version.</p>
</blockquote>

<p>This is what puzzles me. If it is installed, why can't it be imported?
Thanks in advance.</p>

<p>Most likely the library python-opencv is not installed in the default directory. That is why your interpreter cannot find it.</p>

<p>When dealing with python projects it's recommended to use virtualenv. It will allow you to create separate python environments and not mess them up. Then install pip and use it to install python packages rather than apt-get install inside of your virtual environment.</p>

<p>In your case you need to run:</p>

<pre><code>sudo dpkg-query -L python-opencv
</code></pre>

<p>It will output the directories to where the python-opencv library was installed. And the add that path to PYTHONPATH in your .bashrc file (most likely it is .bashrc in Debian):</p>

<pre><code>PYTHONPATH="${PYTHONPATH}:/path/to/the/python/libraries"
export PYTHONPATH
</code></pre>

<p>Then run <code>. .bashrc</code> in your home folder. </p>

<p>But it's not recommended to do that. As I've already said the cleaner way  is to use virtualenv and pip. In that case you don't need to mess up with PYTHONPATH.</p>

python opencv importerror