Simple hello world QT python script. Works fine from the command line. When I package it i get:
Traceback (most recent call last):
File "/Users/jquick/bin/dist/gui.app/Contents/Resources/__boot__.py", line 340, in <module>
_run('/Users/jquick/bin/gui.py')
File "/Users/jquick/bin/dist/gui.app/Contents/Resources/__boot__.py", line 336, in _run
execfile(scriptpath, globals(), globals())
File "/Users/jquick/bin/gui.py", line 3, in <module>
from PySide.QtCore import *
ImportError: No module named PySide.QtCore
2012-06-02 00:23:04.823 gui[4835:707] gui Error
So it sounds like its not including the module.. but ive tried including it in both the setup.py and the command line. nothing works :(
setup.py:
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['gui.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True, 'includes': ['PySide.QtCore', 'PySide.QtGui']}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
i've tried creating with both the --alias option and without. Even tried labeling them as packages. But nothing I do seems to include them.
Can Python find PySide.QtCore? At the command line type:
from PySide.QtCore import *
If (1) works then make sure the Python version your invoking when executing py2app at the command line is the same Python version you're using at step (1). Some operating systems such as Mac OS X come installed with an older version of Python, and if your application works correctly when invoking it at the command line, then be sure you're not invoking a totally different version of python when trying to build your app.
Related
I am using cx_Freeze version 5.1.1 and I have a python 2.7.9 application to package using cx_Freeze. The application is using the python 'requests' module (the version of requests is 2.18.4)
Here is my cx_Freeze setup.py file (note I am specifically including 'requests' in the packages to include):
from cx_Freeze import setup, Executable
import sys
from cx_Freeze import setup, Executable
packages_to_include =['lib','lib/DB','encodings.ascii','requests']
buildOptions = dict(
optimize=1,
excludes = ['tkinter'],
bin_includes = [
'libcrypto.so.1.0.0',
'libcrypto.so.10',
'libgssapi_krb5.so.2',
'libk5crypto.so.3',
'libkeyutils.so.1',
'libssl.so.1.0.1e',
'libssl.so.10'
],
includes = packages_to_include,
packages= ['urllib3','idna']
)
executables = [
Executable(
'workapp.py',
targetName = 'workapp'
)
]
setup(
name='Sample Flask App',
version = '0.1',
description = 'Sample Flask App',
#requires = ["requests"],
options = dict(build_exe = buildOptions),
executables = executables
)
The build completed successfully creating the executable, but upon running my application I got the below error:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/__startup__.py", line 14, in run
module.run()
File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py", line 26, in run
exec(code, m.__dict__)
File "vaas.py", line 2, in <module>
import requests
File "/usr/local/lib/python2.7/site-packages/requests/__init__.py", line 113, in <module>
from . import packages
ImportError: cannot import name packages
I am thinking it is either an issue with my cx_Freeze setup or with requests, but since I tell cx_Freeze to include 'requests', this should work.
I checked in the build directory (that cx_Freeze builds that the requests modules has 'packages' defined and I can find it:
[user#centos-vm]$ ls build/exe.linux-x86_64-2.7/lib/requests/packages/
chardet idna urllib3
Any help is much appreciated!
Found a workaround to this issue:
edit:
/usr/local/lib/python2.7/site-packages/requests/__init__.py
and comment out:
from . import packages
Very strange issue indeed. My unfrozen application works just fine, but the above workaround is needed when using cx_freeze.
Try to add 'request' to the packages list option instead of adding it to the includes list options:
packages= ['urllib3', 'idna', 'requests']
According to the cx_Freeze documentation, the build_exe option includes is a
comma separated list of names of modules to include
whereas the build_exe option packages is a
comma separated list of packages to include, which includes all submodules in the package
I am working on packaging our Python app and Py2App on Mac is not including CefPython library which forms the basis of our app. From what I can see in the app contents, it includes the entire Python3 library, but not CEFPython. How can I add CefPython in setup.py? Currently, when I am generating the .app file and executing it, I get an error and Mac asks me if I want to open the console. I see nothing in install.log
setup.py :
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['Our_APP.py']
DATA_FILES = []
OPTIONS = {}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Updated script
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
from setuptools import setup
APP = ['20notes.py']
DATA_FILES = []
OPTIONS = {'packages':['cefpython3','objc']}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app','cefpython3']
)
Updated error :
Traceback (most recent call last):
File "setup.py", line 18, in <module>
setup_requires=['py2app','cefpython3'],
TypeError: None is not a string
I have tried removing the comma, removing cefpython3 option, nothing works. Any idea. THank you.
Try adding 'cefpython3' package to OPTIONS:
OPTIONS = {
'packages' : ['cefpython3', 'objc'],
}
Also set this:
os.environ['MACOSX_DEPLOYMENT_TARGET'] = "10.9"
I created a python script that uses pythonnet. The script is in a file named main.py. When I run the script from the command line (simply typing main.py at the Windows command prompt), the imported pythonnet module clr works fine. But when I try to build an exe I get an error saying: No module named clr.
To isolate the cause of this, I have verified that building an executable (in my case a simple Tkinter app) using py2exe works. I only have Python 3.4 installed and have verified that where python points to C:\Python34\python.exe.
The error occurs at executable build time and seems to be triggered by including clr in the section {"includes":["sip","clr"]}} in my setup.py for py2exe. The full traceback is below:
Traceback (most recent call last):
File "setup.py", line 32, in <module>
windows = [{'script': "main.py"}],
File "C:\Python34\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Python34\lib\distutils\dist.py", line 917, in run_commands
self.run_command(cmd)
File "C:\Python34\lib\distutils\dist.py", line 936, in run_command
cmd_obj.run()
File "C:\Python34\lib\site-packages\py2exe\distutils_buildexe.py", line 188, i
n run
self._run()
File "C:\Python34\lib\site-packages\py2exe\distutils_buildexe.py", line 267, i
n _run
builder.analyze()
File "C:\Python34\lib\site-packages\py2exe\runtime.py", line 164, in analyze
mf.import_hook(modname)
File "C:\Python34\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Python34\lib\site-packages\py2exe\mf3.py", line 273, in _gcd_import
raise ImportError('No module named {!r}'.format(name), name=name)
ImportError: No module named 'clr'
I also read/tried these:
https://docs.python.org/2/distutils/setupscript.html
https://pythonhosted.org/setuptools/setuptools.html
http://sourceforge.net/p/py2exe/mailman/message/6937658
leading me to move clr.pyd and Python.Runtime.dll into various locations including the location of main.py, C:\Python34\Lib\site-packages (where they were originally) and C:\Python34\Lib\site-packages\py2exe
None of these have worked and I don't know what to try next. I can see that for some reason py2exe can't find either clr.pyd or Python.Runtime.dll or both, but can't see why. Does anyone have any ideas?
Code details
My main.py script looks like this:
import clr
clr.AddReference("name.xxxx")
from name.xxxx import aaa
from clr import System
# All my functioning code, that I've verified works when run from the command line
This is what my setup.py file contains (I've left some bits commented so you can see what I've tried):
from distutils.core import setup
import py2exe, sys, os
mydata_files = []
for files in os.listdir('C:\\d\\Project\\TOOLS\\data_acquisition\\trunk\\DLL'):
f1 = 'C:\\d\\Project\\TOOLS\\data_acquisition\\trunk\\DLL\\' + files
if os.path.isfile(f1): # skip directories
f2 = '.', [f1]
mydata_files.append(f2)
setup(
data_files=mydata_files,
# options = {"py2exe" : {"includes" : "module1,module2,module3"}}
options = {"py2exe": {"includes":["sip", "clr"]}},
# options = {'py2exe': {'bundle_files': 1 , 'compressed': True,"includes":["sip"]}},
#python setup.py py2exe
#CLR.dll and PythonRuntime.dll
# options = {'py2exe': {'bundle_files': 1, "skip_archive":1 ,"includes":["sip"]}},
windows = [{'script': "main.py"}],
# data_files=mydata_files,
# zipfile = None
)
If I change the line options = {"py2exe": {"includes":["sip", "clr"]}}, to options = {"py2exe": {"includes":["sip"]}}, then the .exe builds, but obviously does not function correctly.
###Install description
For reference, I performed standard install of py2exe using pip install py2exe. This puts py2exe into the Lib\site-packages for your python install. Next, I installed pythonnet by downloading the .whl from Christoph Gohlke's unofficial Windows binaries page, then using pip install path\to\pythonnet-2.0.0<version_numbers>.whl. This puts clr.pyd and Python.Runtime.dll into Lib\site-packages for your python install. This question and answers have further info.
###Problem
This is a rather strange behaviour of py2exe that is hard to debug. I think it is purely a bug in that tool. In addition, the error message is not helpful.
The problem is that the module clr is specifically excluded by the tool, via its hooks.py file. It is not clear why. You can see the line that does this exclusion here.
###Solution
The workaround is to delete the word clr from the windows_excludes variable hooks.py file in your py2exe installation. Assuming everything is in its standard place - that means deleting line 23 in the file hooks.py located in C:\Python34\Lib\site-packages\py2exe. you also need to make sure that Python.Runtime.dll is somehow packaged with your .exe - I tested this by adding it to data files. Here is the example that I tested and worked - I used a very simple main.py to illustrate the import and to assure myself that the program was actually working. I left your setup.py as close as possible to your version, commenting out the lines that did not suit my system
To actually make the .exe - use the following (you may not need the path to the python.exe if python is aliased to your Python 3 install)
C:\python34\python.exe setup.py py2exe
###main.py
import clr
# I import clr, but don't use it as this is not my
# expertise. The fact it imports without error means
# I'm pretty sure it will work
with open('out.txt','a') as f:
for i in range(30):
f.write(str(i))
###setup.py
from distutils.core import setup
import py2exe, sys, os
mydata_files = []
# I had to comment these out as they did not apply to my test environment
# for files in os.listdir('C:\\d\\Project\\TOOLS\\data_acquisition\\trunk\\DLL'):
# f1 = 'C:\\d\\Project\\TOOLS\\data_acquisition\\trunk\\DLL' + files
# if os.path.isfile(f1): # skip directories
# f2 = 'dll', [f1]
# mydata_files.append(f2)
# It's essential that the Python.Runtime.dll is packaged with main.exe
# This is how I've done it
mydata_files.append(('.',['C:\\Python34\\Lib\\site-packages\\Python.Runtime.dll']))
setup(
data_files=mydata_files,
# I've left all your commented lines in - they weren't necessary for my test
# options = {"py2exe" : {"includes" : "module1,module2,module3"}}
# I haven't included sip as I don't have it installed, but I think it will work
options = {"py2exe": {"includes":["clr"]}},
# options = {'py2exe': {'bundle_files': 1 , 'compressed': True,"includes":["sip"]}},
#python setup.py py2exe
#CLR.dll and PythonRuntime.dll
# options = {'py2exe': {'bundle_files': 1, "skip_archive":1 ,"includes":["sip"]}},
windows = [{'script': "main.py"}],
# data_files=mydata_files,
# zipfile = None
)
Edit: For anyone interested - I described how I isolated and found this bug in more detail in a chat conversation.
I am on Windows Server 2012R2, trying to compile a script with py2exe, within a virtualenv, and I'm getting issues whenever one of the application scripts tries to "import distutils" (in my case, it's somewhere inside a 3rd-party library, but I reduced the problem here).
Steps to reproduce:
Create a virtualenv
virtualenv venv
call venv\Scripts\activate
Install py2exe inside the virtualenv
easy_install --always-unzip py2exe-0.6.9.win64-py2.7.amd64.exe
Create setup.py
from distutils.core import setup
try:
import py2exe
except:
pass
setup(
console=[
'py2exe_distutils.py'
]
)
Create py2exe_distutils.py
import distutils
Run py2exe
python setup.py py2exe
Try to run the generated executable
dist\py2exe_distutils.exe
It returns:
C:\Users\root\p\dist\library.zip\distutils\__init__.py:14: UserWarning: The virtualenv distutils package at %s appears to be in the same location as the system distutils?
Traceback (most recent call last):
File "py2exe_distutils.py", line 6, in <module>
import distutils
File "distutils\__init__.pyc", line 25, in <module>
ImportError: cannot import name dist
The script runs fine when I run it directly (python py2exe_distutils.py), even from within the virtualenv.
Am I trying to do something unsupported by py2exe, or is something wrong with my setup?
I had the same problem while creating an executable that used pandas 0.12.0. This worked for me: before you create the executable, copy the distutils folder from the base python installation
robocopy C:\Python27\Lib\distutils venv\Lib\distutils /E /COPY:DAT
I am using virtualenv 12.0.4 and py2exe 0.6.6 on Windows 7 Professional. Some extra insight can be found here. This answer pointed me in the direction of just copying the files.
I wrote a small python script that interacts with the database. I wanted to create an exe of the script file and then send it to the end user instead of sending the script file itself. I am using pytoexe to create the exe file .
This is how my setup.py file looks like now
from distutils.core import setup
import py2exe
setup(
console=["Test.py"],
zipfile = None,
data_files=[("",
["config.xml"]),
],
name='Test',
version='1.0.0',
url='',
license='',
author='test user',
author_email='',
description='',
#package_dir = {'': 'Lib'},
py_modules =['pyodbc']
#packages = ['pyodbc']
)
I run the script using the following command line
python setup.py py2exe --bundle 2
While creating the exe , py2exe displays this message
The following modules appear to be missing
['ElementC14N', 'pyodbc']
However the exe is generated. Now, whenever I run this exe , i get this message
Traceback (most recent call last):
File "Test.py", line 4, in
ImportError: No module named pyodbc
The script that I have runs fine if i execute the script. Its only that when i create the exe , the exe does not work and gives me this message .
Any help would be appreciated .
Note :
I have the following imports in the script file
import xml.etree.ElementTree as ET
import pyodbc
The other error ["ElementC14N"] that is present while py2exe is generating is the exe, I believe is due to the xml file that I am reading settings from. any help to resolve that issue would be praiseworthy as well .
Thanks
thank you all ....
this is what i did and it started working for me
options = {"py2exe":{"packages":"encodings",
"includes":["pyodbc",
"datetime", "decimal"],
"bundle_files":2,
"optimize":2},},