在Pycharm中安装opencv出现pip无法更新等等问题

问题背景:
想在Pycharm上安装opencv进行双目视觉学习,出现了一系列问题。
具体问题:
1.pip无法更新到最新版本

ValueError: Unable to find resource t64.exe in package pip._vendor.distlib
WARNING: You are using pip version 21.2.2; however, version 23.0.1 is available.
You should consider upgrading via the 'd:\python39\python.exe -m pip install --upgrade pip' command.

在这里插入图片描述

问题分析:
由于很久没有更新pip或者原因可能是由于要连接外网进行下载速度慢,导致更新中途网速较慢,于是报错停止了。
解决方法:
1.如果是很久没有更新pip,可能出现一下情况:

(paddle2) D:\github\PGL>python.exe -m pip install --upgrade pip
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pip
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/cb/28/91f26bd088ce8e22169032100d4260614fc3da435025ff389ef1d396a433/pip-20.2.4-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.2.3
    Uninstalling pip-20.2.3:
      Successfully uninstalled pip-20.2.3
  Rolling back uninstall of pip
  Moving to c:\users\administrator\appdata\roaming\python\python37\scripts\
   from c:\users\administrator\appdata\roaming\python\python37\~cripts
  Moving to c:\users\administrator\appdata\roaming\python\python37\site-packages\pip-20.2.3.dist-info\
   from c:\users\administrator\appdata\roaming\python\python37\site-packages\~ip-20.2.3.dist-info
  Moving to c:\users\administrator\appdata\roaming\python\python37\site-packages\pip\
   from c:\users\administrator\appdata\roaming\python\python37\site-packages\~ip
ERROR: Exception:
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_internal\cli\base_command.py", line 228, in _main
    status = self.run(options, args)
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_internal\cli\req_command.py", line 182, in wrapper
    return func(self, options, args)
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_internal\commands\install.py", line 406, in run
    pycompile=options.compile,
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_internal\req\__init__.py", line 90, in install_given_reqs
    pycompile=pycompile,
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_internal\req\req_install.py", line 822, in install
    requested=self.user_supplied,
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_internal\operations\install\wheel.py", line 860, in install_wheel
    requested=requested,
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_internal\operations\install\wheel.py", line 762, in _install_wheel
    generated_console_scripts = maker.make_multiple(scripts_to_generate)
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_vendor\distlib\scripts.py", line 418, in make_multiple
    filenames.extend(self.make(specification, options))
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_internal\operations\install\wheel.py", line 498, in make
    return super(PipScriptMaker, self).make(specification, options)
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_vendor\distlib\scripts.py", line 407, in make
    self._make_script(entry, filenames, options=options)
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_vendor\distlib\scripts.py", line 307, in _make_script
    self._write_script(scriptnames, shebang, script, filenames, ext)
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_vendor\distlib\scripts.py", line 242, in _write_script
    launcher = self._get_launcher('t')
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\pip\_vendor\distlib\scripts.py", line 386, in _get_launcher
    raise ValueError(msg)
ValueError: Unable to find resource t64.exe in package pip._vendor.distlib
WARNING: You are using pip version 20.2.3; however, version 20.2.4 is available.
You should consider upgrading via the 'd:\Miniconda3\envs\paddle2\python.exe -m pip install --upgrade pip' command.

这个时候参考博客:

https://blog.csdn.net/weixin_41450123/article/details/110244117

两步走,第一步卸载卸载 setuptools

d:\python39\python.exe -m pip uninstall pip setuptools

