How to create python module and make it available to any application

0

I would like my program in python to be put into the system in such a way that with a simple import it can be executed, for example:

import meucodigo
meucodigo.main()

My code contains several files (own modules) and all are called through the main class.

The idea is that with this I can create an installer so that it fits everything correctly for the end user. I intend to use install creator 2 and so the user can call it after installation. Remembering that I need you to be an installer like the one mentioned. Any tips?

I know it's possible, but unfortunately I can not find any tutorial to teach it.

NOTE: I use and need to use python 2.5.

    
asked by anonymous 17.10.2018 / 03:18

1 answer

1

Create the following folder structure:

MeuCodigo\
   README
   LICENSE
   setup.py
   meucodigo\
       __init__.py
       meucodigo.py

Inside of setup.py, place the following:

from distutils.core import setup
setup(name='MeuCodigo', version='0.1', author='Edeson Bizerril',
    author_email='[email protected]', 
    url='http://bizerril.com/meucodigo',
    packages=['meucodigo'],
)

Within __init__.py put the following:

from .meucodigo import *

Within meucodigo.py put the following:

def main():
     # codigo aqui
def .... # outras funções etc

Then open a command prompt, go to the folder MeuCodigo and type:

C:\MeuCodigo> py setup.py bdist_wininst

This will generate an installer executable in MeuCodigo\dist\MeuCodigo-0.1.exe

You can also use:

C:\MeuCodigo> py setup.py bdist_msi

To generate the installer in msi MeuCodigo-0.1.msi format.

See the distutils documentation .

    
17.10.2018 / 19:29