0

Unlike all other Import errors that other people have been experiencing, my py2exe Import error occurs due to the fact it is unable to locate the modules that I'm trying to import. It is likely to be path problems.

I have two directories:

Code/
  my_main.py
Lib/

Due to the fact that I know I will be importing and using code in my "Lib/" very often, at the very beginning of my_main.py, I did

#PATH_TO_LIB is the absolute path to my library
sys.path.append(PATH_TO_LIB)

Now that after I use py2exe compile, all references to code that is inside of the library will give me an import error.

My code is massive and I really don't want to go through each one of the import to change the path of it.

What do I need to do to prevent this?

twasbrillig
  • 17,084
  • 9
  • 43
  • 67
user3019766
  • 131
  • 1
  • 10
  • Is this what you are looking for: http://stackoverflow.com/questions/13237521/py2exe-importerror-no-module-named-package-i-have-impemented – KSab Nov 14 '14 at 06:49
  • I'm not an expert on py2exe but it appears like you might want to take it out of main.py and put it in the py2exe setup script – KSab Nov 14 '14 at 06:53
  • The question would be, why do you add `Lib` to the path, instead of using it e.g. as a package? That would a) be much more pythonic and b) would not make problems with `py2exe`. – sebastian Nov 14 '14 at 07:06
  • I would prefer to use the Lib instead of use the package is because that way no one needs to run pip installs (or any automated process such as docker) as a pre-run procedure. It will just be sync and run. – user3019766 Nov 14 '14 at 20:00
  • Sorry I cannot just add sys.path.append to every file that I wrote previously due to the fact that there are just too many out there. – user3019766 Nov 14 '14 at 20:00

0 Answers0