OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why is cv2 missing in my Jupyter Notebook, but working in my terminal with the same Virtual Environment?

  • Thread starter Thread starter Lars Haarhus
  • Start date Start date
L

Lars Haarhus

Guest
I am on a Nvidia Jetson Nano with the JetPack4.5 Image from Waveshare. I installed a Virtual Environment with python3.8 and OpenCv. When I try in my terminal there is no Problem.

Code:
(.venv) jetson@nano-4gb-jp451:~/python3.8test$ python
Python 3.8.0 (default, Dec  9 2021, 17:53:27) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2

After that I added the Virtual Environment to my Jupyter Notebook.

Code:
pip install --user ipykernel

python -m ipykernel install --user --name=venv
Installed kernelspec venv in /home/jetson/.local/share/jupyter/kernels/venv

In the new venv Notebook I checked the python version, which was corrected.

Code:
from platform import python_version
print(python_version())

3.8.0

But when I try to import cv2 the Output is "No module named 'cv2'

Code:
%matplotlib inline

from matplotlib import pyplot as plt
import cv2

image = cv2.imread('TestBild.PNG')

cv2.imwrite('TestBildOut.PNG', image)

print(image.shape)
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.show()

Code:
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[3], line 4
      1 get_ipython().run_line_magic('matplotlib', 'inline')
      3 from matplotlib import pyplot as plt
----> 4 import cv2
      6 image = cv2.imread('TestBild.PNG')
      8 cv2.imwrite('TestBildOut.PNG', image)

ModuleNotFoundError: No module named 'cv2'

I was expecting that if opencv is working in the Virtual Environment, it would work too in the Notebook with the same Virtual Environment...

Is there a way to fix the Problem?
<p>I am on a Nvidia Jetson Nano with the JetPack4.5 Image from Waveshare. I installed a Virtual Environment with python3.8 and OpenCv.
When I try in my terminal there is no Problem.</p>
<pre><code>(.venv) jetson@nano-4gb-jp451:~/python3.8test$ python
Python 3.8.0 (default, Dec 9 2021, 17:53:27)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
</code></pre>
<p>After that I added the Virtual Environment to my Jupyter Notebook.</p>
<pre><code>pip install --user ipykernel

python -m ipykernel install --user --name=venv
Installed kernelspec venv in /home/jetson/.local/share/jupyter/kernels/venv
</code></pre>
<p>In the new venv Notebook I checked the python version, which was corrected.</p>
<pre><code>from platform import python_version
print(python_version())

3.8.0
</code></pre>
<p>But when I try to import cv2 the Output is "No module named 'cv2'</p>
<pre><code>%matplotlib inline

from matplotlib import pyplot as plt
import cv2

image = cv2.imread('TestBild.PNG')

cv2.imwrite('TestBildOut.PNG', image)

print(image.shape)
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.show()
</code></pre>
<pre><code>---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[3], line 4
1 get_ipython().run_line_magic('matplotlib', 'inline')
3 from matplotlib import pyplot as plt
----> 4 import cv2
6 image = cv2.imread('TestBild.PNG')
8 cv2.imwrite('TestBildOut.PNG', image)

ModuleNotFoundError: No module named 'cv2'
</code></pre>
<p>I was expecting that if opencv is working in the Virtual Environment, it would work too in the Notebook with the same Virtual Environment...</p>
<p>Is there a way to fix the Problem?</p>
 

Latest posts

Top