No module named cv2 in only one jupyter notebook - python

Before someone says that this is a repeated question and I should just install it, hear my case:
I am running a jupyter notebook from a conda environment in which opencv is already installed
I have had no problem using opencv so far in this environment.
I have downloaded a jupyter notebook, I have also created my own.
In my own newly created notebook I put
import numpy as np
import cv2
import glob
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
#%matplotlib qt
%matplotlib inline
it runs without problems.
Then I open the other notebook (which is situated in the same directory as the previous one)
and I do
import numpy as np
import cv2
import glob
import matplotlib.pyplot as plt
%matplotlib qt
and I get
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-b35e53327fbb> in <module>
1 import numpy as np
----> 2 import cv2
3 import glob
4 import matplotlib.pyplot as plt
5 get_ipython().run_line_magic('matplotlib', 'qt')
ModuleNotFoundError: No module named 'cv2'
Why? It was running in the other notebook!

See if both notebooks are running in the same virtual environment.
You can type conda activate <env_name> before running the notebook with jupyter notebook command.

Related

Jupyter Notebook Import Error: cannot import name 'np_version_under1p17' from 'pandas.compat.numpy'

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.dates as md
import datetime as dt
import time
from zipfile import ZipFile
from matplotlib.pyplot import xticks
%matplotlib inline
--------------------------------------------------------------------------- ImportError Traceback (most recent call
last) in
1 import numpy as np
----> 2 import pandas as pd
3 import matplotlib.pyplot as plt
4 import seaborn as sns
5 import matplotlib.dates as md
~\anaconda3\lib\site-packages\pandas_init_.py in
20
21 # numpy compat
---> 22 from pandas.compat.numpy import (
23 np_version_under1p17 as _np_version_under1p17,
24 np_version_under1p18 as _np_version_under1p18,
ImportError: cannot import name 'np_version_under1p17' from
'pandas.compat.numpy' (C:\Users\XX\anaconda3\lib\site-packages\pandas\compat\numpy_init_.py)
I have upgraded all conda libraries, uninstalled/installed pandas again, but its still stuck
I encountered the same problem and I think that there is no "one-step" solution.
For me, I recently installed python 64-bit version as I was using the 32-bit version till then. But due to some reason the new version was installed in a different location.
My problem was actually with the notebook. So I deleted all the files(the folder in which the old 32-bit python was installed) in the old path and reinstalled the notebook using pip install notebook and everything worked fine.
Before that try upgrading the current pandas version using pip3 --upgrade pandas. For me the problem was messed up installation.

Error when importing matplotlib in Python

I am new to python and am just getting started. I have a Jupyter Notebook from my university and have to plot something using matplotlib. All I find on the web is this:
import numpy as np
import matplotlib.pyplot as plt
but when I try that, it tells me
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-12-e0e1492b7973> in <module>
1 import numpy as np
----> 2 import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
Any help and further tips are very welcome.
matplotlib has to be installed
pip3 install matplotlib
since you have the jupyter tag, installing it with the Anaconda Prompt is an option
conda install matplotlib

How do I import face_recognition in Google Colaboratory?

I'm working in Google Colab and have already imported dlib
!pip install dlib
import dlib
and installed face_recognition module.
!pip install face_recognition
But, I'm getting error for this line:
import face_recognition
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.patches import Circle
import numpy as np
import cv2
%matplotlib inline
The error is as follows:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-159-91aca6eea0d3> in <module>()
----> 1 import face_recognition
2 import matplotlib.pyplot as plt
3 from matplotlib.patches import Rectangle
4 from matplotlib.patches import Circle
5 import numpy as np
1 frames
/usr/local/lib/python3.6/dist-packages/face_recognition/api.py in <module>()
24
25 cnn_face_detection_model = face_recognition_models.cnn_face_detector_model_location()
---> 26 cnn_face_detector = dlib.cnn_face_detection_model_v1(cnn_face_detection_model)
27
28 face_recognition_model = face_recognition_models.face_recognition_model_location()
RuntimeError: Error while calling cudaGetDevice(&the_device_id) in file /tmp/pip-wheel-66glv9rf/dlib/dlib/cuda/gpu_data.cpp:201. code: 100, reason: no CUDA-capable device is detected
What can be done?
From the error I can see you (probably) have not enabled GPU acceleration.
Go to Runtime -> Change Runtime -> Select GPU
Then Run the code !pip install face_recognition
This should install the library (and dependencies) without issue. Besides you don't need to install dlib separately. Let face_recognition build it alongside it.

scikit-learn not importing in jupyter notebook

I installed scikit-learn both using pip and conda commandas. Whenever I check the package, it shows that it is already installed but, whenever I try import it, it shows error.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
%matplotlib inline
ERROR:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-33-82d3fc6531ea> in <module>
3 import matplotlib.pyplot as plt
4 import seaborn as sns
----> 5 from sklearn.model_selection import train_test_split
6 get_ipython().run_line_magic('matplotlib', 'inline')
ModuleNotFoundError: No module named 'sklearn'
I have tried reinstalling it multiple times but it shows the same error
Make sure that if you install the sklearn package in the python version that you are working. For suppose if your system has two versions of python installed in it like both python 2 and python 3 then you have installed sklearn package in python 2 and executing your code in python 3 or vice-versa.
I think you don't have latest version of sklearn because in old version of sklearn
below code was not working.
from sklearn.model_selection import train_test_split
Please update your sklearn by following command
conda update scikit-learn
I got the same error while installing these.
What you can do is install all the packages using the command
conda install pandas
and all other packages similarly or all in once
conda install pandas numpy matplotlib scikit-learn
in your project directory.
And now you can open your jupyter notbook using command
jupyter notebook
in the same environment or I should say same project directory.

How to Install module name pb?

When I am Running code but it is showing error message because it is showing no module name, how to install pb name module in Collaboratory and anaconda?
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-6-65b14fed549b> in <module>()
6 import seaborn as sns
7
----> 8 from pb import log_progress
ModuleNotFoundError: No module named 'pb'
%matplotlib inline
from matplotlib import pylab as plt
import matplotlib.dates as mdates
plt.rcParams['figure.figsize'] = (15.0, 8.0)
import pandas as pd
import seaborn as sns
from pb import log_progress
A quick google brought me here: https://progressbar-2.readthedocs.io/en/latest/#
logically this would be easily fixed by running the commands pip install progressbar2 or pip3 install progressbar2.

Categories