import problems *newbie*

F. Petitjean littlejohn.75 at news.free.fr
Fri Jan 14 04:49:15 EST 2005


Le 13 Jan 2005 21:58:36 -0800, mike kreiner a écrit :
> I am having trouble importing a module I created. I'm running PythonWin
> on Windows XP if that helps. I saved my module in a folder called
> my_scripts in the site-packages directory. I edited the python path to
> include the my_scripts folder (it now reads
> C:\Python23\Lib;C:\Python23\DLLs;C:\Python23\Lib\lib-tk;C:\Python23\Lib\site-packages\my_scripts).
Not a very godd idea to mess with the python path
> When I try to import the module, I get this error:
> 
>>>> from PolyDraw import *
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> ImportError: No module named PolyDraw
> 
> When I select Browse PythonPath from the tools menu, I'm able to locate
> my module, PolyDraw.py.
> 
> The problem goes away if I open PolyDraw.py from PythonWin, which I'm
> assuming is because opening the module makes my_scripts the current
> working directory. This is just a quick workaround, but I'd like to
> know how to fix the problem. Thanks.
A quick fix is to promote your my_scripts folder to be a python package,
by creating a python module (file) named __init__.py right in the
package directory. The content of __init__.py can be for instance
#!/usr/bin/env python
# -*- coding: Latin-1 -*-
"""
my_scripts package containing miscellaneous modules 
  PolyDraw
  ....
"""
__author__ = 'mike kreiner'

To import from this package the syntax is
from my_scripts import PolyDraw
> 
> -Mike
> 



More information about the Python-list mailing list