2

So I want to install the opencv-python package. I typed in pip install opencv-python and got this:

Collecting opencv-python
  Downloading opencv_python-4.7.0.72-cp37-abi3-win_amd64.whl (38.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 38.2/38.2 MB 3.1 MB/s eta 0:00:00
Requirement already satisfied: numpy>=1.17.0 in c:\users\leo westerburg burr\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from opencv-python) (1.24.2)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.7.0.72

When I try and import the package (on IDLE) I get

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    import cv2
ModuleNotFoundError: No module named 'cv2'

This is the same for all the packages I have installed recently, like numpy. The thing is when I type sys.path into the IDLE I get

C:\Users\Leo Westerburg Burr\AppData\Local\Programs\Python\Python311\Lib\idlelib
C:\Users\Leo Westerburg Burr\AppData\Local\Programs\Python\Python311\python311.zip
C:\Users\Leo Westerburg Burr\AppData\Local\Programs\Python\Python311\DLLs
C:\Users\Leo Westerburg Burr\AppData\Local\Programs\Python\Python311\Lib
C:\Users\Leo Westerburg Burr\AppData\Local\Programs\Python\Python311
C:\Users\Leo Westerburg Burr\AppData\Local\Programs\Python\Python311\Lib\site-packages

Which are all in the AppData/Local/Programs directory, however the packages are stored in appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\... as you can see when I installed opencv-python - which I find weird; why are they installed there and not in programs\python ?

I have tried reinstalling pip, and also downloading a newer version of python. What is weird is that I have Python311 and Python38 in my Python folder, but this weird folder that has the packages is python39?

So my question is: how do I get pip to install packages in Programs\Python\Python311\..., rather than Packages\... ?

Do I have to add something to my PATH?

LWB
  • 426
  • 1
  • 4
  • 16

2 Answers2

3

You need to use python -m pip install. Why? pip is an executable that may or may not share an installation directory with your standard python. You can verify this by comparing:

pip -V

python -m pip -V

The latter command, python -m pip install ensures that pip is the one linked to the python command you run for IDLE.

C.Nivs
  • 12,353
  • 2
  • 19
  • 44
0

It seems that you have both python3.9 and 3.11 installed. When just typing in pip install ... you probably install your package in python 3.9 whereas you run python 3.11 in IDLE.

Try python -V in your command prompt, it will probably answer python3.11

Maelinho
  • 1
  • 2
  • It returns `Python 3.9.13`. How do I change this to 3.11? – LWB Apr 06 '23 at 18:13
  • you can check the answer to a similar question here : https://stackoverflow.com/questions/5846167/how-to-change-default-python-version – Maelinho Apr 06 '23 at 19:41