Python SocketIO_client失败 导入错误:没有名为 socketIO_client 的模块



我安装了 https://pypi.python.org/pypi/socketIO-client 来向volumio API发送消息。我的蟒蛇脚本:

#!/usr/bin/env python
from socketIO_client import SocketIO, LoggingNamespace
socketIO = SocketIO('localhost', 3000)
socketIO.emit('play')

我收到此错误:

 volumio@volumio:/home/FTP$ sudo python volumio-testSocket.py
    Traceback (most recent call last):
      File "volumio-testSocket.py", line 3, in <module>
        from socketIO_client import SocketIO, LoggingNamespace
    ImportError: No module named socketIO_client

但是当我在终端中运行时,我的脚本正在工作:

volumio@volumio:/home/FTP$ python
Python 2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from socketIO_client import SocketIO, LoggingNamespace
>>> socketIO = SocketIO('localhost', 3000)
>>> socketIO.emit('play')

有人可以帮我吗?

我使用pip install -U socketIO-client --user安装了socketIO-client,因此当我调用python而不是"sudo python"时它可以工作。

我需要 sudo 才能使用 gpio,所以这次我用 sudo pip install -U socketIO-client重新安装了它。

我不是 100% 确定,但如果您的系统上安装了多个版本的 Python,Python 的终端版本可能会链接到与尝试从文件运行脚本的版本不同的版本。因此,其中一个版本可能安装了模块,而另一个版本可能没有。

这可能值得一看。

希望有帮助。

最新更新