首页 > 解决方案 > PyCharm IDE 中的 pytest 安装

问题描述

我是编程新手。我在以下链接中为 python 开发配置 PyCharm 社区版:https ://realpython.com/pycharm-guide/

我想在设置/工具中配置后尝试 pytest 选项并选择“默认测试运行器:Pytest”。尝试在 IDE 中运行测试时,我有:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pycharm\_jb_pytest_runner.py", line 4, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'

尝试了 python 集成工具的修复选项并出现此错误:

尝试修复 pytest 包时出现 Pycharm 错误

我从 cmd 中检查了 PIP 包:使用官方 python 指南中推荐的以下命令:

1)pip --version检查已安装的版本,并返回版本号pip 19.2.32 c:\users\user_name\appdata\local\programs\python\python38-32\lib\site-packages\pip (python 3.8)python -m pip install -U pip setuptools wheel 检查成功,但轮子失败并出现错误,如下所示:

    C:\Users\user_name>python -m pip install -U pip setuptools wheel
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A1748>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/pip/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A1808>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/pip/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A1910>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/pip/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A19E8>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/pip/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A1AC0>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/pip/
Requirement already up-to-date: pip in c:\users\user_name\appdata\local\programs\python\python38-32\lib\site-packages (19.2.3)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036E5358>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/setuptools/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x03684EC8>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/setuptools/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A1E80>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/setuptools/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A1E50>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/setuptools/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A1D48>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/setuptools/
Requirement already up-to-date: setuptools in c:\users\user_name\appdata\local\programs\python\python38-32\lib\site-packages (41.2.0)
Collecting wheel
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A1F58>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/wheel/
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A1B98>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/wheel/
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A1A30>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/wheel/
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A1970>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/wheel/
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x036A11A8>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')': /simple/wheel/


  ERROR: Could not find a version that satisfies the requirement wheel (from versions: none)

ERROR: No matching distribution found for wheel

我尝试修复修复/卸载并安装仍然出现这些错误我尝试从标准库引导它:

python -m ensurepip --default-pip

C:\Users\user_name>python -m ensurepip --default-pip
Looking in links: c:\Users\user_name\AppData\Local\Temp\tmpyly1wzwb
Requirement already satisfied: setuptools in c:\users\user_name\appdata\local\programs\python\python38-32\lib\site-packages (41.2.0)
Requirement already satisfied: pip in c:\users\user_name\appdata\local\programs\python\python38-32\lib\site-packages (19.2.3)

更新 1

令人惊讶的是,当我检查它时,我没有找到添加到 Windows 环境变量的 python 路径,但我确定我在安装 python 3.8 包“将 python 3.8 添加到 PATH”时检查了该选项我通过“编辑”手动将路径添加到 Windows系统环境变量”但还是有这个问题

标签: pythonpython-3.xpip

解决方案


推荐阅读