没有名为serial的模块

时间:2015-10-21 18:54:35

标签: python

我在运行Python代码时遇到了一个问题。

我在Windows 7上安装了Python 2.7,位64。 我收到错误"没有名为serial"当我编译我的代码时:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim HotArea As Range

    Set HotArea = Range("C17,C21,C25,C29,C33,C42,C46,C50,C54,C58,C67,C71,C75,C83,C87,C91,C100,M17")
    Set HotArea = Union(HotArea, Range("M21,M25,M29,M33,M42,M46,M55,M59,M69,M73,M82,M86,W17,W21,W25,W29,AG17,AG21,AG25,AG34"))
    Set HotArea = Union(HotArea, Range("AG38,AG42,AG51,AG55,AG59,AG68,AG72,AG81,AG85,AG89,AG98,AG102,AG106,AG110,AG114,AQ17"))
    Set HotArea = Union(HotArea, Range("AQ21,AQ30,AQ34,AQ43,AQ47,AQ51,AQ60,AQ64,BA17,BA21,BA25,BA29,BA33,BA37,BA46,BA50,BA54"))
    Set HotArea = Union(HotArea, Range("BA58,BA62,BA71,BA75,BA79,BA89,BA93"))

    If Not Intersect(Target, HotArea) Is Nothing Then
    Select Case Target.Item(1)
    Case ""
        Target = "P1"
        Target.Interior.ColorIndex = 3
    Case "P1"
        Target = "P2"
        Target.Interior.ColorIndex = 6
    Case "P2"
        Target = "P3"
        Target.Interior.ColorIndex = 50
    Case "P3"
        Target = "P4"
        Target.Interior.ColorIndex = 23
    Case Else
        Target = ""
        Target.Interior.ColorIndex = xlNone
    End Select
    Cancel = True
    End If



    Set HotArea = Range("C19,C23,C27,C31,C35,C44,C48,C52,C56,C60,C69,C73,C77,C85,C89,C93,C102,M19")
    Set HotArea = Union(HotArea, Range("M23,M27,M31,M35,M44,M48,M57,M61,M71,M75,M84,M88,W19,W23,W27,W31,AG19,AG23,AG27,AG36"))
    Set HotArea = Union(HotArea, Range("AG40,AG44,AG53,AG57,AG61,AG70,AG74,AG83,AG87,AG91,AG100,AG104,AG108,AG112,AG116,AQ19"))
    Set HotArea = Union(HotArea, Range("AQ23,AQ32,AQ36,AQ45,AQ49,AQ53,AQ62,AQ66,BA19,BA23,BA27,BA31,BA35,BA39,BA48,BA52,BA56"))
    Set HotArea = Union(HotArea, Range("BA60,BA64,BA73,BA77,BA81,BA91,BA95"))

    If Not Intersect(Target, HotArea) Is Nothing Then

        'If the target cell is clear
        If Target.Interior.ColorIndex = xlNone Then
        'Then change the background to the specified color
        Target.Interior.ColorIndex = 4

    'But if the target cell is already the specified color
        ElseIf Target.Interior.ColorIndex = 4 Then

        'Then change the background to the specified color
        Target.Interior.ColorIndex = 6

       'But if the target cell is already the specified color
        ElseIf Target.Interior.ColorIndex = 6 Then

        'Then change the background to the specified color
        Target.Interior.ColorIndex = 3

        'But if the target cell is already the specified color
        ElseIf Target.Interior.ColorIndex = 3 Then

        'Then change the background to the specified color
        Target.Interior.ColorIndex = 5

        'But if the target cell is already the specified color
        ElseIf Target.Interior.ColorIndex = 5 Then

        'Then change the background to the specified color
        Target.Interior.ColorIndex = x1None
    End If
    Cancel = True
    End If

End Sub

我尝试了很多方法来解决这个问题,例如安装Canopy来设置虚拟环境,确保“pip”#p;在那里,没有安装Python v 3.x. 但仍然无法理解。

任何建议都将受到赞赏。

10 个答案:

答案 0 :(得分:57)

Python不包含Serial。这是一个您需要单独安装的软件包。

由于你安装了pip,你可以从命令行安装serial:

pip install pyserial

或者,您可以使用here中的Windows安装程序。看起来您正在使用Python 3,因此请单击Python 3的安装程序。

然后你应该能够像以前一样尝试导入序列号。

答案 1 :(得分:11)

您必须先pip install pyserial

答案 2 :(得分:5)

您必须安装pyserial库。您不需要串行库。因此,如果预安装了串行库,请将其卸载。安装pyserial libray。有许多安装方法: -

  1. pip install pyserial
  2. 从pyserial下载zip并将提取的库保存在Lib的>> site-packages文件夹中。
  3. 使用命令pip install <wheelname>
  4. 下载车轮并安装车轮

    链接:https://github.com/pyserial/pyserial/releases

    安装Pyserial后,导航到安装pyserial的位置。您将看到“setup.py”文件。在同一目录中打开Power Shell或CMD并运行命令“python setup.py install”。 现在您可以使用pyserial库的所有功能而不会出现任何错误。

答案 3 :(得分:4)

下载此文件: - (https://pypi.python.org/packages/1f/3b/ee6f354bcb1e28a7cd735be98f39ecf80554948284b41e9f7965951befa6/pyserial-3.2.1.tar.gz#md5=7142a421c8b35d2dac6c47c254db023d):

cd /opt
sudo tar -xvf ~/Downloads/pyserial-3.2.1.tar.gz -C .
cd /opt/pyserial-3.2.1 
sudo python setup.py install 

答案 4 :(得分:2)

  1. 首先使用命令pip uninstall pyserial
  2. 卸载pyserial
  3. 然后转到https://www.lfd.uci.edu/~gohlke/pythonlibs/和serial for pyserial
  4. 下载合适的pyserial版本,然后转到 下载文件的目录并打开cmd那里
  5. 然后编写pip install&#34;文件已下载&#34;

答案 5 :(得分:1)

首次使用命令

pip uninstall pyserial

然后再次运行

 pip install pyserial

以上命令将使用系统解释器对其进行索引。

答案 6 :(得分:1)

我多次遇到同样的问题,但最终找到了解决方案。

我安装了多个 Python 版本。就像在 Raspberry Pi 中安装了 Python3.5 一样,我也安装了 3.9.2 而没有卸载 3.5。然后我用 pip 安装了 pyserial 并尝试了我的程序。没有模块...但原因是python3中的linux符号链接指向python3.9.2版本而pip3指向python3.5。所以pyserial安装在python3.5中,运行python3.9.2时没有找到可以理解。然后我将 pip3 中的符号链接更改为正确的版本,瞧,一切正常!

答案 7 :(得分:0)

这可能是很老的帖子,但我想分享我的经验。使用Pycharm时,我遇到了同样的问题,并且在“项目设置/首选项”的“项目解释器”页面中安装了该软件包。此问题已解决,请检查以下链接: https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html?_ga=2.41088674.1813230270.1594526819-1842497340.1594080707

答案 8 :(得分:0)

就我而言,下面的命令完成了工作

pip3 install pyserial

答案 9 :(得分:-2)

您没有安装serial软件包。

尝试pip install serial安装模块。

或者,从这里以二进制形式安装它:

Install Pyserial for Windows

请注意,您始终安装预编译的二进制文件需要您自担风险。

相关问题