龙空技术网

Python实现串口助手 - 01环境搭建

春风不得意丶 137

前言:

目前朋友们对“python27的安装”大约比较注重,大家都想要剖析一些“python27的安装”的相关文章。那么小编也在网上网罗了一些有关“python27的安装””的相关知识,希望你们能喜欢,大家一起来了解一下吧!

今天给大家介绍的是串口调试工具pzh-py-com诞生之环境搭建。

  在写pzh-py-com时需要先搭好开发和调试环境,下表列出了开发过程中会用到的所有软件/工具包:

一、涉及工具列表

工具

功能

下载地址

Python 2.7.14

Python官方包(解释器)

pySerial 3.4

Serial Port访问的Python封装库

wxPython 4.0.3

跨平台开源GUI库 [wxWidgets]() 的Python封装库

wxFormBuilder 3.8.0

wxPython GUI界面构建工具

PyCharm Community 2018.02

一款流行的Python集成开发环境

PyInstaller 3.3.1

Python应用程序打包工具

vspd 9

虚拟串口驱动,可以在PC上虚拟出Serial Port

sscom 5.13.1

大虾和丁丁联合推出的一款很流行的串口调试工具

二、开发环境搭建(Python + pySerial + wxPython + wxFormBuilder)

  pzh-py-com工具是一个完全基于Python语言开发的应用软件,首先安装好Python 2.7.14,痞子衡的安装目录为C:\tools_mcu\Python27,安装完成后确保系统环境变量里包括该路径(C:\tools_mcu\Python27),因为该路径下包含python.exe,后续python命令需调用这个python.exe完成的。

  在C:\tools_mcu\Python27\Scripts目录下默认有easy_install.exe,这是PEAK(Python Enterprise Application Kit)开发的setuptools包里的工具,这个工具可以用来完成安装python第三方模块的工作。我们需要借助easy_install.exe来安装pip工具:

PS C:\tools_mcu\Python27\Scripts> .\easy_install.exe pip

Searching for pip

Best match: pip 9.0.1

Adding pip 9.0.1 to easy-install.pth file

Installing pip-script.py script to c:\tools_mcu\python27\Scripts

Installing pip.exe script to c:\tools_mcu\python27\Scripts

Installing pip3.5-script.py script to c:\tools_mcu\python27\Scripts

Installing pip3.5.exe script to c:\tools_mcu\python27\Scripts

Installing pip3-script.py script to c:\tools_mcu\python27\Scripts

Installing pip3.exe script to c:\tools_mcu\python27\Scripts

Using c:\tools_mcu\python27\lib\site-packages

Processing dependencies for pip

Finished processing dependencies for pip

PS C:\tools_mcu\Python27\Scripts> python -m pip install --upgrade pip

Collecting pip

Downloading > (1.3MB)

Installing collected packages: pip

Found existing installation: pip 9.0.1

Uninstalling pip-9.0.1:

Successfully uninstalled pip-9.0.1

Successfully installed pip-18.0

  pip是Python的包管理工具,提供了对Python包的查找、下载、安装、卸载的功能。安装好pip工具之后,可以看到C:\tools_mcu\Python27\Scripts目录下多了pip.exe,为方便后续使用pip来安装其他Python包,确保系统环境变量里包括pip路径(C:\tools_mcu\Python27\Scripts)。我们可以借助pip来安装pySerial和wxPython包:

PS C:\tools_mcu\Python27\Scripts> .\pip.exe install pyserial

Collecting pyserial

Downloading (193kB)

Installing collected packages: pyserial

Successfully installed pyserial-3.4

PS C:\tools_mcu\Python27\Scripts> .\pip.exe install wxPython

Collecting wxPython

Downloading (22.8MB)

Collecting six (from wxPython)

Downloading

Collecting PyPubSub (from wxPython)

Downloading (64kB)

Collecting typing (from PyPubSub->wxPython)

Downloading

Installing collected packages: six, typing, PyPubSub, wxPython

Running setup.py install for PyPubSub ... done

