py2app setup.py usage question - python

Ok so I'm trying to use py2app to generate a distribution for my project. I'm still not sure I get the hang of it tho. So my setup.py looks like this:
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
import setuptools
PACKAGES = ['sqlalchemy.dialects.sqlite']
MODULES = ['sqlite3']
APP = ['tvb/interfaces/web/run.py']
OPTIONS = {'argv_emulation': True,
'packages': PACKAGES ,
'includes' : MODULES }
DATA_FILES = []
setup(
app=APP,
data_files=DATA_FILES,
packages = setuptools.find_packages(),
include_package_data=True,
options={'py2app': OPTIONS},
setup_requires=['py2app', "pyopengl", "cherrypy", "sqlalchemy", "simplejson",
"formencode", "genshi", "quantities","numpy", "scipy",
"numexpr", "nibabel", "cfflib", "mdp", "apscheduler",
"scikits.learn"]
)
So my first question would be: What should I include in my MODULES for py2app here? Does py2app know to scan for the things in setup_requires and include them or do I need to add some entries for them in MODULES ?
Another problem is that I'm getting an: sqlalchemy.exc.ArgumentError: Could not determine dialect for 'sqlite' when trying to run my app. After lots of googling I only saw that for py2exe you need to include the sqlalchemy.dialects.sqlite as a package but it doesn't seem to work for me. Am I missing something here?
The last one is that I'm getting a: malformed object (load command 3 cmdsize not a multiple of 8) just before the python setup.py py2app. Is this normal?
Regards,
Bogdan

Well seems I got the whole thing wrong.
'includes' : ['sqlalchemy.dialects.sqlite']
Instead of packages, and that seems to have done the trick.

Related

Py2App error: ModuleNotFoundError: No module named 'cmath' when using Pandas

I am trying to build a standalone app that utilises Pandas. This is my setup.py file:
from setuptools import setup
APP = ['MyApp.py']
DATA_FILES = ['full path to/chromedriver']
PKGS = ['pandas','matplotlib','selenium','xlrd']
OPTIONS = {'packages': PKGS, 'iconfile': 'MyApp_icon.icns'}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app','pandas','matplotlib','selenium','xlrd'],
)
The making of the *.app file goes smoothly, but when I try to run it, it gives me the following error:
...
import pandas._libs.testing as _testing
File "pandas/_libs/testing.pyx", line 1, in init pandas._libs.testing
ModuleNotFoundError: No module named 'cmath'
I tried to include ‘cmath’ in my list of PKGS and in setup_requires in the setup.py file, but when I tried to build the app using py2app it gave me the error:
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('cmath')
I am stuck. I couldn't find anything useful online. cmath should be automatically included from what I have been reading. Any ideas on where is the problem and how can I fix it?
I think I have found a solution: downgrade to Python version 3.6.6.
See: python 3.6 module 'cmath' is not found
To uninstall Python I followed this process: https://www.macupdate.com/app/mac/5880/python/uninstall
Then I installed Python 3.6.6: https://www.python.org/downloads/release/python-366/
With Python 3.6.6, Py2App seem to work no problem and includes Pandas smoothly.
It seems that for some reasons cmath is not included in the latest versions of Python? I might be wrong. Please let me know what you think and if you have any questions.
P.S.: I am using MacOS (Mojave 10.14.6) and PyCharm.
I had a similar issue with py2app and cmath. I solved this by adding import cmath into the main script. (MyApp.py in your case) I think doing so may have the modulegraph to add the cmath library files.

How to create setup.py with library file as stand alone

