ImportError: No module named controller

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

ImportError: No module named controller

Ben Marinic
Hi 

Basic issues again... :)  

I have created my classes (which are in the same folder) as follows:

startup.py:

import sys
import os
import controller

sys.path.append('/usr/src/pyamf/')
sys.path.append('/var/www/myProject')

os.environ['PYTHON_EGG_CACHE'] = '/var/www/python/'

from pyamf.remoting.gateway.wsgi import WSGIGateway

control = controller.MyController();

application = WSGIGateway({'echo': control.echo})


controller.py:

class MyController(object):

    def echo(self,data):
        return data


I have configured Apache with mod_wsgi per the instructions on the PyAMF website.  However, after I restart Apache and navigate to: flashservices.mydomain.com/gateway I get the following error in my Apache (virtual host) error log:

[Tue Dec 01 10:01:03 2009] [error] [client xx.xx.xx.xx.xx] mod_wsgi (pid=26548): Target WSGI script '/var/www/website/startup.py' cannot be loaded as Python module.
[Tue Dec 01 10:01:03 2009] [error] [client xx.xx.xx.xx.xx] mod_wsgi (pid=26548): Exception occurred processing WSGI script '/var/www/website/startup.py'.
[Tue Dec 01 10:01:03 2009] [error] [client xx.xx.xx.xx.xx] Traceback (most recent call last):
[Tue Dec 01 10:01:03 2009] [error] [client xx.xx.xx.xx.xx]   File "/var/www/website/startup.py", line 3, in <module>
[Tue Dec 01 10:01:03 2009] [error] [client xx.xx.xx.xx.xx]     import controller
[Tue Dec 01 10:01:03 2009] [error] [client xx.xx.xx.xx.xx] ImportError: No module named controller

As I'm new to this I thought possibly the PYTHONPATH is not set or incorrect?  Or could it be something else?

Thanks for your help!

Ben
                                                                                                 

Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159





_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: ImportError: No module named controller

Ben Marinic
BTW

sys.path.append('/var/www/myProject')

Is actually:

sys.path.append('/var/www/website')

I changed the path names for the email.  The paths are all correct so that's not the issue.

Cheers

On 1 Dec 2009, at 11:36, Ben Marinic wrote:

Hi 

Basic issues again... :)  

I have created my classes (which are in the same folder) as follows:

startup.py:

import sys
import os
import controller

sys.path.append('/usr/src/pyamf/')
sys.path.append('/var/www/myProject')

os.environ['PYTHON_EGG_CACHE'] = '/var/www/python/'

from pyamf.remoting.gateway.wsgi import WSGIGateway

control = controller.MyController();

application = WSGIGateway({'echo': control.echo})


controller.py:

class MyController(object):

    def echo(self,data):
        return data


I have configured Apache with mod_wsgi per the instructions on the PyAMF website.  However, after I restart Apache and navigate to: flashservices.mydomain.com/gateway I get the following error in my Apache (virtual host) error log:

[Tue Dec 01 10:01:03 2009] [error] [client xx.xx.xx.xx.xx] mod_wsgi (pid=26548): Target WSGI script '/var/www/website/startup.py' cannot be loaded as Python module.
[Tue Dec 01 10:01:03 2009] [error] [client xx.xx.xx.xx.xx] mod_wsgi (pid=26548): Exception occurred processing WSGI script '/var/www/website/startup.py'.
[Tue Dec 01 10:01:03 2009] [error] [client xx.xx.xx.xx.xx] Traceback (most recent call last):
[Tue Dec 01 10:01:03 2009] [error] [client xx.xx.xx.xx.xx]   File "/var/www/website/startup.py", line 3, in <module>
[Tue Dec 01 10:01:03 2009] [error] [client xx.xx.xx.xx.xx]     import controller
[Tue Dec 01 10:01:03 2009] [error] [client xx.xx.xx.xx.xx] ImportError: No module named controller

As I'm new to this I thought possibly the PYTHONPATH is not set or incorrect?  Or could it be something else?

Thanks for your help!

Ben
                                                                                                 

Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159





Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159





_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: ImportError: No module named controller

Rob Harvey
In reply to this post by Ben Marinic
Whenever you run into import errors in wsgi, try to import them
directly in a shell. In fact, for any errors you can't immediately
identify its worth trying it in the shell as much as you can.

> import sys
> import os
> import controller
> sys.path.append('/usr/src/pyamf/')
> sys.path.append('/var/www/myProject')

You're importing your controller module *before* you've added the
path. If you look at the error again, it mentions line #3 - so it
finds the error before it has even read about the extra paths.

 -rob
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: ImportError: No module named controller

Thijs Triemstra
I prefer to use the WSGIPythonPath directive of mod_wsgi, like:

