2014-06-12 1 views

Répondre

1

Cette solution fonctionne sur Windows. Je m'attendrais à ce que, ou petite variation, fonctionnera sur Linux mais je n'ai pas accès à une boîte Linux pour l'essayer.

Création de l'application à congeler avec la structure de répertoire suivant:

-- sample 
    -- app 
     - __init__.py 
     - fns.py 
    - main.py 
    - setup.py 

code pour chaque fichier python est:

fns.py

"""Place functions you want to access from the frozen app here""" 
def accessible(): 
    print "This function is accessible" 

main.py

import app.fns 

def inaccessible(): 
    print "This function is inaccessible; AFAIK" 

if __name__ == '__main__': 
    inaccessible() 
    app.fns.accessible() 

bb_setup.py

from bbfreeze import Freezer 

f = Freezer(distdir="frozen") 
f.addScript("main.py") 
f() 

Gel des résultats d'application dans le répertoire gelé. Vous pouvez maintenant accéder aux fonctions fns.py de l'application « gelée » avec le code comme:

useFrozenCode.py

import sys 

# Add the path to the frozen applications app module to the python path 
sys.path.append("C:\\no_backup\\personal\\sample\\frozen\\library.zip") 

import app.fns 

if __name__ == '__main__': 
    print "Calling a routine from a frozen application" 
    app.fns.accessible() 

Je ne sais pas de toute façon d'appeler la fonction main.py. inaccessible dans main.py.

Questions connexes