I have a problem, i develop an application with python and i use some libraries like flask, sqlalchemy, etc...
The problem is that i have a define version of each library, and I want to deploy this python application in another computer without internet,
can I create a package or use setup.py and include the other package with path ?
I've already try this code, but the library aren't imported they said that :
ModuleNotFoundError: No module named 'cx_Oracle'
My code is:
from distutils.core import setup
setup(
# Application name:
name="MyApplication",
# Version number (initial):
version="0.1.0",
# Packages
packages=["App","App/service"],
include_package_data=True,
install_requires=[
"flask","cx_Oracle","pandas","sqlalchemy"
],
)
install_requires is a setuptools setup.py keyword that should be used to specify what a project minimally needs to run correctly.
It won’t install those libraries.
Maybe you should try pyinstaller (https://www.pyinstaller.org) to make ready runnable file to run on the other computer.

py2app ImportError with watchdog

I am attempting to use py2app to bundle a small Python app that I've made in Python 2.7 on Mac. My app uses the Watchdog library, which is imported at the top of my main file:
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
When running my program, these import statements work just fine, and the program works as expected. However, after running py2app, launching the bundled application generates the following error:
ImportError: No module named watchdog.observers
At first I thought it was something to do with the observers module being nested inside watchdog, but to test that, I added the line
import watchdog
to the top of my program, and then upon running the app, got the error
ImportError: No module named watchdog
so it seems that it actually can't find the watchdog package, for some reason.
I tried manually adding the watchdog package using py2app's --packages option:
$ python setup.py py2app --packages watchdog
but it had no effect.
My unbundled Python program runs just fine from the command line; other downloaded modules I've imported are giving no errors; and I have successfully bundled a simple "Hello World!" app using py2app, so I believe my setup is correct.
But I'm kind of out of ideas for how to get py2app to find the watchdog package. Any ideas or help would be greatly appreciated.
Edit: Here is the text of my setup.py, as generated by py2applet. I haven't modified it.
from setuptools import setup
APP = ['watcher.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Try manually including the desired packages in the setup.py file:
from setuptools import setup
APP = ['watcher.py']
DATA_FILES = []
PKGS = ['watchdog', /*whatever other packages you want to include*/]
OPTIONS = {
'argv_emulation': True,
'packages' : PKGS,
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
I had installed watchdog 0.5.4, a very old version as it turns out, and got the same error. The error was fixed after upgrading it to 0.8.3:
pip install watchdog --upgrade
Your problem generally indicates that the package (in your case "watchdog", or one of its dependencies) isn't installed, or at least not in a location that py2app expects to find packages.
Do you use the same python command for running py2app as for running the script from the command-line? What is the message of the ImportError you're getting (both when importing "watchdog" and importing "watchdog.observers"?
The (way too long) output of py2app should also mention that it cannot find some packages, and which ones.
As alluded to in one of the answers py2app does not seem to search the same set of paths that are used by the python interpreter, so you need to copy the python library to one of those locations.
For example I've got the MacPorts version of Python installed and found that when I had a module installed in /Library/Python/2.7/site-packages/ py2app wasn't finding it, but it would find it when I copied it into /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages. So to copy it over run :
sudo cp /Library/Python/2.7/site-packages/thatmodule.so /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
Then run the py2applet script again and build the app to check. If it's elsewhere you can do a search for all site-packages locations using Spotlight's command line interface:
mdfind -name site-packages

setuptools/easy_install does not install *.cfg files and locale directories?

I have a little problem with setuptools/easy_install; maybe someone could give me a hint what might be the cause of the problem:
To easily distribute one of my python webapps to servers I use setuptools' sdist command to build a tar.gz file which is copied to servers and locally installed using easy_install /path/to/file.tar.gz.
So far this seems to work great. I have listed everything in the MANIFEST.in file like this:
global-include */*.py */*.mo */*.po */*.pot */*.css */*.js */*.png */*.jpg */*.ico */*.woff */*.gif */*.mako */*.cfg
And the resulting tar.gz file does indeed contain all of the files I need.
It gets weird as soon as easy_install tries to actually install it on the remote system. For some reason a directory called locales and a configuration file called migrate.cfg won't get installed. This is odd and I can't find any documentaiton about this, but I guess it's some automatic ignore feature of easy_install?
Is there something like that? And if so, how do I get easy_install to install the locales and migrate.cfg files?
Thanks!
For reference here is the content of my setup.py:
from setuptools import setup, find_packages
requires = ['flup', 'pyramid', 'WebError', 'wtforms', 'webhelpers', 'pil', 'apns', \
'pyramid_beaker', 'sqlalchemy', 'poster', 'boto', 'pypdf', 'sqlalchemy_migrate', \
'Babel']
version_number = execfile('pubserverng/version.py')
setup(
author='Bastian',
author_email='test#domain.com',
url='http://domain.de/',
name = "mywebapp",
install_requires = requires,
version = __version__,
packages = find_packages(),
zip_safe=False,
entry_points = {
'paste.app_factory': [
'pubserverng=pubserverng:main'
]
},
namespace_packages = ['pubserverng'],
message_extractors = { 'pubserverng': [
('**.py', 'python', None),
('templates/**.html', 'mako', None),
('templates/**.mako', 'mako', None),
('static/**', 'ignore', None),
('migrations/**', 'ignore', None),
]
},
)
I hate to answer my own question this quickly, but after some trial and error I found out what the reason behind the missing files was. In fact it was more than one reason:
The SOURCES.txt file was older and included a full list of most files, which resulted in them being bundled correctly.
The MANIFEST.in file was correct, too, so all required files were actually in the .tar.gz archive as expected. The main problem was that a few files simply would not get installed on the target machine.
I had to add include_package_data = True, to my setup.py file. After doing that all files installed as expected.
I'll have to put some research into include_package_data to find out if this weird behavior is documented somewhere. setuptools is a real mess - especially the documentation.
The entire package distribution system in python leaves a lot to be desired. My issues were similar to yours and were eventually solved by using distutils (rather than setuptools) which honored the include_package_data = True setting as expected.
Using distutils allowed me to more or less keep required file list in MANIFEST.inand avoid using the package_data setting where I would have had to duplicate the source list; the draw back is find_packages is not available. Below is my setup.py:
from distutils.core import setup
package = __import__('simplemenu')
setup(name='django-simplemenu',
version=package.get_version(),
url='http://github.com/danielsokolowski/django-simplemenu',
license='BSD',
description=package.__doc__.strip(),
author='Alex Vasi <eee#someuser.com>, Justin Steward <justin+github#justinsteward.com>, Daniel Sokolowski <unemelpmis-ognajd#danols.com>',
author_email='unemelpmis-ognajd#danols.com',
include_package_data=True, # this will read MANIFEST.in during install phase
packages=[
'simplemenu',
'simplemenu.migrations',
'simplemenu.templatetags',
],
# below is no longer needed as we are utilizing MANIFEST.in with include_package_data setting
#package_data={'simplemenu': ['locale/en/LC_MESSAGES/*',
# 'locale/ru/LC_MESSAGES/*']
# },
scripts=[],
requires=[],
)
And here is a MANIFEST.in file:
include LICENSE
include README.rst
recursive-include simplemenu *.py
recursive-include simplemenu/locale *
prune simplemenu/migrations
You need to use the data_files functionality of setup - your files aren't code, so easy_install won't install them by default (it doesn't know where they go).
The upside of this is that these files are added to MANIFEST automatically - you don't need to do any magic to get them there yourself. (In general if a MANIFEST automatically generated by setup.py isn't sufficient, adding them yourself isn't going to magically get them installed.)

Python - install script to system

how can I make setup.py file for my own script? I have to make my script global.
(add it to /usr/bin) so I could run it from console just type: scriptName arguments.
OS: Linux.
EDIT:
Now my script is installable, but how can i make it global? So that i could run it from console just name typing.
EDIT: This answer deals only with installing executable scripts into /usr/bin. I assume you have basic knowledge on how setup.py files work.
Create your script and place it in your project like this:
yourprojectdir/
setup.py
scripts/
myscript.sh
In your setup.py file do this:
from setuptools import setup
# you may need setuptools instead of distutils
setup(
# basic stuff here
scripts = [
'scripts/myscript.sh'
]
)
Then type
python setup.py install
Basically that's it. There's a chance that your script will land not exactly in /usr/bin, but in some other directory. If this is the case, type
python setup.py install --help
and search for --install-scripts parameter and friends.
I know that this question is quite old, but just in case, I post how I solved the problem for myself, that was wanting to setup a package for PyPI, that, when installing it with pip, would install it as a system package, not just for Python.
setup(
# rest of setup
console_scripts={
'console_scripts': [
'<app> = <package>.<app>:main'
]
},
)
Details

Categories

Resources