Jupyter notebook not recognizing packages in venv

April 22, 2021, at 12:40 PM

This has been driving me crazy. For some reason it seems like my .ipynb file doesn't recognize the python packages in my venv. I get this error even though I've clearly installed opencv. I run into this exact same problem for dlib and imutils too.

However, when I use opevcv in a regular .py file in the save venv, it works completely fine so it's something to do with .ipynb (Jupiter Notebooks).

I have tried pip3 install opencv-python

Note: I am pretty sure I have selected the correct venv when running my .ipynb file.

The output I get when I run !pip list in the Jupyter Notebook (which includes opencv-python):

Package                 Version
----------------------- -------------------
absl-py                 0.12.0
astunparse              1.6.3
cachetools              4.2.1
certifi                 2020.12.5
chardet                 4.0.0
cmake                   3.18.4.post1
cycler                  0.10.0
dlib                    19.22.0
flatbuffers             1.12
gast                    0.4.0
google-auth             1.29.0
google-auth-oauthlib    0.4.4
google-pasta            0.2.0
grpcio                  1.34.1
h5py                    3.1.0
idna                    2.10
imutils                 0.5.4
keras-nightly           2.5.0.dev2021032900
Keras-Preprocessing     1.1.2
kiwisolver              1.3.1
Markdown                3.3.4
matplotlib              3.4.1
numpy                   1.19.5
oauthlib                3.1.0
opt-einsum              3.3.0
Pillow                  8.2.0
pip                     21.0.1
protobuf                3.15.8
pyasn1                  0.4.8
pyasn1-modules          0.2.8
pyparsing               2.4.7
python-dateutil         2.8.1
requests                2.25.1
requests-oauthlib       1.3.0
rsa                     4.7.2
setuptools              54.1.2
six                     1.15.0
tensorboard             2.5.0
tensorboard-data-server 0.6.0
tensorboard-plugin-wit  1.8.0
tensorflow              2.5.0rc1
tensorflow-estimator    2.5.0rc0
termcolor               1.1.0
urllib3                 1.26.4
Werkzeug                1.0.1
wheel                   0.36.2
wrapt                   1.12.1

Please help, thank you

Answer 1

Try changing kernels. (Check on the image in the URL for guidance). If your venv is not in the list, you should add it manually. Follow this guide to add your venv

Answer 2

Are you using your local machine? How do you fire up the jupyter notebook? You could try the following:

  1. Open a prompt and activate your virtual environment.
  2. python And then >>> import <module>: Does it import it?

Make sure that you have jupyter insatlled in that environment and then

  1. Open a prompt and activate your virtual environment.
  2. Issue python -m jupyter notebook
Answer 3

Maybe this question will be deleted but this is what fixed it for me (thanks to @Shi XiuFeng):

I had initially created my venv with virtualenv env which didn't work, and so when I recreated the venv with python3 -m venv env this worked completely fine.

Cannot change role users from wp_list_table

Cannot change role users from wp_list_table

can anyone solve my problem? I want to change users role from administrator to subscriber via wp_list_table but after I click "change" statuses is "role is changed", but it didn't take any effectThe role is still "administrator"

Selecting second child div while hovering on first child div in makeStyles Material UI

Selecting second child div while hovering on first child div in makeStyles Material UI

I have a parent div and two child divs, I want to apply CSS to the second child div when I hover on the first child divThis is the structure of the render method