On 02 Jul 2009, Xavier Saint-Mleux wrote:
> Olivier Delalleau wrote:
> > It sometimes happens that I want to run some Python program while
> > within my piaget/piaget directory, and if it tries to import the 'math'
> > module, it will import piaget.math instead of the standard math
> > module... which does not work too well.
> >
> > Is there another solution besides renaming math? If not, we should
> > probably try to avoid naming any submodule the same as an existing
> > Python base module.
> 
> By default, Python looks in the current working directory first when
> importing, so it is always best not to use Python from within the
> directory of a package in order to avoid name clashes. 
> 
> A similar problem exists when importing piaget from its source
> directory: it will import the "source" package instead of the installed
> one and none of the compiled C++ extensions will be available.
> 
> This is not Piaget-specific.  For example, if you try to import Numpy
> from its source directory, an ImportError is explicitly raised:
> 
> $ cd numpy-1.3.0/
> $ python
> Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
> [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import numpy
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "[...]/numpy-1.3.0/numpy/__init__.py", line 121, in <module>
>     raise ImportError(msg)
> ImportError: Error importing numpy: you should not try to import numpy from
>         its source directory; please exit the numpy source tree, and
> relaunch
>         your python intepreter from there.

Ok, but maybe by using names which are not base python modules the risk
is reduced (since at least there is some hope that python programs may
be using absolute imports for non-base imports).

It's a bit weird that I can't do "bzr log" from piaget/piaget. But I
agree it's not a big deal either, I can live with it.

--
Olivier

_______________________________________________
Mailing list: https://launchpad.net/~piaget-dev
Post to     : piaget-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~piaget-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to