I am unable to install cv2 from pycharm package installer - python

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.

Related

Packages installed via Pip do not get imported in Python VSCode [Windows 10]

Trying to install new packages via pip on Windows, but after it installs - Python cannot resolve the import. For Example, I have just installed the Python package similaritymeasures and pip correctly installed it, but when I import it into my Python program, it cannot find the import. Has anyone know a way around this?
Make sure that you restart VSCode after downloading your package. Sometimes, when you download a package while VSCode is still running, it doesn't recognize the package when using import similaritymeasures.
If that didn't work, then make sure that VSCode is using your preferred version of python. It is possible that you have more than one python version and it's using a non-compatible one to run your code. This can be done at the bottom right corner of the window by clicking the box that says: (for example) 3.9.5 64-bit. Then select a different (preferably older) version from the pop up widnow.
These are the solutions that came to my mind, I hope this helped.

Installing and using npTDMS with Spyder - anaconda3

I have successfully installed npTDMS as seen here:
https://pypi.org/project/npTDMS/
If I try to install with command line using either pip or conda I get a message confirming it is already installed, and I see the package at D:\Users\username\anaconda3\pkgs.
On Spyder I have tried using the PYTHON path manager (in the tools menu) to add both:
D:\Users\username\anaconda3\pkgs\nptdms-1.2.0-pyhd8ed1ab_0
D:\Users\username\anaconda3\pkgs\nptdms-1.2.0-pyhd8ed1ab_0\site-packages\nptdms
As far as I understand this should be enough to use the npTDMS package, however when I try to import I get a ModuleNotFoundError: No module named 'nptdms'.
I'm fairly new to python overall so maybe there is a simple thing I am missing.
This issue comes when there are multiple versions of python or any package you are running at current time. The same issue was with me too when the IDLE was not able to detect the position of where the package is installed.
My suggestion is that uninstall all the versions of python and the module you are using and install them again. Otherwise shift to any other IDLE, in my recommendation - Visual Studio Code.

Why I can't import cv2 and other modules to python

I have problem with importing some modules into python.
First of all, I am on MacBook, it's my first OS X device, so maybe I did something wrong.
I installed conda, created main. Everytime I want to work on my python app, I just open terminal, use command: conda activate main, cd into folder and open in VS code. I used pip3 install opencv-python to download this module, It was completed without errors but when I import everything into python file (cv2, tensorflow, matplotlib.pyplot and numpy) and I just
try to print Hello, I get this error:
Traceback (most recent call last):
File "/Users/zacikm/dev/Python/BC/main.py", line 1, in <module>
import cv2 as cv
ModuleNotFoundError: No module named 'cv2'
Please, help me what can I do to fix this problem. I want to start working on my school project but I'm not able.
Thanks!
Sure.
Picture when I run "pip install opencv-python" under conda env.
Error message what I get after running my code.
Check are you using the right environment after installing the pkg pip install opencv-python.
For example, you are using base python rather the conda one.
Say your conda environment is called test.
You need to run
conda activate test
Then use
pip install opencv-python
to re-install it for this environment. Then you can use cv2 in this test environment.
I had the same problem. I found that the solution was to downgrade the opencv version. In Pycharm, the process is as follows:
In Preferences, go to Python interpreter. You will see the current versions of opencv-contrib-python and opencv-python which may be the same as the latest version.
That is the problem.
Double click on the current version of opencv-contrib-python to open this screen:
Check the specify version checkbox and find version 4.1.2.30. Then click Install Package and wait a few seconds to get a message that package was successfully installed. Press OK and you should see opencv-conbtrib-python downgraded to the appropriate version.
After step 3, opencv-python may have also downgraded to the appropriate version 4.2.0.34. If it hasn't, follow the same process to downgrade opencv-python to 4.2.0.34. At the end, your python interpreter screen should look like this:
That should do it. Test it to make sure it works.

Problems with installation of Pillow

