Cannot import cv2 on PyCharm - python

I am trying to import cv2 module in PyCharm, but it shows error.
I tried in terminal as well
pip install opencv-python
pip3 install cv2
pip install opencv-python
pip3 install cv2
and whatnot.
Trying to install opencv-python from terminal shows this
Requirement already satisfied: opencv-python in ./anaconda3/lib/python3.6/site-packages (3.4.1.15)
and trying to install cv2 from terminal shows this
Could not find a version that satisfies the requirement cv2 (from versions: )
No matching distribution found for cv2
However, trying to import cv2 on Pycharm shows this :
Pycharm Error Image

First, install the package named opencv-python via pip install opencv-python or use the GUI.
Second, just input import cv2; that is ok.

Go to File->Settings->Project Interpreter and then add by '+' button 'opencv-python' module on this repository.
It downloaded without an error for my PyCharm and also downloaded the dependencies as well.

While creating a new project in PyCharm, please select 'Base Interpreter' option from drop-down similar to the one shown in this link:
Creating new Project stage
Next, after successful creation of project and after downloading the opencv-python, it looks a shown in this link:
Success message

Related

ModuleNotFoundError: No module named 'rosbag' with pip

I am trying to install rosbag using pip:
pip install python-rosbag
But I am getting the following error:
(base) C:\Users\santhoshe.e\annotator-master>pip install python-rosbag
Collecting python-rosbag
ERROR: Could not find a version that satisfies the requirement python-rosbag (from versions: none)
ERROR: No matching distribution found for python-rosbag
How can I install rosbag in windows other than using pip? Or the pip I used is wrong?
pyrosbag is actually a different package from rosbag.
The right way should be
conda install -c conda-forge ros-rosbag
After that, you can run import rosbag in Python.
I think it should be this:
pip install pyrosbag
Try this to install pyrosbag using pip:
pip install pyrosbag
Now in the docs, the Usage page shows the import command as:
import pyrosbag
I would suggest to install ros noetic (I installed the desktop-full version).
See link: http://wiki.ros.org/noetic/Installation/Ubuntu
If you then source the setup script for ros via the following command:
source /opt/ros/noetic/setup.bash
Python should be able to import rosbag.
Actually for rosbag, it is not very easy to install by using pip.
However you can use installation steps defined in ROS wiki.
But it is not done after installing rosbag, you should also add PYTHONPATH for the rosbag in your interpreter. Which can be done by simply selecting File>Settings>Project Interpreter and click the gear right next to your interpreter.
After that you will see two options : Add/ShowAll. Go with Show All and on the window that opened, on the right hand side, you will see +,-,..., a symbol that shows the paths for the selected interpreter (the symbol listed at the end)
Under these paths you should also define the path that you installed ros. For me, the path is :
/opt/ros/melodic/lib/python2.7/dist-packages

I am unable to install cv2 from pycharm package installer

I am unable to install cv2. I import it to my python version using pip through my terminal but I continue to receive this error during my pycharm import. :
Collecting cv2
Could not find a version that satisfies the requirement cv2 (from versions: )
No matching distribution found for cv2
I have tried to import and install through pip multiple times but it does not appear as an available package for download in my pycharm interpreter.
I expected the module to install once I installed and imported through pip but it is saying that the requirements are already met and that there is nothing missing in my pip.
Based on what i have understood, you have correctly installed the python package via pip, but you are not able to use it inside PyCharm.
This happen when you didn't select the correct Python Interpreter inside Pycharm.
In order to fix this issue, you should open PyCharm and go to:
Settings->Project->Project Interpreter
Here, you should see the current interpreter with all installed python packages.
At the top of the window, there is a list which contains all local interpreters.
If you find the virtualenv or the python installation in which you have installed cv2 in the list select it, otherwise, in the right corner of the window, there is a settings icon; press it and press on Add local.
After this navigate in your computer and select the directory that contains the virtualenv or python installation in which you have installed cv2.
At this point, you should use the correct virtualenv or python installation, so should be able to import cv2 without problems.

