Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > disutils, project structure & developing - n00b question

Reply
Thread Tools

disutils, project structure & developing - n00b question

 
 
Wells
Guest
Posts: n/a
 
      10-29-2009
So I have my project partitioned like so:

../setup.py
../pymlb/
../pymlb/fetcher.py
../demos
../demos/demo.py

In demo.py I have:

from pymlb import fetcher

However, it fails b/c pymlb is up a folder. It's also NOT installed as
a module in my module directory because it's a development effort and
I don't want to run setup.py to install them. See what I mean?

What's the work around here?
 
Reply With Quote
 
 
 
 
Simon Forman
Guest
Posts: n/a
 
      10-29-2009
On Thu, Oct 29, 2009 at 2:42 PM, Wells <(E-Mail Removed)> wrote:
> So I have my project partitioned like so:
>
> ./setup.py
> ./pymlb/
> ./pymlb/fetcher.py
> ./demos
> ./demos/demo.py
>
> In demo.py I have:
>
> from pymlb import fetcher
>
> However, it fails b/c pymlb is up a folder. It's also NOT installed as
> a module in my module directory because it's a development effort and
> I don't want to run setup.py to install them. See what I mean?
>
> What's the work around here?



In order for "from pymlb import fetcher" no work you must make the
'./pymlb' directory into a "package" by adding a file called
__init__.py (it can be empty.)

Then make sure the "top" directory (i.e. '.' in your example) is in
the python PATH. There are a couple of ways to do that:

1.) Hack it in demo.py before importing fetcher
(i.e. "import sys; sys.path.append(<string absolute path of '.'>)")

2.) Use the PYTHONPATH environment variable.

3.) Use a .pth file (See http://docs.python.org/library/site.html)
You'll have to figure out what directory to put it in (on my system
'/usr/lib/python2.5/site-packages' works) Note, although it's not
mentioned in the site module docs you can include an absolute path and
it will be added to sys.path.

There is additional good information about .pth files on Bob
Ippolito's blog:
http://bob.pythonmac.org/archives/20...n-development/
Be sure to read the comments too.

4.) Probably some other method(s) that someone else will tell you... ;]

HTH,
~Simon
 
Reply With Quote
 
 
 
 
Simon Forman
Guest
Posts: n/a
 
      10-29-2009
On Thu, Oct 29, 2009 at 3:45 PM, Simon Forman <(E-Mail Removed)> wrote:
> In order for "from pymlb import fetcher" no work you must make the


s/no/to/

D'oh!
 
Reply With Quote
 
Lie Ryan
Guest
Posts: n/a
 
      10-29-2009
Simon Forman wrote:

> In order for "from pymlb import fetcher" no work you must make the
> './pymlb' directory into a "package" by adding a file called
> __init__.py (it can be empty.)
>
> Then make sure the "top" directory (i.e. '.' in your example) is in
> the python PATH. There are a couple of ways to do that:
>
> 1.) Hack it in demo.py before importing fetcher
> (i.e. "import sys; sys.path.append(<string absolute path of '.'>)")
>
> 2.) Use the PYTHONPATH environment variable.
>
> 3.) Use a .pth file (See http://docs.python.org/library/site.html)
> You'll have to figure out what directory to put it in (on my system
> '/usr/lib/python2.5/site-packages' works) Note, although it's not
> mentioned in the site module docs you can include an absolute path and
> it will be added to sys.path.
>
> There is additional good information about .pth files on Bob
> Ippolito's blog:
> http://bob.pythonmac.org/archives/20...n-development/
> Be sure to read the comments too.
>
> 4.) Probably some other method(s) that someone else will tell you... ;]


4.) By importing the module from a main.py script in the main directory,
and making every imported folder a package (by putting __init__.py
file). This is the simplest method I found, but has the drawback that
you can't use a subpackage for execution (only for imports).

i.e.

$ ls
../__init__.py
../setup.py
../pymlb/
../pymln/__init__.py
../pymlb/fetcher.py
../demos
../demos/demo.py
../run_script.py
$ cat run_script.py
#!/usr/bin/env python
from demos import demo
$ cat demos/demo.py
from pymlb import fetcher
$ ./run_script.py
....

or something like that...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help in developing a project Abhi Java 0 11-07-2006 01:12 PM
access denied... n00b question Grant Merwitz ASP .Net 1 08-08-2005 09:20 AM
n00b Question Ambush ASP .Net 1 12-19-2004 03:48 PM
n00b Question re: MSDE SQL 2000 Set-up newgenre ASP .Net 2 04-19-2004 06:16 PM
ultimate n00b question re: my / our Koncept Perl 3 12-06-2003 10:58 PM



Advertisments