I'm just starting with twisted.web, and I have a problem importing a Python module in a Script .rpy
script. In
C: \ py \ twisted \ mysite.py
, I have this:
Prepath: and I ran I can import modules from the interpreter, and if I just select Does anyone know the proper way to do this? c: \ py \ twisted \ index.rpy
I have it:
import mysit e reload ( Mysite) resources = mysite.mysite ()
twistd -n web --port 8888 --path c: \ py \ twisted
command prompt and the server started successfully but when i localhost: 8888
, then I found a huge (huge) stack trace generated from an imported errter:
index.rpy
If I execute as a dragon script, then I do not get an import error. The documentation on this topic is a bit unclear, it just says "However, it is often a better idea to define resource subclasses in Python module. To be visible for changes in the module, you must either restart the Python process Must be reloaded, or module: "(from).
short answer: to include you c: \ py \ twisted
There is a need to set the pathstone.
Long answer ...
One such script is basically just some python code, like any other python code. Therefore, any import in one rupee script works like importing into another python code for the most common case, it means that the directories present in sys.path
are viewed one by one, and If any .py
file matches the imported name, that file is used to define the module.
sys.path
is mostly populated with a static definition in which C: \ Python 26 \ lib \ and pithonpath
environment variables, however, learn about it There is an additional thing to do when you run "Python", then the existing working directory is added to sys.path
. When you run "Pyro c: \ fu \ bar \ baz.py", then c: \ foo \ bar \ 'is added to
sys.path . But when you run "twisted ...", then
sys.path`
< / P>
If you run python and interactively try to import the module, but fails when you use twistd C: The modules should be importable by adding \ py \ twisted
to PYTHONPATH
, when the rpy script runs from the server that you start with twistd.