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"
Related
My .app launches if i don't have the requests module imported into my app, but if it's included it crashes when trying to launch the .app compiled by py2app. I've tried to include requests into Setup.py and it still crashes.
i have py2app-0.21 installed.Running Python 3.6.4, MacOs Catalina 10.15.14
error log from console:
(org.pythonmac.unspecified.testapp.2888[62145]): Service exited with abnormal code: 255
Setup.py
from setuptools import setup
APP = ['test.py']
DATA_FILES = []
OPTIONS = {
'argv_emulation': True,
'includes': ['requests'],
'packages': ['requests', 'rumps']
}
setup(
app=APP,
name='TestApp',
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
The unspecified.testapp part of your error log tells me that you need to tell python where your app file actually is (relative path? absolute path? that will depend on your usecase)
Use some pathname manipulation to point to test.py
I built a keylogger in python and I used py2exe (version 0.13) to convert the python file to an exe. It worked perfectly, it included all the packages and everything.
I want my keylogger to come to mac also, so I tried to use py2app. I followed TheBlackBerryChannels tutorial. It was pretty good explaining everything but it didn't show how to install external packages that are installed from pip. Becuase I use the from pynput.keyboard import Key, Listener
import os
import datetime
from pathlib import Path
packages from pip.
In the full setup.py file this is what I have:
from setuptools import setup
APP = ['KeyLoggingMac.py']
OPTIONS = {
# 'iconfile':'logoapp.icns',
'argv_emulation': True,
'packages': ['pynput']
}
setup(
app=APP,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
What am I doing wrong? It doesn't include the pynput package, I figured that it would auto-include the os, datetime, and pathLib modules but why doesn't it include the pynput?
For simplicity sake in your main file import it like this:
from pynput import keyboard
Then in your setup file use 'includes' in OPTIONS, note that I also added the data file test.txt to write the key presses to a file:
from setuptools import setup
APP = ['TEST.py']
DATA_FILES = ['test.txt']
OPTIONS = {'includes': ['pynput']}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Then from your venv run py2app with the terminal command:
python setup.py py2app
You can also use py2applet to generate setup.py files but I find it never works properly.
py2applet --make-setup FILENAME.py
You will also need to give the app permission to access your global keyboard events. This is done in Preferences > Security & Privacy > Privacy
Up to Mojave you want the Accessibility tab then add your app in there, on Catalina you want Input Monitoring.
This works for me.
I'm trying to publish a python package, and I'm having trouble getting it to run after installing it via pip. I believe this is due to my "entry_points" property in my setup.py file.
Currently I can download the project via pip install my_package_name. When I try to run the package I enter my_package_name and get a NameError saying initialize() is not defined. However, if I enter python path/to/my_package_name/__main__.py it runs just fine. Below is my project tree and my setup.py and __main__.py files for reference:
my_package_name/
setup.py
my_package_name/
__init__.py
__main__.py
my_package_name.py
setup.py:
from distutils.core import setup
setup(
name = 'my_package_name',
version = '0.0.1',
packages = ['my_package_name'],
install_requires = ['this', 'that'],
license = 'Creative Commons Attribution-Noncommercial-Share Alike license',
description = 'My cool python package',
long_description = open('readme.txt').read(),
url = 'mypackagename.github.io',
author = 'My Name',
entry_points = {
'console_scripts': [
'my_package_name = my_package_name.__main__:main' # this is likely what I'm doing wrong
]
},
)
__main__.py:
from my_package_name import *
def main(args=None):
"""The main routine."""
if args is None:
args = sys.argv[1:]
initialize()
do_something()
do_something_else()
if __name__ == "__main__":
main()
If more info is needed please let me know. This is my first swing at python, so there might be a big, common-knowledge piece that I'm missing. Any help or suggestions are greatly appreciated. Thanks!
Edit
Here is the full error log when running my_package_name
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\Scripts\my_package_name-script.py", line 11, in <module>
load_entry_point('my_package_name==0.0.1', 'console_scripts', 'my_package_name')()
File "c:\program files (x86)\python36-32\lib\site-packages\my_package_name\__main__.py", line 12, in main
initialize()
NameError: name 'initialize' is not defined
I want to make a game called "dodgeball". I have a main script, a setup.py script and an image called ball.bmp. In my setup.py script I have the following code:
from setuptools import setup
APP = ['dodgeball.py']
DATA_FILES = ["ball.bmp"]
OPTIONS = {'argv_emulation': True}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
When I run
sudo python setup.py py2app
Everything goes perfectly, except when I try to open Dodgeball.app it gives me this error (In a pop-up error window):
dodgeball Error
Open Console
Terminate
And it only works in alias mode:
sudo python setup.py py2app -A
How should I fix this?
I'm on Mac OS X El Capitan (10.11). I'm aware the new Mac update broke a few stuff.
import pygame._view worked.
:D
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.