解决!cmd中‘pip’不是内部或外部命令,也不是可运行的程序或批处理文件的问题

本文介绍了解决在CMD中使用pip安装包时遇到的错误——‘pip’不是内部或外部命令的方法。通过更改目录到pip所在路径,成功安装了openpyxl,并解决了权限问题,最终升级了pip版本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:在cmd中pip install时出现错误——‘pip’不是内部或外部命令,也不是可运行的程序或批处理文件的问题。

C:\Users\hp>pip install openpyxl
'pip' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

在经过搜索后发现需要进入pip.exe所在的文件夹路径,于是进入到pip所在的文件夹,复制路径(每个人存放的路径不一样,不过都在python下的Scripts中)。

C:\Users\hp>cd C:\Users\hp\AppData\Local\Programs\Python\Python37-32\Scripts

再次输入pip install命令。

C:\Users\hp\AppData\Local\Programs\Python\Python37-32\Scripts>pip install openpyxl
Collecting openpyxl
  Using cached https://files.pythonhosted.org/packages/1c/5d/e9087edae37ed185e883c9ec727215caba8b4044a8111ff033ebad85e508/openpyxl-3.0.1.tar.gz
Collecting jdcal (from openpyxl)
  Using cached https://files.pythonhosted.org/packages/f0/da/572cbc0bc582390480bbd7c4e93d14dc46079778ed915b505dc494b37c57/jdcal-1.4.1-py2.py3-none-any.whl
Collecting et_xmlfile (from openpyxl)
  Using cached https://files.pythonhosted.org/packages/22/28/a99c42aea746e18382ad9fb36f64c1c1f04216f41797f2f0fa567da11388/et_xmlfile-1.0.1.tar.gz
Installing collected packages: jdcal, et-xmlfile, openpyxl
  Running setup.py install for et-xmlfile ... done
  Running setup.py install for openpyxl ... done
Successfully installed et-xmlfile-1.0.1 jdcal-1.4.1 openpyxl-3.0.1
WARNING: You are using pip version 19.2.3, however version 19.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

发现需要升级pip,输入pip install --upgrade pip

C:\Users\hp\AppData\Local\Programs\Python\Python37-32\Scripts>pip install --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/00/b6/9cfa56b4081ad13874b0c6f96af8ce16cfbc1cb06bedf8e9164ce5551ec1/pip-19.3.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 19.2.3
    Uninstalling pip-19.2.3:
      Successfully uninstalled pip-19.2.3
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。: 'C:\\Users\\hp\\AppData\\Local\\Temp\\pip-uninstall-aj7beqe0\\pip.exe'
Consider using the `--user` option or check the permissions.

出现拒绝访问,原因是没有获得用户授权,在pip install后添加–user

C:\Users\hp\AppData\Local\Programs\Python\Python37-32\Scripts>pip install --user --upgrade pip
Requirement already up-to-date: pip in c:\users\hp\appdata\local\programs\python\python37-32\lib\site-packages (19.3.1)

成功升级pip,再次install所需的pip

C:\Users\hp\AppData\Local\Programs\Python\Python37-32\Scripts>pip install --user --upgrade pip
Requirement already up-to-date: pip in c:\users\hp\appdata\local\programs\python\python37-32\lib\site-packages (19.3.1)

C:\Users\hp\AppData\Local\Programs\Python\Python37-32\Scripts>pip install openpyxl
Requirement already satisfied: openpyxl in c:\users\hp\appdata\local\programs\python\python37-32\lib\site-packages (3.0.1)
Requirement already satisfied: jdcal in c:\users\hp\appdata\local\programs\python\python37-32\lib\site-packages (from openpyxl) (1.4.1)
Requirement already satisfied: et_xmlfile in c:\users\hp\appdata\local\programs\python\python37-32\lib\site-packages (from openpyxl) (1.0.1)

成功。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值