此篇文章内容会不定期更新,仅作为学习过程中的笔记记录
一、查询Windows 10环境下python版本与安装路径
若电脑成功安装了python环境,不小心忘了版本。
I、查询版本
1、cmd窗口快捷查询
·Win + R 输入cmd 进入窗口;
·直接输入
python --version
即可返回版本
2、使用Python的sys模块
·在Python交互式环境中
·输入代码
import sys
print(sys.version)或者
print(sys.version_info)
即可返回版本
·sys.version是一个字符串,包含了Python解释器的版本信息,以及构建时的一些额外信息(比如编译平台)
·sys.version_info是一个元组,包含了Python解释器的版本号。至少包含五个元素,分别是主版本号、次版本号、微版本号、发布级别(如'alpha', 'beta', 'candidate', 'final'),以及序列号(对于发布级别非'final'的版本)。这个元组非常适合用于版本比较。
II、查询安装路径
1、cmd窗口快捷查询
·窗口输入where python
2、使用Python的sys模块
·在Python交互式环境中
·输入代码
import sys
print(sys.executable)·sys.executable是一个字符串,指向执行该脚本的 Python 解释器的完整路径。
3、编译器中查看
·PyCharm中,使用Crtl + Alt + S快捷键(或者页面编译器右上角File下拉菜单中)
·进入Settings -> Project 项目名 -> Project Interpreter,可以找到当前项目的Python解释器完整路径。
4、系统环境变量
·Windows搜索框中,搜索“编辑系统环境变量” ,再点击环境变量,
·系统变量Path的值或者自己添加的系统变量的值中寻找安装的Python解释器路径。
·值得注意的是:
如果是通过Anaconda、Miniconda或其他第三方软件管理器安装的Python,那么Python的安装路径可能会被放置在特定的目录下;此时系统环境变量中的值可能第三方软件管理器的路径,就需要去对应目录下寻找路径
5、Win + E资源管理器查找
全局搜索排查
二、PyCharm安装依赖库异常
Python版本 = 3.7.16
I、安装pytest相关依赖库
requirements.txt
pytest pytest-html pytest-xdist pytest-ordering pytest-rerunfailures pytest-base-url allure-pytest
报错:
pip install -r requirements.txt Collecting pytest Downloading pytest-7.4.4-py3-none-any.whl (325 kB) ---------------------------------------- 325.3/325.3 kB 17.9 kB/s eta 0:00:00 Collecting pytest-html Downloading pytest_html-3.2.0-py3-none-any.whl (16 kB) ERROR: Ignored the following versions that require a different python version: 4.0.0 Requires-Python >=3.8; 4.0.1 Requires-Python >=3.8; 4.0.2 Requires-Python >=3.8; 4.0.3rc0 Requires-Python >=3.8; 4.1.0 Requires-Python >=3.8; 4.1.1 Requires-Python >=3.8; 8.0.0 Requires-Python >=3.8; 8.0.0rc1 Requires-Python >=3.8; 8.0.0rc2 Requires-Python >=3.8; 8.0.1 Requires-Python >=3.8; 8.0.2 Requires-Python >=3.8; 8.1.0 Requires-Python >=3.8; 8.1.1 Requires-Python >=3.8; 8.1.2 Requires-Python >=3.8; 8.2. 0 Requires-Python >=3.8; 8.2.1 Requires-Python >=3.8; 8.2.2 Requires-Python >=3.8; 8.3.0 Requires-Python >=3.8; 8.3.1 Requires-Python >=3.8; 8.3.2 Requires-Python >=3.8; 8.3.3 Requires-Python >=3.8 ERROR: Could not find a version that satisfies the requirement pytest-xdist (from versions: none) ERROR: No matching distribution found for pytest-xdist
问题原因:
python版本问题
1、pytest-html是一个pytest插件,用于生成测试结果的HTML报告。
出现报错由于Python环境版本低于3.8,而
pytest-html
的较新版本(从4.0.0开始)需要Python 3.8或更高版本;
2、pytest-xdist
是一个pytest的插件,用于支持分布式测试,即并行地在多个进程中运行测试。
pytest-xdist
兼容性主要取决于自身的版本和pytest的版本,因为pytest-xdist
是pytest的一个扩展。出现报错可能是因为pip源(如PyPI)配置不正确,或者Python环境非常特殊。pip install 默认安装最新版本的依赖库,当前安装成功的pytest版本为7.4.4,Python版本3.7.14可能为兼容性错误。
解决:
将项目Setting中的Interpreter更改至3.8以上的python解释器版本,再执行上诉语句,便无报错发生
II、
三、代码运行报错
I、处理多行输入时,报错EOFError
使用如下写法来读入多行输入时
while True: records = list(map(str, input().split())) #操作 print(records)报错:
Traceback (most recent call last): File "Main.py", line 15, in <module> records = list(map(str, input().split())) EOFError: EOF when reading a line : non-zero return = 1
程序在尝试从标准输入(通常是键盘输入或重定向的文件输入)读取数据时,遇到了文件结束符(EOF)
解决方案:
修改程序逻辑,加入try-except处理EOFError,可以避免报错。
while True: try: records = list(map(str, input().split())) #操作 print(records) except EOFError: break