Installing opencv 3.4.2 with Anaconda - python-3.x

I'm running Ubuntu 18.04LTS:
Firstly, I couldn't install opencv from anaconda on my existing environment (base) as it kept searching for conflicts forever and then getting stuck with an empty window saying "these packages will be modified" while displaying absolutely nothing and with the only choice of pressing the "cancel" button.
I created a new virtual environment named env_opencv and was able to install opencv:
enter image description here
Then, I run a jupyter notebook that imports opencv:
import cv2
import matplotlib.pyplot as plt
import matplotlib.patches as patches
...
And here's what I get:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-8-31cd2c78c525> in <module>
----> 1 import cv2
2 import matplotlib.pyplot as plt
3 import matplotlib.patches as patches
4
5 from align import AlignDlib
ModuleNotFoundError: No module named 'cv2'
No matter what I tried, including reinstalling opencv directly from the conda prompt, I can't get past this error.
Incidentally, I was able to make it work on Windows 10 going through the Anaconda prompt and using conda. However, my Windows machine doesn't have an nVidia GPU and I can't use it for CNN training, so I really need to make it work on Ubuntu.
Any suggestions would be great. Thank you.

I found a workaround to this issue:
I activate the env_opencv environment from the command line, then I launch jupyter notebook and it works.
Maybe, there is a bug with anaconda-navigator that doesn't seem to switch environments from the GUI?

Related

Vscode for python jupyter fail to show video

I'm trying to make a animation in the Jupyter of Visual Studio Code. The code is listed below.
import arviz as az
from IPython.display import HTML
from matplotlib.animation import FuncAnimation
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as st
...
...
...
anim = FuncAnimation(fig, update, frames=np.arange(bins.shape[0]),
init_func=init, blit=True, interval=20)
HTML(anim.to_html5_video())
However, the Jupyter fail to play the video on the Visual Studio Code. The result was shown in the picture below.
I'm also getting this issue. I've used this animation tutorial to confirm it was an VSCode issue and not my code, which I'd confirmed works in vanilla Jupyter.
I've installed JupyterLab for use with this code sample since it's easy enough to set up.
conda install -c conda-forge jupyterlab (or pip install jupyterlab)
jupyter lab
Executing the run command from the directory with your resources with default that as the run location of Jupyter so you shouldn't need to alter your code. Here's hoping they resolve this soon.

Module Not Found Error: No module named 'squarify'

On Jupyter notebook, running Python 3 code. Trying to build a squarify Tree map.
When I run the code:
import squarify as sq
ModuleNotFoundError arrises. "No Module named 'squarify'."
Although I know there such a module.
Can someone help me?
I've tried to put
path/to/python -m pip install squarify
and
install squarify
in the cell, but to no avail.
import squarify as sq results in:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-43-d5603c2d6e58> in <module>
6 #Put a title on the chart
7
----> 8 import squarify as sq
9
10 #determine count for each type weathersit
ModuleNotFoundError: No module named 'squarify'
Thank you for all the answers to this question. I have since figured it out. Best advice I can give is to search Anaconda Prompt (Anaconda 3) on your computer, which will pull up a script. Then simply time pip install squarify.
Once this loads the program on your computer, try to import squarify as sq on your jupyter notebook, and the chunk should now work without errors.
Good luck to everyone, and thank you for all the help!
Zach
In my case squarify was added to miniconda - I was not able to import it into anaconda.
I opened Anaconda Navigator - uninstalled miniconda.
Updated anaconda and imported squarify to anaconda (anaconda prompt) and it work now via simple import squarify cmd.
For me I opened Anaconda Navigator, went to Environments base(root) and clicked Open Terminal. I run the below command in the terminal and all was OK.
pip install squarify

Conflict between tensorflow/PIL/pillow and scikit-image?

I am tying to rebuild my computer to run Spyder in a tensorflow environment for some image processing. In the past this worked and I had scikit-image working fully in that environment, and accessible from Spyder. Something has changed. I have:
1) re-installed Anaconda
2) re-installed tensorflow in a conda environment
3) installed libraries as needed, including Spyder.
Then I start Spyder from the Conda navigator, in the tensorflow environment. This seems to work, I can import tensorflow, keras, pandas, sklearn, etc. But skimage only works partially. for example:
import skimage
works fine. But,
import skimage.io as io
does not. The error comes out as 'from PIL import Image' Is this something about PIL/pillow not co-existing in the same environment? Can this be fixed easily or should I just use opencv for image io? I have tried other modules in skimage and they all import. So using another package to open an image would not be the end of the world, but it would be nice to get the entirety of skimage working.
Thanks

opencv import issue and double install

Previously ROS was installed in my system which requires opencv for its implementation and now I am using anaconda in which I need to use the opencv library once again. While writing python code import cv2 throws an error module not found.
Is there any way to use that opencv library which ROS installed in anaconda
Although I installed opencv once again using conda.
$conda install -c conda-forge opencv
however opencv-3.3 was installed using above command. Now my python code is showing different import error as shown below:
ImportError Traceback (most recent call last)
<ipython-input-9-6b49ad4d4ca5> in <module>()
1 from random import shuffle
2 import glob
----> 3 import cv2
4 shuffle_data = True # shuffle the addresses before saving
5 hdf5_path = 'dataset.hdf5' # address to where you want to save the hdf5 file
ImportError: /home/kamal/ros_catkin_ws/install_isolated/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type
How can I particularly specify which opencv library to use. What env variables I need to change.
Any help will be appreciated.
uncommenting the line source /home/user/ros_catkin_ws/install_isolated/share/setup.bash in the .bashrc file dosen't help. You also need to remove the extrasys.path added by the ROS environment.
In a python console
import sys
print (sys.path)
you will see multiple paths related to ROS
then remove the unwanted part of the path by
sys.path.remove('unwanted_path')
This will solve the problem but now ROS will not work. To make it work you need to append the removed path again.
If someone has a better approach please answer.

Jupyter Notebook Packages Won't Import

I've searched around for a while, and I've tried many things such as
conda create -n ipykernel_py3 python=3 ipykernel
source activate ipykernel_py3 # On Windows, remove the word 'source'
python -m ipykernel install --user
Uninstalling and reinstall both Python3 and Anaconda3. All I want is for Jupyter Notebook to be able to use libraries in Anaconda. If I change my environment to root via
activate root
I can open Jupyter notebook, however when I do
activate ipykernel_py3
and then try to do
jupyter notebook
I get the error
Error executing Jupyter command 'notebook': [Errno 'jupyter-notebook' not found] 2
When I open Jupyter notebook and input
import os
os.getcwd()
I get
'C:\Users\Mike\Documents\Mathematical Modeling'
and Anaconda is in
'C:\ProgramData\Anaconda3'
The problem is when I do
import numpy
I get this error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-5a0bd626bb1d> in <module>()
----> 1 import numpy
ModuleNotFoundError: No module named 'numpy'
--------------------------------------EDIT--------------------------------------
I've just uninstalled anaconda, and am currently reinstalling it. For some reason I was unable to install other packages to my ipykernel_py3 environment. Hopefully I figure something out.
The solution after countless re-installations of anaconda, and working with environments, is this
Go to start menu->
View Advanced System Settings->Environment Variables
highlight the variable that has name 'Path'
Click edit
Change variable value to 'C:\Users\Mike\Anaconda3\Scripts'
Of course my directory will be different from anyone else's, but this solved all my problems.

Resources