Thank you!  As long as I manually set projectDir to some valid path all that works for me!  However, you specificaly said that absolute paths should be avoided, and I agree.  So, how should projectDir be getting set without doing it overtly?  For the moment this works, so I'm off high-center, but I need to understand the more general coase for the longer haul.
 
--Hank
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Chuck Esterbrook
Sent: Thursday, January 19, 2006 11:23 AM
To: webware-discuss@lists.sourceforge.net
Subject: Re: [Webware-discuss] "No Module named Middle"

 Sender ALLOWED   [ Remove ]  [ Block ]    details 
Vanquish Anti-Spam Control Panel

 
On 1/18/06, Hank Freeman <[EMAIL PROTECTED]> wrote:
> I am working on learning MiddleKit, and having a great time.  Things have
> gone well until I try to actually build a Store from my model.  After
> creating a simple model, generating it, creating the database and it's
> objects, and loading my sample data all successfully, I've stumbled.  When I
> try to do store.readModelFileNamed(_filename) I get "ModelError: (<path to
> my model.mkmodel>', "Could not import module for class '<First class in my
> model>' due to 'No module named Middle'.  If you added this class recently,
> you need to re-generate your model.')
>
> I have a Settings.config file that contains:
> {
>     'Package': 'Middle',
>     'SQLLOG': {'File': 'mk-sql.log' },
>     'Database': 'MyDbNameHere'
> }
> and my "Middle" directory does have (an empty) __init__.py file to identify
> it as a package.
>
> I suspect I'm making a common noob oversite here, but (admitting to being a
> newbie) I cannot see it.  Any advice on common pitfalls I might be hitting
> here?  Thanks in advance!

The directory containing your Middle directory needs to be in the
python path which is stored in sys.path at runtime, and augmented by
the environment variable PYTHONPATH when Python starts.

I like to make my code impervious to its environment when possible, so
my personal pref is to enhance sys.path in my Python code. Also:

- I also like to make my code impervious to what directory it's run
in, so I don't use absolute paths.
- sys.path[0] is often a blank string or the path of the main python
program. Whatever the case, I never pre-empt it.
- My program is usually "next door" to the Middle directory in another
directory like "bin" or "WebApp".

So given all that, a command line tool I write that uses Middle might say:

import os, sys
progPath = os.path.join(os.getcwd(), sys.argv[0])
progDir = os.path.dirname(progPath)
projectDir = os.path.dirname(projectDir)
assert os.path.exists(projectDir), projectDir
sys.path.insert(1, projectDir)
# now test it:
import Middle


For a WebKit app, you'd do this fixup during context initialization.

Or you could just set the PYTHONPATH environment variable and not
write any Python code.


Btw any time you have problems importing a module, you can "print
sys.path" to help you troubleshoot it, although I find that output
hard to read and do this instead:

for p in sys.path:
    print repr(p)


HTH,
Chuck


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to