Python Forum
python and openCV installation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python and openCV installation
#1
Hello!
I'm new to the world of python, struggling to understand all different versions, types of installations and environments.

My OS is Windows 10 Pro. My goal is to get the python-version of the module "adaptive bilateral filter" from opencv running (https://docs.opencv.org/2.4/modules/imgp...eralfilter).

A few days ago, I sucessfully ran the "bilateral filter" (https://docs.opencv.org/2.4/modules/imgp...eralfilter), using sublime texteditor 3. However, the adaptive filter couldn't be found/was unknown. So I checked the openCV version and it said 3.4. So I figured that in order to get the adaptive filter running I need to updgrade to opencv-version to 4.x, or I need the opencv-contribute files (https://github.com/opencv/opencv_contrib).
Since then, I tried to reach my goal following various guides on the internet - many using e.g. Anaconda and/or pip - but all I achieved is that my system is messed up now. Right now, a python-script with the line "import cv2" causes a "ModuleNotFoundError: No module named 'cv2.cv2'".

Could somebody be so kind to guide me through the process of sorting this out? I believe that a "start from scratch" is absolutely necessary!

Thank you very much.
Reply
#2
dejhost Wrote:I believe that a "start from scratch" is absolutely necessary!
Look at this Python 3.8 (3.6-3.7) and pip installation under Windows
On PyPi opencv-python 4.2.0.34,so from cmd it shall work like this.
# Python interpreter you point to in Editor
C:\>python -c "import sys; print(sys.executable)"
C:\python38\python.exe

# Test pip
C:\>pip -V
pip 20.1.1 from c:\python38\lib\site-packages\pip (python 3.8)

# Install
C:\>pip install opencv-python
Collecting opencv-python
  Downloading opencv_python-4.2.0.34-cp38-cp38-win_amd64.whl (33.1 MB)
     |████████████████████████████████| 33.1 MB 6.8 MB/s
Collecting numpy>=1.17.3
  Using cached numpy-1.19.0-cp38-cp38-win_amd64.whl (13.0 MB)
Installing collected packages: numpy, opencv-python
Successfully installed numpy-1.19.0 opencv-python-4.2.0.34

# Test that it works
C:\>python
>>> import cv2
>>>
>>> cv2.bilateralFilter
<built-in function bilateralFilter>
>>>
>>> help(cv2.bilateralFilter)
Help on built-in function bilateralFilter:
Reply
#3
Hello Snappsat,
I am really grateful for your advice.

I installed as instructed:
Output:
pip 20.1.1 from C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pip (python 3.8)
Output:
Requirement already satisfied: opencv-python in c:\users\xxx\appdata\local\programs\python\python38\lib\site-packages (4.2.0.34) Requirement already satisfied: numpy>=1.17.3 in c:\users\xxx\appdata\local\programs\python\python38-32\lib\site-packages (from opencv-python) (1.19.0)
Now, the "interesting" part:
>>> import cv2
Output:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\Lib\site-packages\cv2\__init__.py", line 3, in <module> from .cv2 import * ModuleNotFoundError: No module named 'cv2.cv2'
I assume that this needs to be fixed through Envornment Variables? My "Path" - variable looks like this:
[Image: vqVYtSm]

If this should be the source of the troubles: how to fix?
Reply
#4
You have now two paths to python,as pip now show Python\Python38-32
Then delete all other paths show in image expect these two.
C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\
C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\Scripts\
Restart pc,then try again.
Reply
#5
This is what my Path- environment variable looks like after the restart:
[Image: YBpwbMw]

And this is the output of python:
Output:
>>> import cv2 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Jost\AppData\Local\Programs\Python\Python38\Lib\site-packages\cv2\__init__.py", line 3, in <module> from .cv2 import * ModuleNotFoundError: No module named 'cv2.cv2'
Reply
#6
Video 
When you open Environment Variables first Window.
There is User variables and System variable(has highest priority).
Go also into System variable Path and make sure that only version poster over is there.
And leave all other variable alone in System variable Path,delete so only has one Python version as mention.
[Image: win10-envirvariables.jpg]
Restart Pc.
Reply
#7
Hello Snippsat,
This is how my System variable "Path" looks like:
[Image: 8MmCLKH]

No improvment, I'm afraid. I get the same error as previously :-(
Reply
#8
That's strange,make sure you restart Pc.
Start cmd and do this.
Microsoft Windows [Version 10.0.18362.900]
(c) 2019 Microsoft Corporation. Med enerett.

C:\Users\Tom>cd ..

C:\Users>cd ..

C:\>python -c "import sys; print(sys.executable)"
C:\python38\python.exe

C:\>pip -V
pip 20.1.1 from c:\python38\lib\site-packages\pip (python 3.8)

C:\>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>>
>>> sys.executable
'C:\\python38\\python.exe'
>>> exit()

C:\>
To copy text in cmd(Right click,Mark all) then <Enter>.
Then can use code tag as i have used over here and not image.
Also do echo %PATH% in cmd and see if you still see path to the other version.
Reply
#9
Good morning :-)

I had the PC restarted after changing the variables.

C:\>pip -V
pip 20.1.1 from C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pip (python 3.8)

C:\>python
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'C:\\Users\\xxx\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe'
>>> exit()

C:\>echo %PATH%
Output:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin; C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\libnvvp; C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin; C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\libnvvp; C:\Windows\system32; C:\Windows; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0\; C:\Windows\System32\OpenSSH\; C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common; C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR; C:\Program Files\Git\cmd; C:\Program Files\Microsoft SQL Server\130\Tools\Binn\; C:\Program Files\MATLAB\R2018a\runtime\win64; C:\Program Files\MATLAB\R2018a\bin; C:\Program Files\CMake\bin; C:\Program Files\dotnet\; C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\Scripts\; C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\; C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\Scripts\; C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\;
Reply
#10
Now do all look correct.
Do this.
pip install opencv-python --upgrade
Then test that it work.
C:\>python
>>> import cv2
>>>
>>> cv2.bilateralFilter
<built-in function bilateralFilter>
>>>
>>> help(cv2.bilateralFilter)
Help on built-in function bilateralFilter:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with using opencv in python Raunak1023984765 21 1,744 Feb-21-2024, 04:25 PM
Last Post: Pedroski55
  Python installation for old MacOS Yonix 1 498 Sep-21-2023, 03:32 PM
Last Post: menator01
  Installation of packages to newest Python version from previous one Andrzej_Andrzej 3 846 Jul-15-2023, 11:32 AM
Last Post: snippsat
  How to see the date of installation of python modules. newbieAuggie2019 4 1,639 Mar-31-2023, 12:40 PM
Last Post: newbieAuggie2019
  Getting "SSL client not supported by this Python installation" error prabirsarkar 0 966 Mar-13-2023, 05:01 PM
Last Post: prabirsarkar
  python installation/running inside singularity container erdemath 2 1,807 Sep-21-2022, 08:13 AM
Last Post: erdemath
Question Python V3.11 Installation Help Danno 2 1,109 Aug-11-2022, 02:30 AM
Last Post: Danno
  Help for the shortest way to install a suitable version of Python, Numpy, and OpenCV. Ezzat 2 2,303 Dec-23-2021, 12:34 PM
Last Post: snippsat
  Python OpenCV window not opening in fullscreen mode Zman350x 0 3,312 Apr-29-2021, 07:54 PM
Last Post: Zman350x
  Portable installation of Python possible? pstein 2 3,099 Nov-15-2020, 12:14 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020