Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
numpy help
#1
I am trying to import cv2 for OpenCV. But its not working. Giving me the following error. I guess Numpy and OpenCV is installed in two different location. How do I move Numpy to c:\python\python38\lib\site-packages folder? or How can I solve this problem? How can I install OpenCV? Please help me.

Requirement already satisfied: opencv.python in c:\python\python38\lib\site-packages (4.4.0.46)
Requirement already satisfied: numpy>=1.17.3 in c:\users\mdani\appdata\roaming\python\python38\site-packages (from opencv.python) (1.19.4)
Reply
#2
Each version of python has it's own site-packages set up.
There are several methods that you can use to control this.

My favourite is setting up virtual environments for each project. This assures that all packages will be using the same python version, and thus the same site-packages version.

to set up a virtual environment in any directory, open a command window, change to target window, and from terminal emulator (command window) issue: python -m venv myvrtualenviromentname
Start with: . ./myvrtualenviromentname/bin/activate (Linux)

And this can be made even easier by using pyenv ( see: https://python-forum.io/Thread-pyenv-Sim...Management ) with this installed, you can switch easily from one version of python to another.

Modifying site-packages manually is asking for trouble down the road (just in case you thought about doing that). It might work for a while, but will get you sooner or later. Better to use pip for the proper python version, and letting it install the package.

You can keep a copy of which packages are installed in a particular virtual environment using:
pip freeze > requirements.txt

Then if you need to install a newer venv, you can bring it up to date with: pip install -r requirements.txt

You can see which version of python you are using with python -v pip with pip -V
and installed packages for current version with pip list
Reply


Forum Jump:

User Panel Messages

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