原因
因为需要在windows上调试板子的串口,用到了python的serial方法。
在pycharm中虽然安装了pip和serial,但是执行py的时候一直在报错,提示
AttributeError: module 'serial' has no attribute 'Serial'
于是准备直接安装windows下的serial。
安装
环境前提:Python2.7已经安装完毕
1.下载ez_setup-0.9,地址
https://pypi.python.org/packages/ba/2c/743df41bd6b3298706dfe91b0c7ecdc47f2dc1a3104abeb6e9aa4a45fa5d/ez_setup-0.9.tar.gz
2.解压后,运行ez_setup.py
3.在python的安装目录下的S会生成一个Scripts文件夹,使用管理员权限打开cmd或者powerShell,然后执行 .\easy_install.exe pip
4.查看pip版本,证明安装成功
.\pip.exe --version
pip 19.1.1 from C:\Program Files (x86)\Python\2.7\lib\site-packages\pip (python 2.7)
5.安装pyserial
.\pip.exe install pyserial
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting pyserial
Downloading https://files.pythonhosted.org/packages/0d/e4/2a744dd9e3be04a0c0907414e2a01a7c88bb3915cbe3c8cc06e209f59c30/pyserial-3.4-py2.py3-none-any.whl (193kB)
|████████████████████████████████| 194kB 29kB/s
Installing collected packages: pyserial
Successfully installed pyserial-3.4
6.完毕
此时再次打开pycharm,运行py程序,发现成功执行,可以通过serial正常调用串口