Attempting to install Python PIL module fails with "Non-zero exit code"

I really don't get why Python is so difficult to get up and running properly.
Anyway, I've just fresh installed Python 3.7 and PyCharm. I want to get the Python Imaging Library working within my project, but when I try to install it using PyCharm I get the following error:
pip install PIL
Non-zero exit code (1)
Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at 'C:\Users\Jake\AppData\Local\Programs\Python\Python37-32\python.exe'.
Command output:
Collecting PIL
Could not find a version that satisfies the requirement PIL (from versions: )
No matching distribution found for PIL
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
I've attempted to run python -m pip install --upgrade pip from a CMD prompt, but I then get this error:
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
I just tried to install NumPy using the exact same method for PIL and Numpy installed without any issues whatsoever. This leads me to think that maybe PIL isn't supported for Python 3.7?
Can someone explain to me what the issue is here and help me with importing modules into my PyCharm project?
PIL is not maintained anymore. You can use Pillow instead, a more active fork of PIL.
pip install Pillow

Unable to install cv2 on windows

I am trying to install opencv in python on my windows machine but I am unable to do so. I have python 2.7.11::Anaconda 2.4.1 <32-bit>
Here is what I have tried till now -
pip install cv2 on command line gives the error :
could not find a
version that satisfies the requirement cv2
I downloaded the package from sourceforge site, followed the steps
and pasted cv2.pyd in C:\Python27\Lib\site-packages but still it is
not working. I get the following error message
ImportError: No
module named cv2
(I already have numpy installed and it works just fine).
pip install opencv-python
you can type this instead of
pip install cv2
it also works with anaconda pro
I was able to solve the error.
If you are using python version 3 , sometimes you have to use pip3.
pip3 install opencv-python
Make sure you are using python 3 , it won't work for python 2.
Try
pip install opencv-python==4.3.0.36
So I was using PyCharm, and what worked for me was to install it directly from file->settings, Project:your-project-name->Python Interpreter list

pip install PIL fails

I am trying to install the pip package PIL. However the install doesn't work throwing the following error.
Could not find a version that satisfies the requirement pil (from xhtml2pdf==0.0.4->-r virtualenv-reqs.txt (line 16)) (from versions: )
Some externally hosted files were ignored as access to them may be unreliable (use --allow-external pil to allow).
No matching distribution found for pil (from xhtml2pdf==0.0.4->-r virtualenv-reqs.txt (line 16))
The install does work when I have an older version of pip, but with the current version of pip 7.1.2 I am not able to download the package. I am using the following command to install the pip packages
pip install --timeout=1000 -i http://pypi.ksjc.sh.colo/simple --trusted-host pypi.ksjc.sh.colo -r virtualenv-reqs.txt
What is the issue with this. I thought it might be an SSL issue which is why I added the --trusted-host flag. Is there any way to the --allow-external flag to be used with the virtualenv-reqs file.
Pillow is a maintained fork of PIL, so I recommend using Pillow. But you can't have both installed at the same time.
First, remove both PIL and Pillow.
Then install Pillow with pip install pillow (although, depending on platform, you may need some prerequisites).
Then make sure code is using from PIL import Image rather than import Image.
You can try using Pillow instead, which is a PIL fork:
pip install Pillow
To import use following:
from PIL import Image
One solution that worked for me:
By simply installing the latest version of Pillow using pip install -U Pillow I can now call import PIL.Image
I'm using PyCharm IDE, and I had this problem. I simply hovered my mouse to the 'PIL' and there's a small pop-up. I clicked more actions and several options appear. I clicked 'Install Pillow, and then, problem solved.
One solution was, right-click on 'from PIL import Image' and click
'install Image'
I was on the PyCharm IDE.

Categories

Resources