Προς το περιεχόμενο

Προτεινόμενες αναρτήσεις

Δημοσ.

θέλω να φτιάξω ένα exe ενός python script

Το φτιάχνω με το cx_freeze δεν βρήκα κάποιο άλλο. Το py2exe δεν το δοκίμασα γιατί είδα ότι δεν έχει ενημερωθεί από το 2008.

 

Έφτιαξα ένα αρχείο setup

 

from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])

base = 'Console'

executables = [
    Executable('script.py', base=base)
]

setup(name='script',
      version = '0.1',
      description = 'Parser',
      options = dict(build_exe = buildOptions),
      executables = executables)

 

 

Μου δημιουργεί έναν φάκελο build, αλλά μόλις εκτελώ το script από εκεί μου βγάζει σφάλμα:

 

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27
, in <module>
    exec code in m.__dict__
  File "script.py", line 7, in <module>
  File "ExtensionLoader_lxml_etree.py", line 22, in <module>
  File "ExtensionLoader_lxml_etree.py", line 14, in __bootstrap__
  File "lxml.etree.pyx", line 84, in init lxml.etree (src\lxml\lxml.etree.c:1797
08)

 

Στο script χρησιμοποιώ τα παρακάτω modules:

 

from lxml import etree
import sys
import Tkinter
import tkFileDialog
import tkMessageBox

from bs4 import BeautifulSoup
from collections import Counter
import operator

 

έχει κανείς κάποια εμπειρία στο θέμα;

ευχαριστώ

  • Like 1
Δημοσ.

Δουλεύει με αυτό:

from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need
# fine tuning.
#buildOptions = dict(packages = [], excludes = [])
build_exe_options = {"packages": ["os","lxml","bs4","gzip"], "excludes": ["tkinter"]}

base = 'Console'

executables = [
    Executable('script.py', base=base)
]

setup(name='script',
      version = '0.1',
      description = 'Parser',
      options = {"build_exe": build_exe_options},
      executables = executables)

το βρήκα στο documentaion ...  RTFM :)

  • Like 3
  • 7 μήνες μετά...
Δημοσ.

Χρησιμοποιώ το matplotlib στο σκριπτ, και δεν μπορώ να έχω πρόσβαση στον υποκατάλογο '/stylelib' του module που εισηγάγει το matplotlib, 'styles':

u'C:\\Users\\myuser\\Downloads\\parser\\build\\exe.win32-2.7\\Library.zip\\matplotlib\\style\\stylelib\\*.*'

Μετά από ψάξιμο κατάλαβα ότι κάποιο πρόβλημα υπάρχει στο ότι ο φάκελος είναι συμπιεσμένος.
Τροποποίησα το setup.py ώστε να μην φτιάχνει συμπιεσμένο φάκελο, αλλά το πρόβλημα παραμένει μόνο που το path τώρα είναι λάθος (κοιτάει το όνομα του αρχείου ως φάκελο: "\exe.win32-2.7\\script.exe\\"):

 


C:\Users\myuser\Downloads\parser\build\exe.win32-2.7>script.exe
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec code in m.__dict__
  File "traces.py", line 10, in <module>
  File "C:\Python27\lib\site-packages\pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "C:\Python27\lib\site-packages\matplotlib\pylab.py", line 274, in <module>
    from matplotlib.pyplot import *
  File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 28, in <module>
    from matplotlib import style
  File "C:\Python27\lib\site-packages\matplotlib\style\__init__.py", line 3, in <module>
    from .core import use, context, available, library, reload_library
  File "C:\Python27\lib\site-packages\matplotlib\style\core.py", line 150, in <module>
    _base_library = load_base_library()
  File "C:\Python27\lib\site-packages\matplotlib\style\core.py", line 95, in load_base_library
    library.update(read_style_directory(BASE_LIBRARY_PATH))
  File "C:\Python27\lib\site-packages\matplotlib\style\core.py", line 127, in read_style_directory
    for path, name in iter_style_files(style_dir):
  File "C:\Python27\lib\site-packages\matplotlib\style\core.py", line 116, in iter_style_files
    for path in os.listdir(style_dir):
WindowsError: [Error 3] The access to the specified path cannot be found: u'C:\\Users\\myuser\\Downloads\\parser\\build\\exe.win32-2.7\\script.exe\\matplotlib\\style\\stylelib\\*.*'


To setup.py:

 

 

from cx_Freeze import setup, Executable
import os
import sys

# Dependencies are automatically detected, but it might need
# fine tuning.
#buildOptions = dict(packages = [], excludes = [])

def include_files():
        path_base = "C:\\Python27\\Lib\\site-packages\\matplotlib\\style\\stylelib"
        skip_count = len(path_base)
        zip_includes = [(path_base, "matplotlib/style/stylelib/")]
        for root, sub_folders, files in os.walk(path_base):
            for file_in_root in files:
                zip_includes.append(
                        ("{}".format(os.path.join(root, file_in_root)),
                         "{}".format(os.path.join("matplotlib/style/stylelib", root[skip_count:], file_in_root))
                        )
                )      
        return zip_includes
#"zip_includes": include_files(),
path = sys.path
options = {"packages": ["os","lxml","bs4","gzip", "matplotlib.style"],
           "path": path,
           "excludes": ["tkinter"],
           "create_shared_zip": False,
           "include_in_shared_zip": False,
           "compressed": False
           }



base = 'Console'

executables = [
    Executable('traces.py',
               appendScriptToLibrary=False,
               compress = False,
               copyDependentFiles = True,
               appendScriptToExe = True,
               base = base)]

setup(name='traces',
      version = '0.10.0',
      description = 'Parser',
      executables = executables,
      options = {"build_exe": options})
      

 

 

 

Ευχαριστώ

  • Like 1

Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε

Πρέπει να είστε μέλος για να αφήσετε σχόλιο

Δημιουργία λογαριασμού

Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!

Δημιουργία νέου λογαριασμού

Σύνδεση

Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.

Συνδεθείτε τώρα
  • Δημιουργία νέου...