(paddle2) D:\github\PGL> d:\python39\python.exe -m pip uninstall pip setuptools
Found existing installation: pip 20.2.3
Uninstalling pip-20.2.3:
Would remove:
c:\users\administrator\appdata\roaming\python\python37\scripts\pip.exe
c:\users\administrator\appdata\roaming\python\python37\scripts\pip3.7.exe
c:\users\administrator\appdata\roaming\python\python37\scripts\pip3.exe
c:\users\administrator\appdata\roaming\python\python37\site-packages\pip-20.2.3.dist-info*
c:\users\administrator\appdata\roaming\python\python37\site-packages\pip*
Proceed (y/n)? y
Successfully uninstalled pip-20.2.3
Found existing installation: setuptools 50.3.0.post20201006
Uninstalling setuptools-50.3.0.post20201006:
Would remove:
d:\miniconda3\envs\paddle2\lib\site-packages_distutils_hack
d:\miniconda3\envs\paddle2\lib\site-packages\easy_install.py
d:\miniconda3\envs\paddle2\lib\site-packages\pkg_resources
d:\miniconda3\envs\paddle2\lib\site-packages\setuptools
d:\miniconda3\envs\paddle2\lib\site-packages\setuptools-50.3.0.post20201006-py3.7.egg-info
d:\miniconda3\envs\paddle2\scripts\easy_install-script.py
d:\miniconda3\envs\paddle2\scripts\easy_install.exe
Proceed (y/n)? y
Successfully uninstalled setuptools-50.3.0.post20201006
第二步,升级pip

pip3 install --upgrade pip

在Pycharm中安装opencv出现pip无法更新等等问题_第1张图片
==2.如果是因为使用的国外镜像源,导致下载速度比较慢,最后报错停止下载:

ValueError: Unable to find resource t64.exe in package pip._vendor.distlib
WARNING: You are using pip version 21.2.2; however, version 23.0.1 is available.
You should consider upgrading via the 'd:\python39\python.exe -m pip install --upgrade pip' command.

在这里插入图片描述

这个时候考虑使用清华源:

https://mirrors.tuna.tsinghua.edu.cn/help/pypi/

使用镜像源下载pip

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

升级pip

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


如果还是不行,考虑上面的第一步卸载卸载 setuptools

d:\python39\python.exe -m pip uninstall pip setuptools

第二步,升级pip

pip3 install --upgrade pip

2.无法安装opencv(下载到一半,又不能下载报错了)
解决方法:
这里参考视频教程:

https://www.bilibili.com/video/BV1TR4y1e7Ke/?spm_id_from=333.788.recommend_more_video.0&vd_source=258d2d263c2bb92125c92f82857bcfa5

第一步,首先配置镜像源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

第二步,安装opencv

pip install opencv-python

第三步,下载拓展包

pip install opencv-contrib-python==4.7.0.72

在Pycharm中安装opencv出现pip无法更新等等问题_第2张图片
第四步,安装可视化包:

pip install matplotlib

在Pycharm中安装opencv出现pip无法更新等等问题_第3张图片
第五步,检验一下是否真的成功安装:

d:\python39\python.exe

在这里插入图片描述

import cv2

出现了问题:

>>> import cv2
OpenCV bindings requires "numpy" package.
Install it via command:
    pip install numpy
Traceback (most recent call last):
  File "d:\python39\lib\site-packages\numpy\core\__init__.py", line 23, in <module>
    from . import multiarray
  File "d:\python39\lib\site-packages\numpy\core\multiarray.py", line 10, in <module>
    from . import overrides
  File "d:\python39\lib\site-packages\numpy\core\overrides.py", line 6, in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的程序。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 1, in <module>
  File "d:\python39\lib\site-packages\cv2\__init__.py", line 11, in <module>
    import numpy
  File "d:\python39\lib\site-packages\numpy\__init__.py", line 141, in <module>
    from . import core
  File "d:\python39\lib\site-packages\numpy\core\__init__.py", line 49, in <module>
    raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "d:\python39\python.exe"
  * The NumPy version is: "1.24.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed while importing _multiarray_umath: 找不到指定的程序。

>>> import cv2
OpenCV bindings requires "numpy" package.
Install it via command:
    pip install numpy
Traceback (most recent call last):
  File "d:\python39\lib\site-packages\numpy\core\__init__.py", line 23, in <module>
    from . import multiarray
  File "d:\python39\lib\site-packages\numpy\core\multiarray.py", line 10, in <module>
    from . import overrides
  File "d:\python39\lib\site-packages\numpy\core\overrides.py", line 6, in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的程序。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 1, in <module>
  File "d:\python39\lib\site-packages\cv2\__init__.py", line 11, in <module>
    import numpy
  File "d:\python39\lib\site-packages\numpy\__init__.py", line 141, in <module>
    from . import core
 

这个问题还没解决,现在这边存疑,有知道的小伙伴可以评论区分享下,后续如果问题解决了,我会及时更新的

你可能感兴趣的:(文章创作,opencv,pycharm,pip)