2

I'm trying to develop a Twisted Web server but can't seem to run the twistd command. I've tried setting the python path and even included the path to the twistd.py script in my Path but nothing seems to work.

I'm using Twisted 12.0.0 and Python 2.7 on Windows. Any help would be hugely appreciated.

Glyph
  • 31,152
  • 11
  • 87
  • 129
Ben S
  • 129
  • 1
  • 9

2 Answers2

3

You need to set the %PATHEXT% environment variable to include .py, as well as %PATH% including the path to twistd. Your most-recently-installed version of Python should then automatically launch it, assuming the filetype association was set correctly by the installer.

Glyph
  • 31,152
  • 11
  • 87
  • 129
  • 1
    hmm it still doesn't work... are the % signs significant? On windows 7 the variables are just called "path" and "pathext" – Ben S Feb 26 '12 at 21:18
  • 1
    On Windows, environment variables are *expanded* by surrounding the variable with `%` characters in the shell. On UNIX, environment variables are expanded by prefixing the variables with the `$` character. So it is conventional to refer to a Windows environment variable as, for example, `%PATH%`, whereas it is conventional to refer to UNIX variables as, for example, `$PATH`. (Also, the variables are `PATH` and `PATHEXT`, not `path` and `pathext`. Case matters.) – Glyph Jul 17 '13 at 17:56
0

Create a twistd.bat and save it under your Scripts directory; if you're using virtualenv, the exact path is: <virtualenv_root_dir>\Scripts\twistd.bat

Edit twistd.bat and put the ff:

@echo off
python %~dp0twistd.py %*

Assumptions:

  • There should be a <virtualenv_root_dir>\Scripts\twistd.py after installing Twisted in your virtualenv.
  • <virtualenv_root_dir>\Scripts is in your %PATH%

Then after activating your virtualenv, you should be able to run twistd directly, e.g.

twistd web --path . --port 8080

I myself uses this approach in a Windows XP machine.

micmejia
  • 11
  • 2