vscode中关于python的一些常用配置

文章目录

python cv2 提示配置

第一步 配置提示信息

打开settings

打开扩展--> 找到python --> 打开json配置

将cv2的安装目录配置到如下位置

第二部 重启vs 可能还不行,那就重新安装以下opencv-python

具体为啥不行没搞明白

配置pytest

还是如上,将下入的位置打开

编写测试用例

当方法以test开头的时候会自动识别成测试用例,会有一个标识,鼠标右键点击标识的时候可以执行测试,如果成功就会出现一个对号

python 复制代码
import pytest
from src import base_function as bf

print(bf.getCurrentAsbDir())

def test_getCurrentAsbDir():
    assert bf.getCurrentAsbDir() == "e:\\learning_sources\\cv_py"

def aaa():
    assert 1==1

def test_aaa():
    assert 1==1

配置跨文件import

在工作目录中新建一个.env文件输入内容如下

复制代码
PYTHONPATH="E:/learning_sources/cv_py/src;E:/learning_sources/cv_py/src/tests;E:/learning_sources/cv_py;${env:PYTHONPATH}"

打开.vscode中的setting.json 进行配置 内容如下

json 复制代码
{
    "python.analysis.autoImportCompletions": true,
    // "python.envFile": "E:/learning_sources/cv_py/.env",
    //这里是配置运行时的工作路径
    "terminal.integrated.env.windows": {"PYTHONPATH":"${workspaceFolder};${env:PYTHONPATH}"},
    "python.defaultInterpreterPath": "D:\\ProgramData\\anaconda3\\python.exe" 
}

参考:

https://blog.csdn.net/qq_31654025/article/details/109474175

类似如下的文件结构,就可以在test目录(包)中引入src的内容了

test_base_function.py 内容如下

python 复制代码
import pytest
from src import base_function as bf

print(bf.getCurrentAsbDir())

配置格式化工具

安装插件 Black Formatter 插件

修改setting.json配置内容如下

json 复制代码
{
    "python.formatting.provider": "none",
    "python.formatting.autopep8Args": [
        "--max-line-length=150"
    ],
    "editor.wordWrap": "on",
    "editor.wordWrapColumn": 150,
    "[python]": {
        "editor.defaultFormatter": "ms-python.black-formatter",
        "editor.formatOnSave": true,
        "editor.formatOnPaste": true,
        "editor.formatOnType": true,
    },
    "black-formatter.args": [
        "--line-length",
        "150"
    ],
}
相关推荐
是有头发的程序猿3 分钟前
Python爬虫实战:面向对象编程在淘宝商品数据抓取中的应用
开发语言·爬虫·python
萑澈17 分钟前
Windows系统Anaconda/Miniconda的安装、配置、基础使用、清理缓存空间和Pycharm/VSCode配置指南
python
Onebound_Ed35 分钟前
Python爬虫进阶:面向对象设计构建高可维护的1688商品数据采集系统
开发语言·爬虫·python
foxsen_xia1 小时前
Go安装、配置和vsCode配置Go
开发语言·vscode·golang
阿蔹1 小时前
JavaWeb-Selenium 配置以及Selenim classnotfound问题解决
java·软件测试·python·selenium·测试工具·自动化
万粉变现经纪人1 小时前
如何解决 pip install 代理报错 407 Proxy Authentication Required 问题
windows·python·pycharm·beautifulsoup·bug·pandas·pip
李剑一2 小时前
Python学习笔记3
python
luod2 小时前
Python包
python
Mr Lee_2 小时前
Smali 文件生成dex装箱算法整合
开发语言·python·算法
电饭叔2 小时前
《python语言程序设计》2018版--第8章14题利用字符串输入作为一个信用卡号之一(Luhn算法解释)
android·java·python