WSGIPythonPath "/usr/src/pyamf:/var/www/myApp"
See http://docs.pyamf.org/current/tutorials/apache/mod_wsgi.html for  
the rest of the example.

Cheers,

Thijs

On 1 Dec 2009, at 15:49, Rob Harvey wrote:

> Whenever you run into import errors in wsgi, try to import them
> directly in a shell. In fact, for any errors you can't immediately
> identify its worth trying it in the shell as much as you can.
>
>> import sys
>> import os
>> import controller
>> sys.path.append('/usr/src/pyamf/')
>> sys.path.append('/var/www/myProject')
>
> You're importing your controller module *before* you've added the
> path. If you look at the error again, it mentions line #3 - so it
> finds the error before it has even read about the extra paths.
>
> -rob
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

PGP.sig (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ImportError: No module named controller

Thijs Triemstra
Oops, that page is currently showing an old version of the mod_wsgi  
tutorial, if you want to see the complete tutorial, run:

make html

in the /doc folder of a checkout of the pyamf trunk (requires sphinx).  
Anyway, here's the vhost i was talking about:

WSGIPythonPath "/usr/src/pyamf:/var/www/myApp"

<VirtualHost 192.168.1.100:80>

         ServerName example.server.com

         CustomLog /var/log/apache2/myApp-access.log combined
         ErrorLog /var/log/apache2/myApp-error.log

        # Set this to 'warn' when you're done with debugging
         LogLevel debug

         # PyAMF remoting gateway
         WSGIScriptAlias /flashservices/gateway /var/www/wsgi/myApp.wsgi

         <Directory /var/www/wsgi>
                 WSGIApplicationGroup %{GLOBAL}
                 Order allow,deny
                 Allow from all
         </Directory>

</VirtualHost>
On 1 Dec 2009, at 20:43, Thijs Triemstra | Collab wrote:

> I prefer to use the WSGIPythonPath directive of mod_wsgi, like:
>
> WSGIPythonPath "/usr/src/pyamf:/var/www/myApp"
> See http://docs.pyamf.org/current/tutorials/apache/mod_wsgi.html for  
> the rest of the example.
>
> Cheers,
>
> Thijs
>
> On 1 Dec 2009, at 15:49, Rob Harvey wrote:
>
>> Whenever you run into import errors in wsgi, try to import them
>> directly in a shell. In fact, for any errors you can't immediately
>> identify its worth trying it in the shell as much as you can.
>>
>>> import sys
>>> import os
>>> import controller
>>> sys.path.append('/usr/src/pyamf/')
>>> sys.path.append('/var/www/myProject')
>>
>> You're importing your controller module *before* you've added the
>> path. If you look at the error again, it mentions line #3 - so it
>> finds the error before it has even read about the extra paths.
>>
>> -rob
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

PGP.sig (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ImportError: No module named controller

Ben Marinic
Thanks Thijs/Rob.  All good now.

Although there's the initial pain of getting to grips with the basics, it's certainly *much* less painful than anything Java.

On 1 Dec 2009, at 20:47, Thijs Triemstra | Collab wrote:

Oops, that page is currently showing an old version of the mod_wsgi tutorial, if you want to see the complete tutorial, run:

make html

in the /doc folder of a checkout of the pyamf trunk (requires sphinx). Anyway, here's the vhost i was talking about:

WSGIPythonPath "/usr/src/pyamf:/var/www/myApp"

<VirtualHost 192.168.1.100:80>

       ServerName example.server.com

       CustomLog /var/log/apache2/myApp-access.log combined
       ErrorLog /var/log/apache2/myApp-error.log

# Set this to 'warn' when you're done with debugging
       LogLevel debug

       # PyAMF remoting gateway
       WSGIScriptAlias /flashservices/gateway /var/www/wsgi/myApp.wsgi

       <Directory /var/www/wsgi>
               WSGIApplicationGroup %{GLOBAL}
               Order allow,deny
               Allow from all
       </Directory>

</VirtualHost>
On 1 Dec 2009, at 20:43, Thijs Triemstra | Collab wrote:

I prefer to use the WSGIPythonPath directive of mod_wsgi, like:

WSGIPythonPath "/usr/src/pyamf:/var/www/myApp"
See http://docs.pyamf.org/current/tutorials/apache/mod_wsgi.html for the rest of the example.

Cheers,

Thijs

On 1 Dec 2009, at 15:49, Rob Harvey wrote:

Whenever you run into import errors in wsgi, try to import them
directly in a shell. In fact, for any errors you can't immediately
identify its worth trying it in the shell as much as you can.

import sys
import os
import controller
sys.path.append('/usr/src/pyamf/')
sys.path.append('/var/www/myProject')

You're importing your controller module *before* you've added the
path. If you look at the error again, it mentions line #3 - so it
finds the error before it has even read about the extra paths.

-rob
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159





_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users