我无法在pycharm中安装opencv吗?

时间:2020-11-05 15:29:23

标签: opencv pycharm opencv-python

我已经使用pip install opencv-python通过cmd下载了opencv。但是,当我在pycharm中运行简单的读写程序时,搜索时无法加载import cv2命令,我知道pycharm还有其他安装opencv的方法。我做到了setting->project->project interperter,然后搜索 opencv-python ,但是在安装过程中出现此错误:

Collecting opencv-python
  Could not fetch URL https://pypi.org/simple/opencv-python/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/opencv-python/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/opencv-python/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/opencv-python/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/opencv-python/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/opencv-python/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/opencv-python/
  Could not find a version that satisfies the requirement opencv-python (from versions: )
No matching distribution found for opencv-python
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

我拥有python和pip的最新版本,但是尽管出现此错误,任何人都可以帮助我。

2 个答案:

答案 0 :(得分:0)

很有可能您是在基本conda环境中安装了opencv,而不是在您作为解释程序激活的环境中安装的,或者您是在创建并已激活基本环境的环境中安装了opencv的:

尝试以下步骤:

conda create -n envname python

conda activate envname

pip install opencv-python

转到pycharm并将envname环境添加到pycharm解释器中,将其激活,然后运行代码。

答案 1 :(得分:0)

您的初始错误是:

Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))

如果您是Windows用户,则将以下路径设置为系统的 PATH 环境变量:

如果使用Anaconda:

<system_path>\Anaconda3
<system_path>\Anaconda3\scripts
<system_path>\Anaconda3\Library\bin

如果您的系统上仅安装了Python,则(我假设您的系统中安装了Python 3.6):

<system_path_where_python_is_installed>\Python36
<system_path_where_python_is_installed>\Python36\Scripts
<system_path_where_python_is_installed>\Python36\Library\bin

然后尝试通过PyCharm安装opencv。

希望这可以解决您的问题。