Import error when building .py file to .exe - python

I am using python 2.7.10, and have scripted a program which plays music with the help of mp3play module. I have installed the mp3play module and the program is working fine in .py format but when I am trying to build it into .exe with the help of py2exe, It is giving me ImportError: Stating mp3play module is not installed. Here is the following code for the setup.py file for the building of exe
import os
import sys
from distutils.core import setup
import py2exe
py2exe.build_exe._py_suffixes = ['.py', '.pyo', '.pyc', '.pyw', '.dat', '.log', '.txt', '.png']
setup(
version = "1.0",
name = "abcd",
author = "pqrs,mnop",
author_email = "abcd#gmail.com,pqrs#gmail.com",
windows=[{'script': "main.py","icon_resources": [(0, "data/icon.ico")]}] , options={'py2exe':{"skip_archive": True,"unbuffered": True,'packages':['Tkinter','PIL','mp3play','tkFileDialog','tkMessageBox','ttk','os', 'sys']}}
)
can someone help me out and tell me where I am getting it wrong ??

A very elegant way of using mp3play can be refered from here http://mp3play.googlecode.com

Related

Cannot run generated .exe with py2exe

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")])

python: py2exe paramiko showing no results

I am using python 2.7.11 on Windows 7 64bit, I am facing a problem with py2exe when I import paramiko module, the .exe file runs but does not show any results, after executing it closes immediately knowing that i did not get any error during the conversion.
import paramiko
print raw_input("press enter to exit")
the setup.txt file:
from distutils.core import setup
import py2exe
setup(console=['test.py'])
I have found that in the "dist" folder there are some dll files such as API-MS-Win-Core-ErrorHandling-L1-1-0.dll - API-MS-Win-Core-LibraryLoader-L1-1-0.dll - API-MS-Win-Core-LocalRegistry-L1-1-0.dll, such files I don't usually face them on another machine, so could anyone help please.
I was able to solve this after importing some modules:
import appdirs
import packaging
import packaging.version
import packaging.specifiers
import packaging.requirements
hopefully that could be useful for someone.

is cx-freeze incompatible with python for .net?

for sake of testing I am using demo from https://github.com/pythonnet/pythonnet/blob/master/demo/wordpad.py to convert it to .exe using cx_freeze==5.0.
but it shows missing clr modules (obviosly).
How to work around with this?
import sys
from cx_Freeze import setup, Executable
setup(
name = "WordPad",
version = "3.1",
description = "A word pad demo",
executables = [Executable("main.pyw", base = "Win32GUI")])
Disclaimer: This is my first attempt using cx_freeze.
This auto-discovery of pythonnet was merged to cx_freeze:
https://github.com/anthony-tuininga/cx_Freeze/pull/251

Best of both worlds: python packaging for a game

I am currently trying to package a game made with python and pygame and I am running into some issues.
I am using py2exe to package and have looked up some question on here about it but I couldn't find a great solution. I want to end up with a folder, containing an exe, that I can compress and put online. Running the setup.py works fine except it puts all the dependencies into library.zip. This means that the program, when run, does not work.
I found that someone else was running into this issue and they ended using the "skip archive = true" option to solve it. And while, yes, that does work for me too I was hoping there was a method that would still let the program be run without trouble but wouldn't clutter the folder with countless files.
To be very precise the issue I'm running into with the library.zip is:
ImportError: MemoryLoadLibrary failed loading pygame\mixer.pyd
Which, if I understand it properly, means that the program can not reach/find the mixer module of Pygame.
Here is the setup script I am currently using (and that isn't working):
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
data_files = [('resources', ['resources/step.wav',
'resources/wind2.wav',
'resources/The Steppes.ogg',
'resources/warrior3-nosword-notassle.png',
'resources/warrior3-sword.png',
'resources/warrior2-blood1.png',
'resources/warrior2-blood2.png',
'resources/warrior2-blood3.png',
'resources/warrior2-blood4.png',
'resources/warrior3-up.png',
'resources/warrior3-kneel.png',
'resources/warrior3-kneel-nosword.png',
'resources/warrior2-blood2-kneel.png',
'resources/warrior2-blood3-kneel.png',
'resources/warrior2-blood4-kneel.png',
'resources/warrior3-death.png',
'resources/warrior3-offarm.png',
'resources/menu1.png',
'resources/plains3-top-nomount.png',
'resources/mountains.png',
'resources/plains5-bottom.png',
'resources/plains3-bottom.png',
'resources/cloud1.png',
'resources/warrior2-sword.png',
'resources/warrior2-hand.png',
'resources/blue-tassle1.png',
'resources/blue-tassle2.png',
'resources/blue-tassle3.png',
'resources/blue-tassle4.png'])]
setup(options = {'py2exe': {"bundle_files": 1}},
data_files = data_files,
console = [{'script': "steppes2.0.py"}],
zipfile = None
)
This code in your setup.py should do the trick of producing a single executable (you will still have to distribute msvc dlls separately)
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
console = [{'script': "myscript.py"}],
zipfile = None,
)

LoadLibrary(pythondll) failed error using py2exe tutorials

I'm trying to use py2exe and right now I'm just having trouble building the samples and tutorials that come with py2exe. I run setup.py and that goes fine but when I try to run the exe that is created I get the "LoadLibrary(pythondll) failed" error. I haven't moved the exe from the dist directory and I see that python27.dll is in that dist directory. Does anyone know what might be happening?
In case it matters I'm running 32 bit python 2.7 with the corresponding 32 bit python 2.7 py2exe on windows 7.
Thanks
The test.py file just contains
print "test"
Here's my setup.py based off what Kirk wrote:
from distutils.core import setup
import py2exe
import sys
from glob import glob
project_folder = r'C:\\Python27\\Lib\site-packages\\py2exe\\samples\\test\\'
data_files = [
("dlls", glob(project_folder + r'dlls\\*.dll'))
,("pyds", glob(project_folder + r'pyds\\*.pyd'))
]
options = { }
setup(
name='test'
,options = options
,zipfile = None
,data_files=data_files
,console=['test.py']
)
You'll want to specifically include the python27.dll file. If you're including multiple things, use glob and a data files array like below to get the best results with py2exe. For this example, create a Dll folder and put python27.dll in there.
from distutils.core import setup
import py2exe
import sys
from glob import glob
data_files = [
("Stuff", glob(r'C:\projectfolder\Stuff\*.*'))
,("dlls", glob(r'C:\projectfolder\dlls\*.dll'))
,("pyds", glob(r'C:\projectfolder\pyds\*.pyd'))
]
options = { }
setup(
name='ProjectName'
,options = options
,zipfile = None
,data_files=data_files
,console=['projectname.py']
)
I know this is a pretty old question, but I had a similar problem.
I had uninstalled python and py2exe 64 bit to replace it with the 32 bit version.
After I did this, I always got this error.
Later, I deleted my dist and build directories from my project, and the subsequent build worked.

Categories