I am running Python 2.7.1.1 with Anaconda2 4.0.0 64-bit on a Windows 7 machine. I'm trying to install Pillow for imaging, and after having read through every thread I could find, I am still unable to reach a solution. I have installed and uninstalled Pillow through various means including:
pip install Pillow
conda install Pillow
easy_install Pillow
I've gone to the Anaconda site-packages list and, lo and behold, the package for Pillow-3.2.0-py2.7.egg-info exists.
I've tried importing the package through both:
import Image
from PIL import Image
But I encounter the following ImportError:
from PIL import Image
ImportError: No module named PIL
I've already uninstalled the original PIL library that I tried to install to ensure that only the Pillow package exists. Any help would be greatly appreciated!
It sounds like Anaconda isn't playing nice with your system due to the fact that you have two interpreters installed (Anaconda's and Python 2.7.1.1). I would remove everything (Python, Anaconda, etc) and either reinstall Anaconda fresh, or the get the newest version of Python from python.org (2.7.12).
Personally, I'd go for the Python 2.7.12 from python.org (I've always had issues with prepackaged distros like Anaconda).
If you go that route, after your environment is clean I would make sure Pip is all up to date (pip install pip --upgrade) and then install Pillow from whl file provided by the University of California Irvine.
To do that, just go here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Download the Pillow whl file for Windows 64bit. Make sure Python is set up in your path and then just go to the directory where you downloaded Pillow and enter the following (replacing the filename with the one you downloaded):
pip install pillowfile.whl
good luck, and happy coding!
If you can't import a package into Python but it is definitely there in the site-packages folder, then you are more than likely running the wrong Python interpreter.
You can check this by running python from the command line and then entering:
import sys
sys.executable
That will return a string pointing to the current running Python interpreter.
Wrong Python
If that doesn't point to your Anaconda installation then you have a paths problem.
On windows you can set the PATH through My Computer / Properties / Advanced. Look at the Environment Variables and ensure that the Anaconda path string is before any other Python path (If the Anaconda path isn't there, then something is very messed up and you may want to simply re-install Anaconda).
Right Python
If the path returned by sys.executable is correct then the installation of Pillow must be broken somehow. You can try un-installing and then re-installing. As an absolute last-resort you could also try deleting the Pillow folder manually and re-installing it.

PyCharm does not recognize cv2 as a module

I am using OpenCV 3 and python 2.7 and coding using PyCharm. The code works fine but PyCharm does not recognize cv2 as a module. It underlines it with a red line, so it doesn't display its functions in the IntelliSense menu.
I tried to set an environment variable OPENCV_DIR but it didn't work
OpenCV is extracted in F:\opencv and Python is installed on C:\Python27
What is wrong?
here are proper instructions if you have not built opencv from source so that everyone can follow it
Click File menu > Settings
Search " Project Interpreter " in search bar
Click that + button to install packages or press Alt+Insert
now Available packages window will open and then search for " opencv-python " and click install package button.
enjoy and do +1
Try File->Invalidate Caches / Restart...
I can't say definitively why this works, but it may have something to do with the cached module definitions that PyCharm uses to provide code hints. In some cases they aren't updated or get corrupted. I just know that it's worked for me.
I've solved this problem. Hope this works for you also.
from cv2 import cv2
https://stackoverflow.com/a/61242587/8423105
Worked on Pycharm 4.0 version
Follow these steps:
Go to File>Settings in Pycharm IDE Window
Search Project Interpreter in search bar.
Click on any package from the available options
Package window will open from where you can install any packages.
I have installed opencv-python package to run opencv commands
Follow the link How to install OpenCV on Windows and enable it for PyCharm without using the package manager
Steps to follow:
Install Python 2.7.10
Install Pycharm(If you have not done it already)
Download and install the OpenCV executable.
Add OpenCV in the system path(%OPENCV_DIR% = /path/of/opencv/directory)
Goto C:\opencv\build\python\2.7\x86 folder and copy cv2.pyd file.
Goto C:\Python27\DLLs directory and paste the cv2.pyd file.
Goto C:\Python27\Lib\site-packages directory and paste the cv2.pyd file.
Goto PyCharm IDE and goto DefaultSettings>PythonInterpreter.
Select the Python which you have installed on Step1.
Install the packages numpy,matplotlib and pip in pycharm.
Restart your PyCharm.
PyCharm now has OpenCV library installed and working.
I have the same problem and I'm afraid that there isn't a solution for this at the moment. You can read more about the issue here
The problem is that OpenCV doesn't include the needed .py file to have the autocomplete which might be why PyCharm isn't picking up the package as well.
To be sure that we are on the same page, when you go File>Default Settings>Default Project>Project Interpreter and select the python 2.7 interpreter, does it list cv2 or opencv in the packages?
EDIT: I was able to get it working with anaconda instead of python. Just instaled anaconda and did everything the same as I would with python (copied cv2 where it would be in python). Hope it helps you!
Installing opencv-python package from pycharm setting worked for me.
I follow the steps in the webapp response and after that It does not work and I decided to reinstall the pycharm IDE, this works for me.
Hope it helps.
Just install opencv python package from settings.
What ended up working for me was uninstalling the package from pip and installing it from my package manager (apt):
python3 -m pip uninstall opencv-python
sudo apt install python3-opencv
You can install your existing libraries to pycharm by enabling the button "Inherit global site-packages" while creating project.
If you don't have installed libraries then you can install it by going to File>Settings>Project:your project name>project interpreter and then install your required package by searching that.
After installing OpenCV with pip and then pip3 in terminal. It would import when writing python in terminal, but not in PyCharm. I tried the invalidation of cache mentioned above, and it worked for a min until cache was warmed up. Same result....
I fixed it by going to:
PyCharm Menu
Preferences
Project (proj name) -> Project Interpreter
(this time instead of CV2)
Plus sign (to install packages)
searched for opencv-python
installed the package
I didn't even have to dot off that library, it then accepted the
"import cv2"
Just:
pip install opencv-python
solved for me on Windows and Linux.
While Installing pycharm,dont select virtual environment unless u want it,If you select it ,then it will create a venv file and you need to import all the module by command prompts.Tick the existing interpreter,it will make everything easy.

Categories

Resources