Using py2exe I create an exe version of my script with instructions I found here. The script compiles well and generates a dist and build folder each but when I run the program on the command line it gives this error. N.B the script works fine on my IDE environment, however I intend give a colleague the exe version.How can I fix this error?
Traceback (most recent call last):
File "tester2.py", line 4, in <module>
ImportError: No module named mechanize
here is the setup.py file:
from distutils.core import setup
import py2exe
setup(
console = ['tester2.py'],
zipfile = None,
)
You have to declare your dependencies.
This is my setup
setup(
executables=executables,
options=options,
name='bla',
version='0.3',
packages=[...],
url='',
license='',
author='',
author_email='',
description='', requires=['pandas', 'unidecode', 'click',
'xlsxwriter'] // you would have to add mechanize here
)
Have you added files to the build?
Pls have a look at include option in setup.py: exe built with cx_Freeze, PyQt5, Python3 can't import ExtensionLoader_PyQt5_QtWidgets.py and run
Also here's my solution to similar problem, how to add files to build and run them later: Python - create an EXE that runs code as written, not as it was when compiled
Related
I have written a fairly simple GUI application using Python 3.8.0 and PySide6 and I would like to package it for distribution. Based on the table here, I chose cxfreeze as it's compatiable with Qt6 and with Windows/Linux/Mac.
My application in running with a pyenv environment on my development machine, if that makes a difference. The machine is running Debian Bullseye.
I ran the cxfreeze-quickstart wizard in order to create the setup.py script. The output from the script is here (apologies for pastebin link, the text is too long for stackoverflow)
When I run the created executable (build/build/exe.linux-x86_64-3.8/sne), I get the following error:
Traceback (most recent call last):
File "/home/james/.pyenv/versions/3.8.0/lib/python3.8/site-packages/cx_Freeze/initscripts/__startup__.py", line 104, in run
module_init.run(name + "__main__")
File "/home/james/.pyenv/versions/3.8.0/lib/python3.8/site-packages/cx_Freeze/initscripts/Console.py", line 15, in run
exec(code, module_main.__dict__)
File "app.py", line 7, in <module>
ImportError: libpyside6.abi3.so.6.1: cannot open shared object file: No such file or directory
The libpyside6.abi3.so.6.1 file is in the build/exe.linux-x86_64-3.8/lib/PySide6 directory.
I added a line to print the contents of sys.path when the application runs:
['/home/james/code/cave-escape/simple-nano-ethernet/SNEGui/build/exe.linux-x86_64-3.8/lib/library.zip', '/home/james/code/cave-escape/simple-nano-ethernet/SNEGui/build/exe.linux-x86_64-3.8/lib']
The lib/PySide6 directory is not in the path, but I believe this is not the issue as the PySide6 package is present in lib.
If I run ldd against libpyside6.abi3.so.6.1, all the dependencies have filepath listed against them except for one:
libshiboken6.abi3.so.6.1 => not found
This file is present in build/exe.linux-x86_64-3.8/lib/shiboken6 directory.
I am guessing I need to make a manual edit to the setup.py script to fix this, or perhaps edit the sys.path at application startup, but I'm not sure exactly what to do in either case.
EDIT: contents of setup.py (autogenerated, unaltered):
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
build_options = {'packages': [], 'excludes': []}
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('app.py', base=base, target_name = 'sne')
]
setup(name='Simple Nano Ethernet GUI',
version = '1.0',
description = 'An interface to configure the simple nano ethernet board',
options = {'build_exe': build_options},
executables = executables)
I am trying to generate aa .exe using py2exe for a python script that generates an excel. Here is just a sample code. I am writing value 100 to a cell and saving the excel to Users Desktop using openpyxl. This works perfectly fine when I run it directly.
import openpyxl
import getpass
wb = openpyxl.Workbook()
ws = wb.create_sheet('test')
ws.cell(row=1, column=1, value=100)
username = getpass.getuser()
wb.save('C:\\Users\\{}\\create_exe\\gen.xlsx'.format(username))
print 'Done'
And when I compile it using py2exe it compiles also just fine.
The problem arises when I run the generated .exe file. I get a return saying
ImportError: No module named jdcal
setup.py file is as follows
import py2exe
from distutils.core import setup
packages = ["openpyxl", "openpyxl.workbook", "xml.etree", "xml"]
excludes = []
setup(console=['test_program.py'],
options={"py2exe": {"excludes": excludes,
"packages": packages}}
)
Thisngs I have already tried
I have searched and few people said Install openpyxl using pip. I
have done that and pip says its alöready installed.
I have also tried to install jdcal using pip and pip says it is installed.
I have uninstalled jdcal and installed it using pip and manually, and
still the same error.
I have included jdcal in the packages and still no change in the outcome.
I hope someone can help me with it.
Thanks in advance
EDIT :
Generated Filed in dist folder are as follows (openpyxl cannot be seen here, I don't know why)
tcl (Folder)
_ctypes.pyd
_elementtree.pyd
_hashlib.pyd
_multiprocessing.pyd
_socket.pyd
_ssl.pyd
_tkinter.pyd
bz2.pyd
pyexpat.pyd
select.pyd
unicodedata.pyd
win32ui.pyd
numpy.core._dummy.pyd
numpy.core.multiarray.pyd
numpy.core.multiarray_tests.pyd
numpy.core.operand_flag_tests.pyd
numpy.core.struct_ufunc_test.pyd
numpy.core.test_rational.pyd
numpy.core.umath.pyd
numpy.core.umath_tests.pyd
numpy.fft.fftpack_lite.pyd
numpy.linalg._umath_linalg.pyd
numpy.linalg.lapack_lite.pyd
numpy.random.mtrand.pyd
_win32sysloader.pyd
win32api.pyd
win32pdh.pyd
win32pipe.pyd
tk85.dll
tcl85.dll
libiomp5md.dll
pywintypes27.dll
python27.dll
w9xpopen.exe
pythoncom27.dll
library.zip
test_program.exe (Executable File)
Try to manually include it in setup.py in packages = ["openpyxl", "openpyxl.workbook", "xml.etree", "xml"]
so it would be:
packages = ["openpyxl", "openpyxl.workbook", "xml.etree", "xml", "jdcal"]
I personally have had good luck letting py2exe detect the modules that are needed. I've never tried to specify every module necessary.
try this:
from distutils.core import setup
import py2exe
setup(console=['test_program.py'])
this should be run from command line as
python setup.py py2exe
py2exe outputs .dll files in the dist directory, these have to be in the directory that you run your .exe file from. if you just want one .exe file and no .dll files try this:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
console = [{'script': "test_program.py"}],
zipfile = None,
)
this should be run from command line as
python setup.py
I use cx_freeze and never had any issues.
Here's the setup.py for a cx_freeze file
from cx_Freeze import setup, Executable
build_exe_options = {"excludes": ["html5lib"],"optimize":2}
setup(name = "App Name" ,
version = "1.0.0.0" ,
options = {"build_exe": build_exe_options},
description = "" ,
executables = [Executable("FooBar.py")])
I'm trying to create an IRC client using the irclib library. When I try to freeze the script using cxFreeze, however, I always run into that error:
Traceback (most recent call last):
File "C:\python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "client.py", line 38, in <module>
ImportError: No module named jaraco
The setup.py script has been modified several times, to try to include files, packages and so on. Nothing seems to work. Here's the current version for reference:
from cx_Freeze import setup, Executable
client = Executable(
script="client.py",
base="Win32GUI",
)
setup(
name = "client",
version = "0.2",
description = "client",
options = {'build_exe': {'includes': ["jaraco"], "packages": ["jaraco"]}},
executables = [client],
)
The script of the client can be shortened in a single line:
from irc import client
That's all. I'm not using Jaraco, irclib (package irc) is. Jaraco must have been installed as a dependency from irclib.
I've tried to find the reasons why it could happen, but so far, nothing found.
Thanks for your help!
Well, after some digging around, it seems the same problem exists with zope when freezing an application with twisted. Although I haven't tested it with jaraco, I would imagine it's the same issue. I hope this solution works for users stuck with the same problem:
In your 'site-packages' directory, in the 'jaraco' package, add the 'init.py' file. It can be empty. Why isn't it provided, I have no idea. A package without a 'init.py", for cxFreeze, isn't a package.
Re-run the 'setup.py' script. Don't include 'jaraco' as a package, provide the package that needs it (here, it would be 'irc').
Here's the setup.py script:
from cx_Freeze import setup, Executable
client = Executable(
script="client.py",
base="Win32GUI",
)
setup(
name = "client",
version = "0.2",
description = "client",
options = {'build_exe': {'packages': ["irc"]}},
executables = [client],
)
I provide this answer because it worked just fine with twisted and zope. Seeing my client uses twisted now for its IRC communication, I don't know if the provided steps below work, but that's what helped me for twisted.
HTH,
I am a beginner in python and django. This error keeps coming, even after installing cx_freeze from http://www.lfd.uci.edu/~gohlke/pythonlibs/#cx_freeze
I am trying to make an executable file and I want to run my server through it, which I normally do by:
manage.py runserver
I am currently using commands:
setup.py build
I have already tried:
pyinstaller --name=mysite myproject_dir/manage.py
and my setup.py file contains
import sys
from distutils.core import setup
from cx_Freeze import setup, Executable
setup(
name = "Management System",
version = "1.0",
description = "A Database Management System",
py_modules=['virtualenv'],
executables = [Executable("manage.py", base = "Win32GUI")])
I have also tried py2exe, it doesn't work. You can also suggest to read something for this knowledge.
Here is the image of error that keeps appearing on running the exe file
If I use this command:
Barcode.exe runserver
There also comes an error
WindowsError: [Error 3] The system cannot find the path specified:'C:\\Users\\D ell\\AppData\\Local\\Temp\\_MEI85~1\\Entry\\migrations/*.*'
So I'm just trying to create an exe from a simple hello world program using py2exe. I have created the setup file (setup.py) with the following code:
from distutils.core import setup
import py2exe
setup(console=['hello.py'])
(I have also tried setup(console=[{"script":'hello.py'}]) as per another suggestion )
I run cmd as an administrator and type C:\python27\setup.py py2exe
It then says:
error: hello.py: No such file or directory
I have the hello.py file in the same folder as the setup file. Looked at many different forums and py2exe tutorials and none seem to have answers, any help would be greatly appreciated.
You have to first navigate to that directory and then make the python call:
C:>cd C:\python27
C:\python27>python setup.py py2exe
Note: your hello.py script should also be in C:\python27 directory.