Couldn't import cv2 in SageMaker Studio Lab - opencv

I tried importing cv2 from opencv but i got error saying
import error: libgthread-2.0.so.0: cannot open shared object file: No such file or directory
Since Sagemaker Studio Labs doesn't support installation of Ubuntu packages i couldn't use apt-get or yum to install libglib2.0-0.

You fix this by:
!pip uninstall opencv-python -y
Then use the headless version instead with studio:
!pip install opencv-python-headless
Ref: https://github.com/aws/amazon-sagemaker-examples/issues/1773

With this line, you can install the glib dependency for Amazon Sagemaker Studio Lab. Just run it on your notebook cell.
! conda install glib=2.51.0 -y
You also can create another virtual environment for your session that contains glib:
! conda create -n glib-test -c defaults -c conda-forge python=3 glib=2.51.0` -y
After that maybe you need albumentations to import cv2:
! pip install albumentations

Related

Raspberry PI 4 - 8GM RAM - 64 bit OS aarch64 - easyocr - torch - opencv - illegal instruction

I am trying to get easyocr running on a raspberry pi 4 and could use some suggestions or help. I am using the 64 bit build from May 7th - 2021 (2021-05-07-raspios-buster-arm64.zip). When I do a fresh OS install, I execute the following commands:
sudo vi /etc/dphys-swapfile # change swapfile to 2GB
sudo raspi-config # expand the filesystem to use the entire SD card
sudo apt-get update #
sudo apt-get upgrade #
sudo apt autoremove # The following packages will be REMOVED: python-colorzero
sudo python -m pip install --upgrade pip # upgrade pip
sudo pip3 install --upgrade pip # upgrade pip3
sudo python3 -m pip install numpy --upgrade # upgrade numpy
sudo python3 -m pip install easyocr # install easyocr
I open a python3 editor and execute the following commands:
import cv2
import torch
import easyocr
reader = easyocr.Reader(['en'])
results = reader.readtext('/home/pi/Downloads/Calibration.bmp')
The last command results in an Illegal instruction error. I figured openCV was the likely culprit so I compiled it from source and tried again. I got the same error. I have tried going with a 32 bit build, but torch needs 64 bit to work. I have tried the same sequence and code through Anaconda on a windows 64 bit machine and it works without issue.
My next two attempts will be to build easyocr and/or torch from source , but I am grasping at straws here. I am really not sure how to figure out what software is causing the illegal instruction so I can hone in on that package. I would appreciate any thoughts on what I can do to get more information or thoughts on what things I can try.
Thanks a bunch.
[EDIT]I installed python3-dbg so I could run the application under gdb. When I do, the error I get is
Thread 1 "python3-dbg" received signal SIGILL, Illegal instruction. 0x0000ffffe4189fc8 in exec_blas () from
/home/[USER]/.local/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so
[EDIT2]I found a git hub repository that creates wheel files (WHL) for those having illegal instruction errors like me. So far it hasn't helped. I have tried a few, but am going to use a more systematic approach. to see if I can find the right combination.

pwntools Python module doesn't work in python2 but works in python3

I have a python2 script I want to run with the pwntools python module and I tried running it using:
python test.py
But then I get:
File "test.py", line 3, in
from pwn import *
ImportError: No module named pwn
But when I try it with python3, it gets past that error but it runs into other errors because it's a python2 script. Why does pwntools not work when I run it with python2 and can I get my script to run without porting the whole thing to python3?
Hard to say for sure but it looks like you installed pwntools for python3 and not for python2. Packages are not shared between python versions. if you run python2 -m pip install --user pwntools and then try to run with python2 does it work?
Yeah even I had faced this issue. Try installing pwntools using sudo pip install pwntools.

conda install opencv ImportError: the specified module could not be found

I installed opencv using the conda command:
conda install -c conda-forge opencv
The installation was successful without errors. Typing conda list also indicates opencv installed. But import cv2 gives the error: DLL load failed: The specified module could not be found.
I note the opencv does not show up in the Lib/site-packages folder, but occurs in the pkgs folder, that is, C:\\Anaconda\\Anaconda3.7\\pkgs\\opencv-4.1.1-py37h6afde12_1. The site-packages folder has a file cv2.cp37-win_amd64.pyd;
What is problem with the import cv2 error? Was the conda-based opencv installation really successful? My python version is python3.7.1.
A similar problem has been reported here DLL load failed error when importing cv2
Try to install with pip. 'pip install opencv-python'
Did you install the contribution packages of opencv?

gudhi python module installed but won't import

After importing the gudhi module like:
$ conda config --add channels conda-forge
$ conda install -c vincentrouvreau gudhi
import gudhi
gives import error. python2.7 is installed. Path variable lists the python path. What others have to be checked?
gudhi packages are only available for Python 3.6 for the moment.
I am working for them to be available on conda-forge, but I still have some compilation issue.
You can install GUDHI Python version by doing :
Install Miniconda (for instance) Python 3.6 x64 from here : https://conda.io/miniconda.html
In a command line :
conda config --add channels conda-forge
conda install -c vincentrouvreau gudhi
python
>>> import gudhi
Then you can try examples from documentation : http://gudhi.gforge.inria.fr/python/latest/
Regards,
Vincent Rouvreau

ImportError('Could not import PIL.Image. ' working with keras-ternsorflow

I'm following some lectures from lynda.com about deep learning using Keras-TensorFlow in a PyCharmCE enviroment and they didn't have this problem.
I get this error:
raise ImportError('Could not import PIL.Image. '
ImportError: Could not import PIL.Image. The use of array_to_img requires PIL.
I have checked if others get the same error, but for me installing pillow using pip with the command pip install Pillow doesn't solve anything.
MacBook-Pro-de-Rogelio:~ Rogelio$ pip install Pillow
Requirement already satisfied: Pillow in ./anaconda3/lib/python3.6/site-packages
MacBook-Pro-de-Rogelio:~ Rogelio$
Any solution?
All you need to do is install pillow:
pip install pillow
Then you should be all set. Found this after hours of searching.
I had the exact same error and I fixed it the following way:
1) Run this command in your Jupyter Notebook:
import sys
from PIL import Image
sys.modules['Image'] = Image
2) Run the following two lines in your notebook to be sure that they are correctly pointing to the same directory (if not it's because your PIL old library is messing up with the Pillow library)
from PIL import Image
print(Image.__file__)
import Image
print(Image.__file__)
3) If that's working correctly and both import prints pointing to the same python3 directory then move on.
If not:
3.a) Go to your OS console and to your conda environment (be sure you are working within your desire conda environment) :
conda uninstall PIL
conda uninstall Pillow
conda install Pillow
You should now have successfully installed all the libraries for Pillow and let behind any problems with PIL.
3.b) Now try to execute the code of your jupyer notebook again, now the paths to both the imports should look exactly the same
4) Now, in the OS console/terminal, having your desired conda environment active, run the following commands:
conda install keras
conda install tensorflow
5) Run your jupyter notebook script again, It should be fixed and working now!
If it's still not working, it must be because you have opened a jupyter notebook kernel that's not point to the right environment. Fix that and you will be fine!
If this problem is being seen on an Anaconda env,
use
conda install pillow
and reopen
I ran into a similar issue with keras + tensorflow + miniconda.
I followed this advice from this issue : https://github.com/asataniAIR/Image_DL_Tutorial/issues/4 and did a pip install in conda admin console.
So I enter
pip install --upgrade tensorflow keras numpy pandas sklearn pillow
on anaconda prompt, and add
from sklearn.preprocessing import LabelEncoder
in python code instead
from PIL import Image
Here's what worked for me. Uninstall the conda version of pillow and install the pip version, then restart the kernel of your Jupyter Notebook
conda uninstall --force pillow
pip install pillow
pip install pillow
This did it for me as well.
I am using Jupyter Notebook, and Tensorflow2.0 Keras. To set the context, I got this error when i was trying to use builtin image.load_img() function in Keras. You will have to restart your kernel as well after doing this install.
I encountered the same problem while working on Pycharm. Even after trying various methods on the internet, I could not solve it. When I ran the code on Jupyter notebook, it asked me to install the module, SciPy. I installed it and the code is now working on Pycharm.
I have the same problem good news is it can be easily solvable.
my problem was:
I was using jupyter notebook for my python project which was launched using Anaconda navigator. In the python program I was using the function
image_ = image.load_img(image_path, target_size=(224,224))
then I got this error "raise ImportError('Could not import PIL.Image. ' ImportError: Could not import PIL.Image."
solution worked for me:
in the environment you are using for jupyternotebook firstly uninstall pillow using the command
conda uninstall --force pillow
then install it using the command
pip install pillow
(type these commands in the anaconda prompt)
then close all your notebooks and anaconda navigator, open anaconda navigator with the environment that you have installed before, in that environment launch the jupyter notebook and run the code
it will work
I had the exact same question. And I fixed it by changing my environment variables. Because I had two versions of python in my windows PC.
So I changed the priority, and moved the python 3.x version at the top position.
Then I reinstalled the pillow, and the problem was solved.
if pip and conda installing is not working for you try to:
pip3 install pillow
and then:
from PIL import Image
It should work! Check your python version and which one are you using as default! :)
Using a conda environment run conda install pillow. If you're using Jupyter notebook, don't forget to restart the Kernel.
This just worked for me.
If anyone wondering the above-mentioned process can be implemented using anaconda navigator.
Open the navigator, go to the Environments tab you are currently working and search pillow from the uninstalled tab before the search tab (if it's not installed in the current environment you are working)
Then select pillow and apply. Install then.
After that go to Home tab and launch Spyder.
If your using Anaconda 3, u have to install Pillow in the environment that your working on. just go to the not install section and search for Pillow, then install it to the environment. This way will nail the problem for you.
Install these:
$ pip install pillow -U
$ pip install pathlib -U
It may be a version issue, I had this issue with TensorFlow 3.2.0 and setting pillow to 8.2.0 worked for me somehow along the way of uninstall/reinstall/restart.

Resources