2
votes

I am using py2exe-0.6.9.win32-py2.7.exe and converted a .py file to .exe. The problem is that it won't open as it says something like 'unable to import Frame' when I try to open the .exe file. 'Frame' is another .py file which I wrote some code in.

Also, when I open another .exe(converted from .py) file which does not import some .py file which I made, then it opens without any problem.

Here is my setup.py file.

from distutils.core import setup
import py2exe
from glob import glob
import sys
import os
sys.path.append("C:\\Users\\USER\\Desktop\\Microsoft.VC90.CRT")
print os.path.isdir("C:\\Users\\USER\\Desktop\\Microsoft.VC90.CRT")
data_files = [("Microsoft.VC90.CRT",glob(r'C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_bcb86ed6ac711f91\*.*'))]

setup(data_files="",console=["C:\\3d-Model\\bin\\Application.py"])

EDIT: I understood the problem. the modules present only in C:\Python27\Lib\site-packages\ gets imported by the .exe file. The question now is do I have to copy every module the .exe file is trying to import to C:\Python27\Lib\site-packages\ before running py2exe or is there any other easier way?

Thanks in advance.

3
please add an empty init.py inside your python/sitepakages/module which it says import error - sundar nataraj
by the way which module does it shows import error - sundar nataraj
Thanks. It somehow helped me figure out what caused the problem. Please see the EDIT . - user3109895
yes! u need to place 'init.py' to every module your using in your project. since init.py tell to your py2exe convertor that there is a python module here - sundar nataraj
You mean I need to place a totally empty "init.py" in every folder(and subfolder as well?) where there is .py file that my .exe needs to import. - user3109895

3 Answers

1
votes

What I did is I updated the 'setup.py' file to contain the paths to the missing modules, using

import sys
sys.path.insert(0, <path_to_missing_modules>)

This way I do no need to polute the ...\site_packages\ folder.

0
votes

Here is what finally worked for me. Manually copying the folder containing the files which your .py(to be converted to .exe) file imports, before running py2exe, to Python27\Lib\site-packages\ fixes such problems I guess.

0
votes

you need to place '__init__.py' to every module your using in your project. since init.py tell to your py2exe convertor that there is a python module here.

Since i have faced the same issue Few days back. with zope.interface and mp_tools i placed empty __init__.py worked fine for me