python开发测试工具遇到的问题整理


查看python的所有安装包

在windows cmd串口直接输入"python -m pip list",即可查看Python安装的所有包。
在这里插入图片描述

Matplotlib的使用

安装,在windows cmd串口下,直接输入"pip install matplotlib"即可安装,如下图(上面部分是安装时完成显示的),安装了有两三分钟。
在这里插入图片描述


import sys
import re
import numpy as np
import matplotlib.pyplot as plt

filename = r'C:\Users\11\Desktop\ll\4.c'
# 9 | gg Ang:18 -2064 -49
# 9 | gg Acc:13359 -7957 -4958
# 9 | gg Ang:9 -9 -34
# 9 | gg Acc:13326 -7903 -4985
# 9 | gg Ang:5 -9 -22
# 9 | gg Acc:13361 -7782 -4965
# 9 | gg Ang:-6 1 -27
# 9 | gg Acc:13485 -7887 -4963
pattern_ang =r'.*gg Ang:(-?\d+)\s+(-?\d+)\s+(-?\d+)?'
pattern_acc =r'.*gg Acc:(-?\d+)\s+(-?\d+)\s+(-?\d+)?'
step_acc = []
acc_x, acc_y, acc_z = [], [], []
step_ang = []
ang_x, ang_y, ang_z = [], [], []

with open(filename, 'r', encoding='UTF-8') as f:
    lines = f.readlines()
    j = 0
    k = 0
    for line in lines:
        search_acc =re.search(pattern_acc, line, re.I)
        if(search_acc  is not None):
            print (line)
            print (search_acc.group(1))
            print (search_acc.group(2))
            print (search_acc.group(3))
            acc_x.append(int(search_acc.group(1)))
            acc_y.append(int(search_acc.group(2)))
            acc_z.append(int(search_acc.group(3)))
            step_acc.append(j)
            j = j + 1

        search_ang =re.search(pattern_ang, line, re.I)
        if(search_ang  is not None):
            print (line)
            print (search_ang.group(1))
            print (search_ang.group(2))
            print (search_ang.group(3))
            ang_x.append(int(search_ang.group(1)))
            ang_y.append(int(search_ang.group(2)))
            ang_z.append(int(search_ang.group(3)))
            step_ang.append(k)
            k = k + 1

plt.subplot(2,  1,  1)
plt.plot(step_acc, acc_x, "c*-.", label="acc_x")
plt.plot(step_acc, acc_y, "gv:", label="acc_y")
plt.plot(step_acc, acc_z, "y^--", label="acc_z")
plt.legend(loc="upper left")
plt.subplot(2,  1,  2)
plt.plot(step_ang, ang_x, "r*-.", label="ang_x")
plt.plot(step_ang, ang_y, "mv:", label="ang_y")
plt.plot(step_ang, ang_z, "b^--", label="ang_z")
#plt.title("Matplotlib demo")
#plt.xlabel("x axis caption")
#plt.ylabel("y axis caption")
plt.legend(loc="upper left")
plt.show()

# 
# pres idx:0 staus:0x1, data: 0x1fbed7
# pres idx:1 staus:0x1, data: 0x1fbcf4
pattern_pres0 =r'.*pres idx:0 .*data: (\b0x[0-9a-fA-F]+\b)'
pattern_pres1 =r'.*pres idx:1 .*data: (\b0x[0-9a-fA-F]+\b)'

step_sample = []
sample_0, sample_1, sample_diff = [], [], []

with open(filename, 'r', encoding='UTF-8') as f:
    lines = f.readlines()
    i = 0
    cnt = 0
    tmp = 0
    #k = 0
    for line in lines:
        if cnt == 0:
            search_pressure0 =re.search(pattern_pressure0, line, re.I)
            if(search_pressure0  is not None):
                print (line)
                print (search_pressure0.group(1))
                tmp = int(search_pressure0.group(1), 16)
                cnt = cnt + 1
        else:
            cnt = cnt + 1
            search_pressure1 =re.search(pattern_pressure1, line, re.I)
            if (search_pressure1  is not None):
                print (line)
                print (search_pressure1.group(1))
                sample_1.append(int(search_pressure1.group(1), 16))
                sample_0.append(tmp)
                sample_diff.append(tmp - int(search_pressure1.group(1), 16))
                step_sample.append(i)


