How to import opencv in python (not from virtualenv) [UBUNTU] - python

I have problem about importing OpenCV to my project.
Not actually problem, but I didn't find how to do that. I know it's trivial, but I really don't know.
I have opencv downloaded and compiled in my home directory.
I know how to import it in virtualenv, but how to import it directly from original - non virtualenv python2.7?

To import opencv in your python project import cv2

Related

import rpy2 but can not import rpy2.robjects when changing start folders

The Current problem I am looking into is described below:
My computer is Win10, I installed only one anaconda 3.5.3 on it. Using where python there is only one python in my computer.
I downloaded a rpy2python wheel file from the uefi website, and install that using pip install.
When I import rpy2 in C disk, it is already fine, import rpy2,import rpy2.robjects are all OK.
But when I import rpy2 in my own project, I can only first import rpy2, when I import rpy2.robjects,the program says can not find rpy2 module.
Finally I found the problem is that in my project, I occasionaly established an rpy2.py file, when I first import rpy2, it where automatically create an rpy2.pycache folder, secondly when I import rpy2.robjects, Of Course the computer can not find an rpy2.robjects.
Just Keep a track of my problem.
You'll want to check the Python documentation about import rules for modules. By default, having a file called rpy2.py in the working directory for your Python code will cause import rpy2 to find this one rather that the rpy2 package.
The easiest fix is probably to rename your module rpy2.py into something else.

How to force python to import only a specific version of OpenCV?

I need to install a specific version of OpenCV. How do I do this at the import stage?
I've seen some people use this method on other packages, and I tried to replicate for opencv, but it did not work... what's the correct statement for this method?...
import pkg_resources
pkg_resources.require("OpenCV==3.3.1")
import cv2
print('OpenCV version: ', cv2.__version__)
You can just install a different version of OpenCV on https://opencv.org/releases/ and then put it into python...

How to import cv2 in python project "Visual Studio 2015"?

I would like to start with OpenCV . I followed some tutorials for installing OpenCV in Windows.
After downloading and extracting OpenCV
First, I create environment variable and path
Then I moved to python in Visual Studio. I installed python and I started with a very simple tutorial, but I faced some problems with python.
First problem was with numpy module was not found. solved
cv2 error I couldn't solved it, I followed instruction said that I need copy cv2.pyd file in ..\Python34\Lib\site-packages
afterword I tried to >>> import cv2
but I got this error
Thanks for all of you.

'ImportError: No module named pillow' in PyCharm

I'm getting an error while using PyCharm which doesn't allow me to import the pillow module even though I have it installed as a package in the project interpreter. Any help is greatly appreciated!
http://imgur.com/a/DfjC3
While the name of the package is pillow, it is a replacement for PIL and uses the PIL for the name of the base module
the usual way to use pillow is
from PIL import Image
im = Image.open("filename")
See the tutorial, and the documentation
You try to run code with default Python interpreter (/Library/Frameworks/Python.framework/Versions/3.2/bin/python3). You need to configure PyCharm to run Your code with anaconda (~/anaconda/bin/python)
And now (Like #JamesK say) read Pillow tutorial and documentation:
import PIL not import Pillow
For anybody still having trouble with this, I did the following which solved my problem.
Open up your Project Interpreter (⌘ + , on Mac).
At the bottom of this page you'll see the + symbol to the left of the anaconda logo. This will create a pop-up that allows you to search for available packages.
In this new window, search for 'Pillow'.
Click and Install Package.
You should now be able to use "from PIL import Image" or "import Pillow as pil" etc.
After running this command on your terminal
pip install pillow
and you are sure it was installed, but still having same problem of PIL module not found.
Go to your IDE and make sure existing interpreter is set to python interpreter and not anaconda

Importing OpenCV with python 2.7 in Virtualenv and PyCharm

I am struggling with installing opencv for python 2.7.11 on OSX for almost three days now.
After some failures, I accomplished a first success by following the instructions here. So my basic setup is python 2.7.11 running from ~/.virtualenvs/cv_env/bin/python and I have a cv2.so located in ~/.virtualenvs/cv/lib/python2.7/site-packages/.
So good so far. Using source ~/.virtualenvs/cv_env/bin/activate, I can activate the virtualenv and than use import cv2. For some reasons, this does not work always. From time to time, I have to deactivate first and than reactivate (any guesses?).
Next, I wanted to use opencv in PyCharm. Under "preferences - Project interpreter", I selected the virtualenv interpreter and this is also working. I can import other moduals like numpy and pandas (previously installed into the vortualenv using pip). But for some reasons, I am not able to import opencv (import cv2). It always gives me
ImportError: No module named cv2
So my question is, why I am able to import opencv in terminal (at least sometimes) but not in PyCharm. Any ideas are welcomed.
Best,
Fabian
Your cv2.so located in a different directory. And you activating from another directory. I mean cv_env and cv.

Categories