gpt4 book ai didi

python - ImportError: cannot import name properties python error while importing serial

转载 作者:太空宇宙 更新时间:2023-11-04 04:57:07 32 4
gpt4 key购买 nike

导入序列号时,出现以下错误:

Traceback (most recent call last):
File "main.py", line 4, in <module>
import serial # library for communicating through Serial (used to connect to Arduino)
File "/usr/local/lib/python2.7/dist-packages/serial/__init__.py", line 1, in <module>
from serial import properties, meta, model, utilities, errors
File "/usr/local/lib/python2.7/dist-packages/serial/properties.py", line 7, in <module>
from serial import meta, model
File "/usr/local/lib/python2.7/dist-packages/serial/meta.py", line 12, in <module>
from serial import model
File "/usr/local/lib/python2.7/dist-packages/serial/model.py", line 15, in <module>
from serial import properties, meta
ImportError: cannot import name properties

我已经安装了这个包。我想不明白。请帮忙。

最佳答案

看起来你想使用 pyserial,但是 pyserial 没有 properties.py,没有 meta.py 也没有 model .py,参见:https://github.com/pyserial/pyserial/tree/master/serial所以你显示的堆栈跟踪不是来自 pyserial。

所以另一个包和pyserial之间有冲突。

在 Python 中隔离工作环境的日常解决方案是使用 virtual environment ,比如:

$ cd /tmp/
$ mkdir -p ~/.venvs/
$ python3 -m venv ~/.venvs/my_project_using_pyserial/
$ . ~/.venvs/my_project_using_pyserial/bin/activate
(my_project_using_pyserial) $ python3 -m pip install pyserial
Collecting pyserial
Downloading pyserial-3.4-py2.py3-none-any.whl (193kB)
100% |████████████████████████████████| 194kB 2.2MB/s
Installing collected packages: pyserial
Successfully installed pyserial-3.4
(my_project_using_pyserial) $ python3
Python 3.5.4 (default, Aug 12 2017, 14:08:14)
[GCC 7.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> dir(serial)
['CR', 'EIGHTBITS', 'FIVEBITS', 'LF', 'PARITY_EVEN', 'PARITY_MARK', 'PARITY_NAMES', 'PARITY_NONE', 'PARITY_ODD', 'PARITY_SPACE', 'PosixPollSerial', 'SEVENBITS', 'SIXBITS', 'STOPBITS_ONE', 'STOPBITS_ONE_POINT_FIVE', 'STOPBITS_TWO', 'Serial', 'SerialBase', 'SerialException', 'SerialTimeoutException', 'Timeout', 'VERSION', 'VTIMESerial', 'XOFF', 'XON', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'basestring', 'importlib', 'io', 'iterbytes', 'os', 'portNotOpenError', 'protocol_handler_packages', 'serial_for_url', 'serialposix', 'serialutil', 'sys', 'time', 'to_bytes', 'unicode', 'writeTimeoutError']

关于python - ImportError: cannot import name properties python error while importing serial,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46797922/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com