我如何 运行 从控制台扭曲?

How do I run twisted from the console?

我在 Windows 7 上使用 Python 3 和 Anaconda。我用 conda install twisted 安装了 Twisted,现在我正在尝试 运行 twisted(或twistd?)来自控制台,但我收到此错误

'twisted' is not recognized as an internal or external command, operable program or batch file.

这让我觉得路径中缺少目录,如 this question 中所示。 Anaconda 安装在 C:\Anaconda3 中,但即使在 C:\Anaconda3\Lib\site-packages\twisted 中也没有 twisted.pytwistd.py 文件。

是我做错了什么,还是找错了文件位置?

这是一个问题,因为 Twisted 还没有正式移植到 Python 3 吗?

Don't confuse "Twisted" with "twistd". When you use "twistd", you are running the program with Python. "twistd" is a Python program that, among other things, can load an application from a .tac file (as you're doing here).

The "Twisted Command Prompt" is a Twisted installer-provided convenience to help out people on Windows. All it is doing is setting %PATH% to include the directory containing the "twistd" program. You could run twistd from a normal command prompt if you set your %PATH% properly or invoke it with the full path.

(来自 How do you you run a Twisted application via Python (instead of via Twisted)?

运行:

set PATH=%PATH%;C:\path\to\twistd.py

C:\path\to\twistd.py 中插入 twistd.py 文件的路径。

twistd 运行s 扭曲的应用程序(虽然你可以 运行 一个带有扭曲代码的脚本,就像任何其他 Python 文件一样)并且应该在 bin 目录在你的 Anaconda 安装目录中,所以如果你能得到 conda,你也能得到 twistd

twisted 是您用来编写使用 Twisted 的代码的库,因此您不能从命令行 运行。

这是 Twisted 在 Python3 https://twistedmatrix.com/trac/milestone/Python-3.x

上的状态

这是关于 twistd 在 Python3 https://twistedmatrix.com/trac/ticket/7497

上不可用的特定问题单

Twisted 是一个 Python 库。要使用它,您可以导入它,例如,这是来自 twisted home page:

的网络服务器
#!/usr/bin/env python
from twisted.web import server, resource
from twisted.internet import reactor, endpoints

class Counter(resource.Resource):
    isLeaf = True
    numberRequests = 0

    def render_GET(self, request):
        self.numberRequests += 1
        request.setHeader("content-type", "text/plain")
        return "I am request #" + str(self.numberRequests) + "\n"

endpoints.serverFromString(reactor, "tcp:8080").listen(server.Site(Counter()))
reactor.run()

将其保存到文件中,例如 counter_server.py 和 运行:py counter_server.py。您可以访问 http://localhost:8080/ 以确保它有效(它不适用于 Python 3 上的 twisted-15.2.1 版本)。 Twisted is ported only partially to Python 3(图表基于一年前的数据)。

twistd是一个Python程序,使用了twistedPython包(注:e)。它尚未移植到 Python 3(pip install twisted 将其安装在 Python 2 上,但未将其安装在 Python 3 上)。