英文:
Pip installs packages in the wrong directory
问题
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\LocalPackages\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?
英文:
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?
答案1
得分: 3
你需要使用 python -m pip install
。为什么?pip
是一个可执行文件,它可能与你的标准 python
安装目录共享,也可能不共享。你可以通过比较以下方式来验证:
pip -V
python -m pip -V
后者的命令,python -m pip install
确保了 pip
与你在 IDLE 中运行的 python
命令关联。
英文:
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.
答案2
得分: 0
看起来你同时安装了python3.9和3.11。当你只输入pip install ...
时,你可能会在python 3.9中安装你的包,而在IDLE中运行的是python 3.11。
尝试在你的命令提示符中输入python -V
,它可能会显示python3.11。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论