VS Code中pip命令未被识别,无法安装cowsay库求助
解决pip命令无法识别导致cowsay库安装失败的问题
在VS Code中执行pip install cowsay时出现以下报错:
pip: The term 'pip' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At line:1 char:1
pipCategoryInfo : ObjectNotFound: (pip:String) [], CommandNotFoundException FullyQualifiedErrorId : CommandNotFoundException
以下是几种实用的解决办法:
直接通过Python模块调用pip
不用纠结环境变量,直接执行python -m pip install cowsay(如果系统里同时装了Python2和Python3,换成python3 -m pip install cowsay),这条命令会通过当前使用的Python解释器调用对应版本的pip,直接完成安装。将pip所在路径添加到系统环境变量
- 找到Python安装目录下的
Scripts文件夹(比如C:\Users\你的用户名\AppData\Local\Programs\Python\Python311\Scripts,版本号根据实际安装情况调整) - 打开系统环境变量设置:右键「此电脑」→「属性」→「高级系统设置」→「环境变量」,在「系统变量」里找到
Path,点击「编辑」 - 把刚才找到的
Scripts路径添加进去,点击「确定」保存 - 重启VS Code的终端,再执行
pip install cowsay即可
- 找到Python安装目录下的
确认VS Code使用的Python环境
- 查看VS Code左下角的Python版本标识,点击它切换到你安装的目标Python环境
- 如果还是不行,可以直接用该环境pip的绝对路径执行命令,比如
C:\Python311\Scripts\pip.exe install cowsay
Windows系统专用:用Python启动器调用
执行py -m pip install cowsay,Python启动器会自动识别系统中安装的Python版本并调用对应的pip。
内容的提问来源于stack exchange,提问作者programmer
相关产品推荐
相关产品推荐

