Code Management

Sergio Correia sergio.correia at gmail.com
Wed Nov 21 01:05:26 EST 2007


As a side note, I find much easier to drop a PTH file than messing
with pythonpath. If you are not familiar with PTH files, what I do is
this

1) Go to "C:\Program Files\Python25\Lib\site-packages" or whatever is
appropiate in your case.
2) Create a text file, name it something like "MyProjects.PTH" (note
the extension!)
3) in the file, just write the path of the folder that contains all
your projects (in my case, C:/docs/python)

The idea is to keep the main python installation separated from the
modules you are currently developing. Your python installation goes to
"program files/python" or "bin/python", and your personal projects go
somewhere else (usually inside your 'user' folder). This smooths many
things, like working with different versions of a package you are
developing.

On Nov 20, 2007 11:34 PM, Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
> Jens <j3nsby at gmail.com> writes:
>
> > On 21 Nov., 04:16, Jens <j3n... at gmail.com> wrote:
> > > On 21 Nov., 01:46, brzr... at gmail.com wrote:
> > > dummy/
> > >   dummy_package/
> > >     __init__.py
> > >     moduleA.py
> > >     tests/
> > >        __init__.py
> > >        test.py
>
> To avoid confusion, the directory that is the package should be named
> as you want the imports to appear; e.g. if you want to 'import
> foo.module_a', then name the directory containing 'module_a.py' as
> 'foo/'.
>
> This often results in::
>
>     foo/
>       setup.py
>       foo/
>         __init__.py
>         module_a.py
>       test/
>         __init__.py
>         test_module_a.py
>
> That is, the *project* directory (containing all the files) is named
> 'foo/'; the *package* directory (where all the implementation code is
> found) is named 'foo/foo/', and the unit tests are found in the
> directory 'foo/test/'.
>
> That's normal, though if it confuses you you might want to rename the
> project directory. I'm often doing development on multiple
> version-control branches, so each project directory is named for the
> branch it contains; within each of those, the same 'foo/' name is used
> for the package directory.
>
> > > I'm using Python 2.5.1. When I'm trying to call a function in
> > > 'moduleA' from 'test' it won't work unless I make the 'dummy'
> > > folder a package as well. That's pretty weird. Does
> > > 'dummy_package' have to be in my pythonpath or something? How do I
> > > reference moduleA from test?
>
> You should install the package into a place where Python's import path
> will find it. Read up on using the standard library 'distutils'
> mechanism for this; it involves writing a 'setup.py' file to define
> the parameters for installation of your package.
>
> > > I would like to avoid making 'dummy' into a package as well.
>
> Yes. The top-level directory is used for containing a number of files,
> including 'setup.py', that should not be part of the installed
> package.
>
> > Problem solved. I added 'dummy' to the PYTHONPATH. (Do I really have
> > to do that for every project I create?) Anyway, it works the way I'd
> > like it to now.
>
> I hope the above makes it clearer what I prefer for this situation.
>
> --
>  \         "True greatness is measured by how much freedom you give to |
>   `\      others, not by how much you can coerce others to do what you |
> _o__)                                             want."  --Larry Wall |
> Ben Finney
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list