参考文档:
Matplotlib 可视化最有价值的 50 个图表
NumPy Matplotlib
https://matplotlib.org/
Python绘图总结(Matplotlib篇)之坐标轴及刻度
Matplotlib 教程
Python 绘图,我只用 Matplotlib(二)
Python 正则表达式验证十六进制数字
Python中进制转换及int()函数;

notepad++开发python环境配置

按“F5”键,输入命令“cmd /k python “$(FULL_CURRENT_PATH)” & ECHO. & PAUSE & EXIT
保存并设置快捷键,即可在“运行”菜单看到所设置的快捷键了!

如下命令也是可以的:

cmd /k cd /d “$(CURRENT_DIRECTORY)” & python “$(FULL_CURRENT_PATH)” & ECHO. & PAUSE & EXIT

详情可参考下面两文章:

  1. 如何用Notepad++开发Python程序?
  2. 在Notepad++里配置python环境

pyserial安装——python串口开发

pyserial的下载地址:https://pypi.org/project/pyserial/, 可以下载后自己编译,也可以在windows命令行中输入“pip install pyserial”的方式进行安装。
参考如下:

  1. 【Python入门】 使用 pip 安装 pySerial 串口通讯模块
  2. windows Python安装Pyserial
    在这里插入图片描述
    在这里插入图片描述

python3.7/3.8 IDLE打不开,import tkinter编译报错:_tkinter.TclError

  • 现象1——win7 64位按照python3.7.3后,IDLE打不开。
  • 现象2——运行有“import tkinter”的文件时,提示错误如下:

_tkinter.TclError: Can’t find a usable init.tcl in the following directories:
{D:\Program Files (x86)\CSR\BlueSuite 2.6.7} {C:/Program Files/Python37/lib/tcl8.6}
{C:/Program Files/lib/tcl8.6} C:/lib/tcl8.6 {C:/Program Files/library} C:/library C:/tcl8.6.9/library C:/tcl8.6.9/library
This probably means that Tcl wasn’t installed properly.

网上搜索了下解决办法,有修改环境变量解决的,也有建议拷贝tcl8.6文件的。

  1. 解决:easygui.msgbox(“Hello there!”)报错:Tcl_Init error: Can’t find a usable init.tcl in the following directories问题的解决
  2. 在windows下的虚拟环境中使用tk,要留神了

其实从提示的错误信息来看,python要找tcl8.6这个文件夹,搜索了很多目录找不到。查看安装目录,发现tcl8.6文件夹在目录下的tcl文件夹中。
在这里插入图片描述
个人感觉,python既然安装目录是这样的情况,那么简单的将tcl8.6文件夹拷贝到lib文件中显得有点笨拙,于是就选择修改环境变量来尝试了,经过多次测试,修改了两个环境变量就解决了上面的问题。

  1. 环境变量“PATH”中添加项“ C:\Program Files\Python37\tcl;”
    在这里插入图片描述
  2. 环境变量“TCL_LIBRARY”修改为“ C:\Program Files\Python37\tcl\tcl8.6”
    在这里插入图片描述
    在这里插入图片描述
    python3.8安装后也是tk、Matplotlib均无法使用,按照上图拷贝后正常了。

修改环境变量的方法可参考:https://jingyan.baidu.com/article/20b68a888931b6796cec622d.html

如何将python程序打包成exe文件

使用命令“pip install pyinstaller”安装pyinstaller,之后运行pyinstaller命令即可打包,命令格式如下:

pyinstaller -F -w (-i icofile) filename
    // filename表示你的Python程序文件名
    //  -w 表示隐藏程序运行时的命令行窗口(不加-w会有黑色窗口)括号内的为可选参数
    // -i icofile表示给程序加上图标,,图标必须为.ico格式
    // icofile表示图标的位置,建议直接放在程序文件夹里面,这样子打包的时候直接写文件名就好,输入完成,按回车即可自动打包。

参考:

  1. Python打包项目为EXE程序
  2. 轻松的将python程序打包为独立的EXE文件,并配上自定义的图标

查看pyinstaller参数:
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值