Python setup.py setup() config{} - python

I'm a beginner in the process of learning how to create a skeleton directory complete with automated tests, install scripts etc. I am a fair ways from understanding all of this process despite the amount of time spent attempting to.
At this point in time all I can do in relation to this is make a source distribution and executable installer for a single module.
The format of my setup.py (using a template provided by my beginners book) for my skeleton project is:
#!/usr/bin/env
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
config = {
"description": "asks a question",
"author": "David",
"url": "none",
"download_url": "none",
"author email": "dmt257257#gmail.com",
"version": "0.1",
"install_requires": ["nose"],
"packages": ["ask_main", "tests"],
"scripts": [],
"name": "ask"
}
setup(**config)
However I see the format on python.org as:
#!/usr/bin/env python
from distutils.core import setup
setup(name='Distutils',
version='1.0',
description='Python Distribution Utilities',
author='Greg Ward',
author_email='gward#python.net',
url='https://www.python.org/sigs/distutils-sig/',
packages=['distutils', 'distutils.command'],
)
Can anyone explain why you would use the config method? What is '**' doing in setup(**config)?

Related

py2exe for distribution: Executable crashes

I am trying to make a single executable out of my application that uses matplotlib using Python 2.7 and py2exe. So, I have this standard routine:
from distutils.core import setup
import zmq.libzmq
import py2exe
import glob
import matplotlib
import shutil
ico_file = "C:/Users/MyPC/Documents/newIcon.ico"
setup( windows = [{
"script":"myApp.py",
"icon_resources": [(1, ico_file)]
}],
options={
'py2exe': {
'includes':['zmq.backend.cython',
'scipy.special._ufuncs_cxx',
'scipy.linalg.cython_blas',
'scipy.linalg.cython_lapack',
'scipy.sparse.csgraph._validation'],
'excludes':['zmq.libzmq'],
'dll_excludes':['libzmq.pyd'],
'bundle_files': 2,
'compressed': True
}
},
zipfile=None,
data_files=[ ('lib', (zmq.libzmq.__file__,), ico_file) ] + matplotlib.get_py2exe_datafiles()
)
Problem Definition The created file, myApp.exe, does not run after double clicking on it (or calling from cmd). So, I used Dependency walker and I can see that zlip.pyd is missing:
LoadLibraryA("c:\users\mypc\documents\myapp\bin\dist\zlib.pyd") returned NULL. Error: The specified module could not be found (126).
Now if I change 'bundle_files': 3, I have myApp.exe running just fine, though I get a cluttered distribution directory. Any ideas about what is going wrong here?

Setuptools entry_points/console_scripts have specific Python version in shebang

I am generating a Python package on RHEL6 (with Python2.6), and trying to deploy it to a RHEL7 server (Python2.7). The package includes scripts generated with entry_points/console_scripts.
However, the generated scripts have the specific python2.6 version in the shebang, as in:
#!/usr/bin/env python2.6
How can I override or disable this so it just generates:
#!/usr/bin/env python
entry_points = {
'console_scripts':[
...
]
},
options = {
'build_scripts': {
'executable': '/usr/bin/env python',
},
},

Esky not including sub-module

