Can';找不到Python模块-队列、websocketserver
更新-19年4月30日: 谢谢你帮助我。我将该行更改为queue.queue(),现在出现以下错误:Can';找不到Python模块-队列、websocketserver,python,python-3.x,tornado,Python,Python 3.x,Tornado,更新-19年4月30日: 谢谢你帮助我。我将该行更改为queue.queue(),现在出现以下错误: $ python3 netgrafio1.py 2019-04-30 16:58:45,470 - DEBUG - [asyncio] - Using selector: EpollSelector 2019-04-30 16:58:45,472 - INFO - [WebSocketServer] - Starting WebSocket server on port 8080 2019-04
$ python3 netgrafio1.py
2019-04-30 16:58:45,470 - DEBUG - [asyncio] - Using selector: EpollSelector
2019-04-30 16:58:45,472 - INFO - [WebSocketServer] - Starting WebSocket server on port 8080
2019-04-30 16:58:45,472 - INFO - [WebSocketServer] - Start collector server
2019-04-30 16:58:45,473 - INFO - [WebSocketServer] - Waiting for incoming data ...
2019-04-30 16:58:45,477 - INFO - [WebServer] - Listening on 5000
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/home/ubuntu/netgrafio/lib/WebServer.py", line 114, in start_server
http_server = Thread(target=IOLoop.instance().start)
File "/home/ubuntu/.local/lib/python3.5/site-packages/tornado/ioloop.py", line 201, in instance
return IOLoop.current()
File "/home/ubuntu/.local/lib/python3.5/site-packages/tornado/ioloop.py", line 265, in current
loop = asyncio.get_event_loop()
File "/usr/lib/python3.5/asyncio/events.py", line 632, in get_event_loop
return get_event_loop_policy().get_event_loop()
File "/usr/lib/python3.5/asyncio/events.py", line 578, in get_event_loop
% threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-3'.
Traceback (most recent call last):
File "netgrafio1.py", line 100, in <module>
main(parse_args(sys.argv[1:]))
File "netgrafio1.py", line 95, in main
tcp_server = JSONServer(host, int(params.tcp_port), in_queue)
NameError: name 'JSONServer' is not defined
运行此命令时:
python netgrafio1.py -h
python3 netgrafio1.py
我得到这个错误:
Traceback (most recent call last):
File "netgrafio1.py", line 44, in <module>
from lib.WebSocketServer import WebSocketServer
File "/home/ubuntu/netgrafio/lib/WebSocketServer.py", line 54, in <module>
from queue import Queue
Traceback (most recent call last):
File "netgrafio1.py", line 44, in <module>
from lib.WebSocketServer import WebSocketServer
File "/home/ubuntu/netgrafio/lib/WebSocketServer.py", line 46, in <module>
import tornado.web
ImportError: No module named 'tornado'
我得到这个错误:
Traceback (most recent call last):
File "netgrafio1.py", line 44, in <module>
from lib.WebSocketServer import WebSocketServer
File "/home/ubuntu/netgrafio/lib/WebSocketServer.py", line 54, in <module>
from queue import Queue
Traceback (most recent call last):
File "netgrafio1.py", line 44, in <module>
from lib.WebSocketServer import WebSocketServer
File "/home/ubuntu/netgrafio/lib/WebSocketServer.py", line 46, in <module>
import tornado.web
ImportError: No module named 'tornado'
我正在尝试让netgrafio运行,因此我得到以下结果:
$ python netgrafio.py -h
usage: netgrafio.py [-h] [--tcp-port TCP_PORT] [--ws-port WS_PORT]
[--web-port WEB_PORT] [--host HOST]
netgrafio - visualize your network
optional arguments:
-h, --help show this help message and exit
--tcp-port TCP_PORT Specify TCP port to listen for JSON packets (default:
8081)
--ws-port WS_PORT Specify WebSocket port to send JSON data to (default:
8080)
--web-port WEB_PORT Specify web port to server web application (default:
5000)
--host HOST Specify host to bind socket on (default: 127.0.0.1)
当您使用
python…
命令时,您的操作系统可能正在运行python2.7。在Python2.7中,没有队列
模块。在v2.7中,它被称为队列
。在v3中,它被重命名为队列
当您运行python3…
时,您的操作系统正在运行python3.x。尽管这个版本有队列
模块,但是您还没有安装Tornado for Python 3
要解决此问题,请安装Tornado for Python 3:
pip3 install tornado
然后使用python3…
命令运行脚本
更新与新错误相关
队列
不是可调用对象;它是一个模块(即python文件)。请参阅模块的文档。您需要在代码中使用queue.queue
in_queue = queue.Queue()
当您使用
python…
命令时,您的操作系统可能正在运行python2.7。在Python2.7中,没有队列
模块。在v2.7中,它被称为队列
。在v3中,它被重命名为队列
当您运行python3…
时,您的操作系统正在运行python3.x。尽管这个版本有队列
模块,但是您还没有安装Tornado for Python 3
要解决此问题,请安装Tornado for Python 3:
pip3 install tornado
然后使用python3…
命令运行脚本
更新与新错误相关
队列
不是可调用对象;它是一个模块(即python文件)。请参阅模块的文档。您需要在代码中使用queue.queue
in_queue = queue.Queue()
你能试试“pip3安装tornado”然后运行脚本吗?完成后,我必须根据需要更新pip3并用pip3安装flask。我也会发布我的新错误。@xpewpewx我已经根据新错误更新了我的答案。我投票结束这个问题,因为OP似乎不具备Python的基本知识,希望其他人修复他们遇到的每个错误。公平点,让我试着解决这个问题。我们现在还不能结束这个。你能试试“pip3安装tornado”然后运行脚本吗?完成后,我必须根据需要更新pip3并用pip3安装flask。我也会发布我的新错误。@xpewpewx我已经根据新错误更新了我的答案。我投票结束这个问题,因为OP似乎不具备Python的基本知识,希望其他人修复他们遇到的每个错误。公平点,让我试着解决这个问题。让我们暂时不要关闭它。@xpewpewx新的错误表示未定义
JSONServer
。我认为这是非常清楚的。请不要期望人们为您调试所有代码:堆栈溢出不是调试服务。这都是基本的Python。如果您不这样做,请花一些时间学习该语言。@xpewpewx新的错误表示未定义JSONServer
。我认为这是非常清楚的。请不要期望人们为您调试所有代码:堆栈溢出不是调试服务。这都是基本的Python。如果你不知道,请花点时间学习这门语言。