当前位置: 代码迷 >> 综合 >> 解决‘pip‘ is a package and cannot be directly executed报错问题和WinError 5]拒绝访问
  详细解决方案

解决‘pip‘ is a package and cannot be directly executed报错问题和WinError 5]拒绝访问

热度:59   发布时间:2023-10-12 15:03:46.0

今天装包的时候,提示我要升级pip

WARNING: You are using pip version 21.0.1; however, version 21.1.1 is available.
You should consider upgrading via the 'd:\python\python.exe -m pip install --upgrade pip' command.

解决‘pip‘ is a package and cannot be directly executed报错问题和WinError 5]拒绝访问

d:\python\python.exe -m pip install --upgrade pip

于是就按它的提示,切换到python安装路径下升级了

ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。: 'd:\\python\\scripts\\pip.exe'
Consider using the `--user` option or check the permissions.

解决‘pip‘ is a package and cannot be directly executed报错问题和WinError 5]拒绝访问

一开始看到 [WinError 5] 拒绝访问。: 'd:\\python\\scripts\\pip.exe',以为是得用管理员权限,于是切换

解决‘pip‘ is a package and cannot be directly executed报错问题和WinError 5]拒绝访问

发现还是不好使,这才仔细一看。

后来知道得加上用户信息或者用python -m pip install --upgrade pip

好家伙,把我pip给卸载了,然后更新的时候还没给我更新成功!

执行pip -v都不好使了,欲哭无泪。

d:\Python>pip -v
Traceback (most recent call last):
  File "d:\python\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "d:\python\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\Python\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip._internal'

解决‘pip‘ is a package and cannot be directly executed报错问题和WinError 5]拒绝访问

这下可好,有事干了。

于是我按照网友的解决方案操作,但是试了以下三个都没有用!

python -m pip install --upgrade pippython -m ensurepipeasy_install pip

再执行还是

d:\Python\python.exe: No module named pip.__main__; 'pip' is a package and cannot be directly executed

解决‘pip‘ is a package and cannot be directly executed报错问题和WinError 5]拒绝访问

好家伙,居然都不好使!

然后我注意到执行python -m ensurepip后,有一条报错信息是这样的:

Requirement already satisfied: pip in d:\python\lib\site-packages (20.2.3)

喵喵就猜想着,应该是没有卸载干净,于是我按照路径找到d:\python\lib\site-packages

然后把文件夹下的如下两个文件夹删掉了

解决‘pip‘ is a package and cannot be directly executed报错问题和WinError 5]拒绝访问

删除后,我再执行安装pip的命令就成功了!

#安装pip
python -m ensurepip#更新pip
python -m pip install --upgrade pip

解决‘pip‘ is a package and cannot be directly executed报错问题和WinError 5]拒绝访问

完美!

总的来说,就是更新pip的时候,把旧版卸载了,但是新版又没有成功安装,而卸载又没有卸载干净,手动安装又失败。

 

这是我在CSDN的第一篇blog,今后会保障每天至少写一篇debug的文章,记录一下那些年我们一些解决的bug。

 

生信喵 X CSDN,记录debug的日常。

 

另外,欢迎大家关注公众号【生信喵】,在那里我会分享机器学习、算法开发的总结笔记……

  相关解决方案