I have a medium-size PyQT5 desktop application that has been working fine with py2app. I want to incorporate Esky so that the app can update itself, but the app terminates during startup (before displaying the main window) with a log entry that says "HelloApp Error" (where "HelloApp" is the name of my application).
I've created a small test case that reproduces the problem that is available at https://github.com/markmont/esky-package-question
The test-case app has the following structure:
HelloApp/
HelloApp/
HelloApp.py
helloform
__init__.py
setup.py
setup.py contains:
from esky import bdist_esky
from distutils.core import setup
PY2APP_OPTIONS = {
'argv_emulation': True,
'includes': [ 'sip', 'PyQt5', 'helloform' ],
'qt_plugins': [ '*' ]
}
ESKY_OPTIONS = {
"freezer_module": "py2app",
"freezer_options": PY2APP_OPTIONS,
"includes": [ 'sip', 'PyQt5', 'helloform' ]
}
HelloApp = bdist_esky.Executable( "HelloApp/HelloApp.py", gui_only=True )
setup(
name='HelloApp',
version = "2014060301",
data_files=[],
options = { "bdist_esky": ESKY_OPTIONS },
scripts=[ HelloApp ]
)
HelloApp.py contains the statement from helloform import Form -- this appears to be what is causing the app to fail to start with the error "HelloApp Error", as if I remove that statement and paste in the contents of helloform/init.py the application starts up and works properly.
Also, if I move everything into a single directory and adjust the paths in setup.py, then the problem does not occur -- Esky finds helloform.py (formerly named helloform/init.py), includes it, and the application starts up and works properly:
HelloApp/
HelloApp.py
helloform.py # formerly ./HelloApp/helloform/__init__.py
setup.py
...but putting everything in single directory is not a scalable solution for a medium-to-large application.
There are no error messages in the output of python setup.py bdist_esky when the problem occurs, and I have not found the answer in the Esky documentation or in various examples on the web.
The full error from /var/log/system.log is:
2014-06-03 13:03:07.100 HelloApp[14968]: HelloApp Error
I'm assuming that I'm not using Esky's includes option properly in setup.py, but I've got no clue as to how to fix this -- can anyone help?
Other possibly relevant details: MacOS X 10.9 Mavericks, Python 2.7.6 (local build), qt-5.3.0 opensource, sip 4.16, PyQT 5.3.0 (GPL), py2app 0.8.1 patched to support PyQT5, and the latest version of Esky from GitHub.
Thanks in advance!
I've solved this problem -- the problem was due to my limited knowledge of Python distutils and setuptools. Since things "just worked" with py2app (which was using setuptools), I assumed that the problem was with how Etsy was configured when the problem was really with how I was using distutils.
The problem was that helloworld.py was not being copied into the frozen app.
The solution involved restructuring the files and changing the disutils configuration to explicitly add HelloApp as a package.
New file structure:
HelloApp/
hello.py # formerly HelloApp.py
HelloApp/
__init__.py
helloform.py
setup.py
New setup.cfg:
from esky import bdist_esky
from distutils.core import setup
PY2APP_OPTIONS = {
'argv_emulation': True,
'includes': [ 'sip', 'PyQt5' ],
'qt_plugins': [ '*' ]
}
ESKY_OPTIONS = {
"freezer_module": "py2app",
"freezer_options": PY2APP_OPTIONS,
"includes": [ 'sip', 'PyQt5' ]
}
HelloApp = bdist_esky.Executable( "hello.py", gui_only=True )
setup(
name='hello',
version = "2014060301",
data_files=[],
options = { "bdist_esky": ESKY_OPTIONS },
scripts=[ HelloApp ],
packages=[ 'HelloApp' ],
)

Compiling docx with py2exe

I'm compiling a python script to .exe via py2exe. I originally started compiling it and the entire program ran fine aside from the Word document creation.
My logfile would give me: ERROR: Could not close or save Word Document 'docName.docx' :, so where I am supposed to be supplied an error message - I am not.
I started to think it could do with the missing modules in py2exe, reported as:
The following modules appear to be missing
['ICCProfile', '_imaging_gif', '_scproxy', '_sysconfigdata']
And then I noticed many people didn't care too much about these errors.
I looked in the docx package, located in C:\Python27\Lib\site-packages\docx-0.2.4-py2.7.egg\, as installed by easy_install, and saw this docx-templates folder, which I am certain was not imported, so I wrote my setup.py referencing the docx-template I put in my build folder manually:
from distutils.core import setup
from glob import glob
import os
import py2exe
#templatePath = 'C:/Python27/Lib/site-packages/docx-0.2.4-py2.7.egg/docx-template'
setup(
console=['xmlpolicydocx-0.4.py'],
options={
'py2exe':
{
'includes': ['docx', 'PIL', 'lxml.etree', 'lxml._elementpath', 'gzip']
}
},
packages=[
'docx-template'
],
package_data={
'docx-template': [
'_rels/*',
'docProps/*',
'word/theme/*.xml',
'word/*.xml'
],
},
)
Yet I still have no luck in getting docx to work when compiled via py2exe. Any suggestions or methods of debugging I can take to take another look at solving this problem?

Py2Exe and Easgui

I am trying to convert a py file to an exe.
Here is the code for my setupfile
from distutils.core import setup
import py2exe
setup(console=["mycode.py"])
When I use cmd, it says:
Import Error: No module named easygui
How do I let py2exe know about the easygui? As well as the numpy and mathplotlib (all are used in mycode.py)
First, use pyinstaller. It is newer and better (though I have used py2exe until switching to pyinstaller) And it seems to have much better recipes for finding your included libs.
But for py2exe, you will need to expand that setup.py a bit more to tell it what to include (since they are probably hidden imports)
setup(
console=["mycode.py"],
options={
"py2exe": {
"includes": ["easygui"],
"bundle_files": 1
},
},
zipfile = None,
)
If this fails to build, then easygui is not in your PYTHONPATH properly. Make sure you are not doing something special in your script to add a pythonpath, which would not be visible to py2exe.
You may need to do a little more work with this file for numpy and matplotlib. See this wiki for help
Relative to the issue of the specific dll's mentioned, I had similar issues but fixed those problems by specifically excluding those in the setup lie so:
setup(
console=['DET14.py'],
options={
'py2exe': {
'packages' : ['matplotlib', 'pytz'],
'dll_excludes':['MSVCP90.DLL',
'libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll',
'libgdk_pixbuf-2.0-0.dll'],
'includes':['scipy.sparse.csgraph._validation',
'scipy.special._ufuncs_cxx']
}
},
data_files=matplotlib.get_py2exe_datafiles()
)`
I would say try adding that exclude to your setup statement.

Categories

Resources