8

I'm using Python 3 with Anaconda on Windows 7. I installed Twisted with conda install twisted, and now I'm trying to run twisted (or twistd?) from the console, but I get this error

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

which makes me think a directory is missing from the path, as in this question. Anaconda is installed in C:\Anaconda3, but even in C:\Anaconda3\Lib\site-packages\twisted, there isn't a twisted.py or twistd.py file.

Am I doing something wrong, or am I looking in the wrong place for the file(s)?

Is this an issue because Twisted isn't officially ported to Python 3 yet?

Community
  • 1
  • 1
Michael A
  • 4,391
  • 8
  • 34
  • 61
  • 1
    `twisted` should install console-scripts into the binary/script folder of your Python installation. I don't have anaconda, but it's basically "just" a python installation. So try a search in your `C:\Anaconda3\` directory, with `twistd.bat` or `twistd.*` – deets Jul 08 '15 at 20:24
  • 2
    It's `twistd`. Have you tried `twistd`? – ljk321 Jul 10 '15 at 08:40
  • 1
    @MichaelA Why would you ever want to run that command? The Python code executes perfectly running `python filename.py`. –  Jul 10 '15 at 13:34
  • 1
    It should be in `/twisted/scripts/twistd.py` – Padraic Cunningham Jul 10 '15 at 13:46
  • 1
    @skyline75489 Yes, I have. (I mentioned looking for both `twisted` and `twistd` in my original question). – Michael A Jul 13 '15 at 14:24
  • 1
    @deets None of those searches return any results, except for one `twisted.py` file in the `Lib/site-packages/tornado/platform/` directory. The Anaconda installation does have a `Lib/site-packages/twisted/` directory, but it doesn't contain a `scripts/` subdirectory or any files named `twisted.py` or `twistd.py`. – Michael A Jul 13 '15 at 14:29
  • 2
    I got the same results as you. The anaconda 2.3.0/python 3.4.3 install of twisted just creates pkgs/twisted-15.2.1-py34_0.tar.bz2. After installation was able to import twisted and some but not all of its subclasses which should be there if it was complete. In conclusion this release of twisted for python 3 is incomplete and there is no quick fix. –  Jul 14 '15 at 02:45

3 Answers3

4

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.

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

Run:

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

Where in C:\path\to\twistd.py you insert the path to the twistd.py file.

Community
  • 1
  • 1
4

twistd runs twisted applications (though you can run a script with Twisted code in it like any other Python file) and should be in the bin directory inside your Anaconda installation directory, so if you can get conda, you can get twistd as well.

twisted is the library you use to write code that uses Twisted, so you can't run that from the command line.

Here is the status of Twisted on Python3 https://twistedmatrix.com/trac/milestone/Python-3.x

And here is the particular ticket about twistd not being available on Python3 yet https://twistedmatrix.com/trac/ticket/7497

belteshazzar
  • 2,163
  • 2
  • 21
  • 30
  • 1
    But how does that fix the issue? –  Jul 16 '15 at 21:10
  • @J.C.Rocamonde It informs the asker that twisted is not fully available yet, where to check the progress of porting to Python3, and that if he wants all of twisted, he will have to use Python2, and if he does it will work as expected. – belteshazzar Jul 17 '15 at 05:51
2

Twisted is a Python library. To use it, you could import it e.g., here's a web server from 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()

Save it to a file e.g., counter_server.py and run: py counter_server.py. You could visit http://localhost:8080/ to make sure it works (it doesn't with twisted-15.2.1 version on Python 3). Twisted is ported only partially to Python 3 (the graph is based on the data from a year ago).

twistd is a Python program that uses twisted Python package (note: e). It is not ported to Python 3 yet (pip install twisted installs it on Python 2 but it doesn't install it on Python 3).

jfs
  • 399,953
  • 195
  • 994
  • 1,670