[IPython-dev] Regarding Import for a Package

Nikolas Tezak ntezak at stanford.edu
Thu Jul 25 14:52:12 EDT 2013


Hi!

If the directory containing the top-level pydy module is already in your sys.path variable, the smartest thing IMHO is to use absolute imports including the whole tree of modules.

from pydy.pydy_viz.shapes import *

To add it to the sys.path, you modify your system's  PYTHONPATH environment variable. 
Since I don't know any details of your runtime setup, here is a way to find out more ;)
https://www.google.com/search?q=setting+pythonpath

Best,

Nik


On Jul 25, 2013, at 11:43 AM, TARUN GABA wrote:

> Hi,
> I am developing a Package under PyDy,  for GSoC.
> This is my directory structure.
> 
> pydy/
> --------- __init__.py
> ---------pydy_viz/
>                     -----------------__init__.py
>                     --------------shapes.py
>                     --------------tests\
>                                     -----------__init__.py
>                                     -----------test_shapes.py
> 
> Now I am trying to import pydy_viz.shapes from inside tests, i.e from test_shapes.py
> 
> I have tried both approaches.
> from pydy_viz.shapes import *
> Error: No module named pydy_viz.shapes
> and relatively ..
> 
> from ..shapes import *
> Error: tried relative imports from non-package.
> 
> but I am not able to import it.
> Any ideas what I might be doing wrong.
> I dont have a setup.py file in place for now.
> 
> Thanks
> 
> 
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev




More information about the IPython-dev mailing list