问题
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.
回答1:
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.
回答2:
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.pyafter installingTwistedin your virtualenv. <virtualenv_root_dir>\Scriptsis 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.
来源:https://stackoverflow.com/questions/9440303/twistd-is-not-a-recognized-internal-or-external-command