python基本使用命令记录

这篇博客记录了Python的基本使用,包括查看版本号、Python路径、安装路径、虚拟环境的创建、安装依赖包的方法以及执行案例。特别提到了遇到的`ImportError: cannot import name 'soft_unicode' from 'markupsafe'`异常,并给出了解决方案,即降级markupsafe到2.0.1版本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

查看版本号

# 系统当前版本
python -V

# 查看系统自带的python
open /System/Library/Frameworks/Python.framework/Versions

查看当前的python路径

which python         # mac自带python2
which python3       # 自安装的python3

安装路径

在这里插入图片描述

虚拟环境

# 创建venv
 python3 -m venv venv1
# 进入venv
 source venv1/bin/activate
 # 退出venv
 deactivate

安装依赖包

# 默认方式
pip install -r  requirements.txt    

# 镜像方式                        
pip install -i https://xxxx -r requirements.txt

执行case

# 执行整个文件夹
pytest testcase/
# 执行测试文件
pytest testcase/test_demo.py
# 执行测试类
pytest testcase/test_demo::TestDemo
# 执行测试方法
pytest testcase/test_demo::test_01

异常记录

1、ImportError: cannot import name ‘soft_unicode’ from ‘markupsafe’ (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/markupsafe/init.py)

在这里插入图片描述

解决: 把markupsafe降级为2.0.1(原版本为2.1)
pip install markupsafe==2.0.1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值