0

I have a dir structure .

location of dir is "d:\sources\dir"

/dir
    __init__.py
    commonlibs/
              __init__.py
              lib1.py
              lib2.py
    project1/
            __init__.py
            prgfile1.py
            prgfile2.py
            prglib/
                   __init__.py
                   prglib1.py
                   prglib2.py

when i add dir to my PYTHONPATH i can easily import from anything and run the python script. but when i create my exe from py2exe i get import error of modules present in "commonlibs". and these modules are imported in prglib1 modules. and some other modules are not imported.

i dont know what i am missing ,but at the end i want to import from any where and my exe should run without error. my exe is an windows service and my project has named pipe implemented.

rgm
  • 1,241
  • 2
  • 16
  • 33
  • 1
    At runtime you can append directory paths to Python's `sys.path` list which might solve your problem. – martineau Jan 27 '13 at 16:51
  • @ martineau i did that too, but did not work. – rgm Jan 27 '13 at 20:00
  • 1
    If you're adding a hardcoded path like the one shown in your question to `sys.path` on Windows, make sure you use `r"d:\sources\dir"` or `"d:/sources/dir"` rather than `"d:\sources\dir"`. – martineau Jan 27 '13 at 21:43
  • @martineau Actually i use komodo ide and i configured PYTHONPATH in this ide , this does not set "PTYTHONPATH" windows, it sets only if you run using komodo ide. one other thing i did not added the dir to "os.sys.path" i addded to the environment variable in windows (" path " env ). from your comment what you are telling me is to add programatically to os.sys.path in script right ? my script to create binary is present in " dir/project1/createbinary.py ", so should i include os.sys.path in this file i.e createbinary.py ? – rgm Jan 28 '13 at 05:10
  • 1
    Yes, I'm saying append the directory path string to `sys.path` in your script before importing things. Alternatively, if you want to change the Window environment variable you have to do it in the Advanced tab of your System Properties control panel. There should be a way to define new one and change existing ones there. See [this answer](http://stackoverflow.com/questions/4208659/when-to-use-sys-path-append-and-when-modifying-pythonpath-is-enough/4209102#4209102) for examples of doing this. – martineau Jan 28 '13 at 08:41
  • @martineau Thanks. i added pythonpath in windows environment and mypy2exe worked perfectly. and i even checked with "sys.path.append". that too worked perfectly. Once again thank you verymuch – rgm Jan 28 '13 at 10:47
  • That's good to hear. You're welcome. – martineau Jan 28 '13 at 14:38

0 Answers0