Hi everyone,
I have 4 .py files : main.py , file1.py , file2.py , file3.py
as :

main.py:

import sys
import file1 
import file2 
import file3

def main(a,b):
    c=file1.somme(a,b)
    d=file2.mul(a,b)
    file3.div(a,b)
    print c,d

if __name__ == '__main__':
    a,b=sys.argv[1:]
    a=int(a)
    b=int(b)

    main(a,b)

file1.py:

def somme(i1,i2):
    return i1+i2

file2.py:

def mul(i1,i2):
    return i1*i2

file3.py:

def div(i1,i2):
    return i1/i2

I would like to create main.exe so I tried to write the following setup.py file:

from distutils.core import setup
import py2exe
import sys


includes=['src/file1.py','src/file2.py','src/file3.py']

setup(
    options = {"py2exe": {"compressed": 2, 
                          "optimize": 2,
                          'bundle_files': 3, 
                          'dist_dir': 'dist',
                          "includes":includes,
                         }
              },
    console=['src/main.py']
)

but when I tried to run : python setup.py py2exe I get this error

ImportError: No module named src/file1

can someone help me please ?

PS: I'm using python 2.7 , windows 64

Thanks

This worked for me ...

''' Py2ExeConSetup.py

Py2Exe (version 6.6 and higher) setup file for a console program.
Creates a single .exe file.

Simply add this file into the same folder with your source file (s).
Change your main source filename at the bottom to whatever you called
your main code file.  Now run Py2ExeConSetup.py ...

Two subfolders will be created called build and dist.
The build folder is for info only and can be deleted.
Distribute whatever is in the dist folder.

'''

from distutils.core import setup
import py2exe
import sys
# these .py modules will be converted to .pyo and included in the .exe
import file1
import file2
import file3

sys.argv.append("py2exe")
sys.argv.append("-q")

setup(
  options = {"py2exe": {"compressed": 1,
                        "optimize": 2,
                        "ascii": 1,
                        "bundle_files": 1}},
  zipfile = None,
  console = [{"script": 'main.py'}]
)

For testing I changed main.py ...

# main.py

import sys
import file1
import file2
import file3

def main(a,b):
    c=file1.somme(a,b)
    d=file2.mul(a,b)
    file3.div(a,b)
    print c,d

    # console wait
    raw_input("press enter to go on ...")

if __name__ == '__main__':
    #a,b=sys.argv[1:]
    a,b=3,7  # test
    a=int(a)
    b=int(b)

    main(a,b)

Thanks a lot vegaseat for your answer !
Actually it worked for me too but only when I put setup.py file in the src directory which contains my files :
when I try to put it as:

myApplication
|_ setup.py
|_ src (main.py , file1.py , file2.py , file3.py)

I get this error: ImportError: No module named file1

Do you have an idea how to fix it ?
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.