The scripts helpviewer.exe, img2png.exe, img2py.exe, img2xpm.exe, pycrust.exe, pyshell.exe, pyslices.exe, pyslicesshell.exe, pywxrc.exe, wxdemo.exe, wxdocs.exe and wxget.exe are installed in 'c:\tools_mcu\python27\Scripts'

Successfully installed PyPubSub-4.0.0 six-1.11.0 typing-3.6.4 wxPython-4.0.3

  有了pySerial便可以访问Serial Port,有了wxPython便可以设计GUI。

  单纯使用wxPython设计pzh-py-com GUI界面时仅能是手工写代码布局,手工布局的界面创建和修改起来都比较繁琐,我们需要一款可视化的界面设计工具,痞子衡选择的是wxFormBuilder,从其github官网下载安装包并安装到C:\tools_mcu\wxFormBuilder目录下。安装完成打开软件便可在Designer里尽情创作界面,创作完成后点击"Python"便可看到Python GUI源代码,这个GUI源代码后续直接复制到JaysPyCOM工程里使用。

  至此pzh-py-com工具开发的Python基础环境便搭好了。

三、测试环境搭建(PyCharm + vspd + sscom)

  在开发pzh-py-com工具过程中免不了要调试Python代码,所以我们还需要一个Python IDE,痞子衡选择的是PyCharm,在jetbrains官网下载PyCharm community免费版并安装,安装完成后打开PyCharm并创建名为pzh-py-com空工程,成功创建后会看到pzh-py-com目录下自动生成一个.idea的文件夹,该文件夹是用于pycharm管理项目。

  有了PyCharm环境,便可以开始写pzh-py-com代码,代码在开发过程中,需要结合Serial Port进行联合调试,如果手里没有硬件串口设备,可以使用虚拟串口设备,vspd便是著名的虚拟串口驱动,从eltima官网下载vspd标准版并安装,安装完成后打开vspd可看到如下界面,COM10和COM11(COM号是自定义的)便是虚拟出来的串口设备号,并且已经完成了对接。

  虚拟Serial Port设备已经有了并且对接了,最后还需要一个成熟的串口调试助手,作为串口通讯的另一方,痞子衡选取的是非常经典的sscom,从大虾官网下载sscom包,sscom是个免安装的工具,可以直接打开使用,设置sscom使用COM11,将来pzh-py-com使用COM10。

四、发布环境搭建(PyInstaller)

  pzh-py-com工具开发和调试工作都完成之后,我们希望将她打包成一个独立的可执行文件(即运行设备不需要安装Python+pySerial+wxPython),PyInstaller可以帮助我们完成打包工作,所以我们需要利用pip工具安装PyInstaller包:

PS C:\tools_mcu\Python27\Scripts> .\pip.exe install pyinstaller

Collecting pyinstaller

Downloading (3.5MB)

Requirement already satisfied: setuptools in c:\tools_mcu\python27\lib\site-packages (from pyinstaller) (28.8.0)

Collecting pefile>=2017.8.1 (from pyinstaller)

Downloading (62kB)

Collecting macholib>=1.8 (from pyinstaller)

Downloading

Collecting dis3 (from pyinstaller)

Downloading

Collecting future (from pyinstaller)

Downloading (824kB)

Collecting pypiwin32 (from pyinstaller)

Downloading

Collecting altgraph>=0.15 (from macholib>=1.8->pyinstaller)

Downloading

Collecting pywin32>=223 (from pypiwin32->pyinstaller)

Downloading (7.3MB)

Installing collected packages: future, pefile, altgraph, macholib, dis3, pywin32, pypiwin32, pyinstaller

Running setup.py install for future ... done

Running setup.py install for pefile ... done

Running setup.py install for dis3 ... done

Running setup.py install for pypiwin32 ... done

Running setup.py install for pyinstaller ... done

Successfully installed altgraph-0.16.1 dis3-0.1.2 future-0.16.0 macholib-1.10 pefile-2018.8.8 pyinstaller-3.3.1 pypiwin32-223 pywin32-223

  PyInstaller包安装好之后,环境搭建便大功告成

  至此,串口调试工具pzh-py-com诞生之环境搭建便介绍完毕了

标签: #python27的安装