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

问题:在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)

成功。

你可能感兴趣的:(Error问题)