[英]Installed python package with pip but can't import said package
I installed a python3 package called urllib3 using pip with the following command:我使用 pip 和以下命令安装了一个名为 urllib3 的 python3 package:
pip install urllib3
It seemed to be successful and when I type the command:它似乎是成功的,当我输入命令时:
pip list
I get the following list which implies it is installed我得到以下列表,这意味着它已安装
But when I try to import in in the python console I get the following error:但是当我尝试在 python 控制台中导入时,我收到以下错误:
ModuleNotFoundError: No module named 'urllib3
I am using Python 3.8.5 (64bit) with a VS Code virtual enviroment, I have tried uninstalling it and reinstalling I've also checked typos but I can't seem to find any.我正在使用带有 VS Code 虚拟环境的 Python 3.8.5(64 位),我尝试卸载它并重新安装我也检查了拼写错误,但我似乎找不到任何错误。
try:尝试:
pip3 install urllib3
As it can be possible you have also installed python2 on your machine.您可能还在您的机器上安装了 python2。
Also try restarting your IDE.也尝试重新启动您的 IDE。
You're paths might be mixed up: python, python3 as well as pip and pip3 might not point to the places you're expecting.您的路径可能会混淆:python、python3 以及 pip 和 pip3 可能不会指向您期望的地方。
Try to validate that which pip
and which python
point to the same python installation.尝试验证
which pip
和which python
指向相同的 python 安装。
Alternatively, you can install urllib3
using python -m pip install urllib3
instead of pip install urllib3
.或者,您可以使用
python -m pip install urllib3
urllib3
不是pip install urllib3
。
Lastly, it might be a VS Code issue.最后,它可能是 VS Code 问题。 See if the information on selecting a Python interpreter are helpful to you.
查看有关选择 Python 解释器的信息是否对您有帮助。
The problem was with permissions for running scripts on the computer, I had to run the following command to enable permissions on my system:问题在于在计算机上运行脚本的权限,我必须运行以下命令才能在我的系统上启用权限:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
This enabled the current user (me) to actually activate the venv when I opened powershell (I think) and run the pip install inside the venv instead of outside.这使当前用户(我)能够在我打开 powershell(我认为)并在 venv 内部而不是外部运行 pip 安装时实际激活 venv。
Note that I had the package installed globally since the PowerShell was not inside the venv.请注意,由于 PowerShell 不在 venv 中,因此我在全局范围内安装了 package。
Thanks for the help谢谢您的帮助
Resolved!解决!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.