Python Import Error, Symbol not found: _iconv Referenced from: - python

I've successfully running Python 2.7.15 (default one) on macOS Sierra 10.12.6.
I have also installed OpenCV using pip of version 3.4.0, using this tutorial.
Screenshot: Python IDLE Screenshot showing OpenCV version on macOS
When I try to import cv2 from python IDLE it gets successfully imported, but when I try import cv2 from a python script and run as cgi script, it shows the following error:
Error Screenshot: OpenCV import error while importing and running from browser
What does the error actually mean?
How can I solve this?
Note: I've no errors while running python as CGI scripts (without importing opencv).
Note: I've even tried of installing OpenCV using Homebrew but it still produces the same error while importing OpenCV as a CGI script.

Very common error with OpenCV, the best move you can do is to install OpenCV using Anaconda.
I recommend you to fully uninstall Python and install Anaconda Python, it comes with the conda package manager that will allow you to install opencv--python easily.
https://www.anaconda.com/download/
Once Anaconda Python is installed, try the following commands:
conda install -c conda-forge opencv
conda install -c menpo opencv3

Related

Ubuntu terminal crashes while installing python package

I am trying to install mmcv python package, but Ubuntu terminal crashes every time during installaction (application simply closes without any errors). I tried to install this package both using standard Linux terminal and via VS Code - the result is always the same. It causes no errors when I install other python packages, but when I try to install mmcv - terminal crushes.
I am using this code for installation:
pip install mmcv-full==1.3.9 -f https://download.openmmlab.com/mmcv/dist/cu117/torch1.13.1/index.html
I tried to install mmcv using this code in Kaggle Kernel (it is Jupyter Notebook-like development environment, which works on Linux too) - and package was installed correctly.
It seems to me that my terminal crashes because mmcv is quite "heavy" python package, but I do not know what to do with it. How can I solve this problem and install mmcv?
It seems like my version of Ubuntu is not compatible with old versions of mmcv.
This code worked for me:
pip install -U openmim
mim install mmcv-full==1.5.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

How to import OpenCV into python

I have downloaded Anaconda on my Windows PC, and I have been using Spyder IDE. Now I want to do a project with OpenCV.
However, I have tried to install OpenCV using the Command Prompt and typing the following in:
pip install opencv-python
This only gives an error message and says "pip" is not recognized as a command.
Furthermore I tried to import OpenCV into Python using the following:
import cv2
This also doesn't work
I would appreciate any help in getting OpenCV working.
It depends on Your OS. Check Your pip installation with cmd: pip -V and check python with: python -V
It seems like You don't have pip installed at all.
Than import cv2 should work.

import dlib ModuleNotFoundError: No module named 'dlib' in python IDLE

I have installed dlib using Anaconda 3 prompt.
It has shown me that it got installed successfully. I checked through command import dlib it did not give me any error even I checked the version also it came up with 19.9.0.
But when I open my program in IDLE and run the program its showing me error
import dlib ModuleNotFoundError: No module named 'dlib'
Even from command prompt, I am getting same error.
What is the issue? I am using Python 3.6.
Installation process of dlib using anaconda3:
You have installed the package in different version of python and importing the package in other version of the python.
Package is installed. in virtual environment(3.6.8) and is being imported in standard system python (3.6.0).
So either you need to use this virtual environment for your application otherwise you will need to install the package into global system python.
Extending #Rohit's answer:
As you have installed dlib in Anaconda, you need to run the program using Anaconda prompt.
By default, IDLE and python command in command prompt use Python that is installed system wide (which is Python 3.6.0 in your case).
But to use dlib which is installed in Anaconda's virtual environment (env_dlib) you need to do:
Open Anaconda prompt.
Activate env_dlib environment: activate env_dlib
Run the Python file which uses dlib package: python FILENAME

py-opencv import error in Bash for Windows 10

I installed py-opencv in Bash for Windows 10 using Anaconda:
conda install -c conda-forge opencv
But when I import it in my Python3 interpreter, I get the following error:
ImportError: libopencv_reg.so.3.1: cannot enable executable stack as shared object requires: Invalid argument
It works fine on my Ubuntu machine so I figure this is a bug with Bash for Windows 10. If anyone has a work around it would be great.
Probably you have already found a solution, given the time that passed since you asked the question.
I faced the same problem and the solution in my case was installing opencv-python, which makes the bindings between OpenCV and Python. To install use the command sudo pip install opencv-python.
Works in the latest Windows build.

installing opencv for python in Ubuntu 14.04

I ran the following command on terminal
$ sudo apt-get install libopencv-dev python-opencv
This installed opencv version 2.4.10.
After that I open python in terminal and try to import opencv as follows
>> import cv2
This gives me an error :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
I also tried using import cv, import opencv, etc. but I am getting the same error.
Do I need to follow some more steps to configure opencv for python ??
This happens when python cannot refer to your default site-packages folder where you have kept the required python files or libraries
Add these lines in the code:
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
or before running the python command in bash move to /usr/local/lib/python2.7/site-packages directory. This is a work around if you don't want to add any thing to the code.
OR
try adding the following line in ~/.bashrc
export PATH=/usr/local/lib/python2.7/site-packages:$PATH
This happens when python cannot refer to your default site-packages folder where you have kept the required python files or libraries
Add these lines in the code:
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
or before running the python command in bash move to /usr/local/lib/python2.7/site-packages directory. This is a work around if you don't want to add any thing to the code.
There is an installer for Ubuntu 16.04, and it may work well on Ubuntu 14.04, you could have a try. I have used it to install on Ubuntu 16.04 and it succeed!
An interactive installing script for install openCV on Ubuntu 16.04 LTS
The Opencv version(2.4.10) installed is for python2x version.
I think you are trying to use cv2 in python3x version (which might be set as default for python)
Open python2 on terminal (use command python2 instead of python)
>> import cv2
This will work.
I think it is better that you just install Anaconda python distribution.
https://www.continuum.io/downloads
You can find wealth of tutorials in the internet on how to install it in your system. And trust me, it is VERY EASY to install.
After you have install your Anaconda python distribution, you can install OpenCV 3.1 by the following commands. Note that you should have an internet connection.
# if you are using Anaconda for Python 2.7
conda install -c menpo opencv
The above code should install OpenCV 3.1 in your anaconda python 2.7
# if you are using Anaconda for Python 3.5
conda install -c menpo opencv3
The above code should install OpenCV 3.1 in your anaconda python 3.5
Then to verify that you have successfully install OpenCV 3.1 in your system, you can issue the following command in the python interpreter:
# import the opencv library
import cv2
# prints the version of the OpenCV installed in your system
cv2.__version__
That's it. I hope that helped you =)
Try using this:
sudo apt-get install python-opencv opencv-dev python-numpy python-dev

Categories

Resources