I am trying to create a py2app application on a Mac OS X 10.6 Server. I downloaded and installed py2app, but I can't get it to work (I get a "is a directory error"). The same exact code and setup.py file work perfectly with py2app on Mac OS X 10.9.
After some research I learned that Mac OS X 10.6 ships with py2applet and that's the one that works. I am trying to run py2applet directly to generate the app.
Here is my setup.py file:
from setuptools import setup
APP = ['app.py']
DATA_FILES = ['resource']
OPTIONS = {'argv_emulation': True, 'includes': ['wx', 'wx.wizard', 'wx.lib.mixins.listctrl']}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Here is the py2applet command that I am running:
It seems to complete, but the app crashes right away, so I feel like my parameters are wrong.
py2applet -i wx -i wx.wizard -i wx.lib.mixins.listctrl resource app.py
Thank you!
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 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"
So I finally have an app working while in py2app alias mode. I can open the file and it works well. After I remove the build & dist files and run python setup.py py2app, the package receives an error. Why would it be doing this?
magnolia.py:
from splinter import Browser
import webbrowser
with Browser() as browser:
# Visit URL
url = "http://magnolia.msstate.edu/k12/login.asp"
browser.visit(url)
browser.fill('username', 'magn0897')
# Find and click the 'search' button
button = browser.find_by_name('btnG')
# Interact with elements
browser.find_by_xpath('//html/body/div[3]/div[1]/div/section/form/input').click()
#Open browser in new tab to keep browser open
webbrowser.open_new_tab('http://magnolia.msstate.edu/k12/elementary.asp')
#source: https://splinter.readthedocs.io/en/latest/mouse-interaction.html
#Instructions:
# Activate: go into bin.... $source activate
# To Update Requirements File: $pip freeze > requirements.txt
#http://www.marinamele.com/from-a-python-script-to-a-portable-mac-application-with-py2app
setup.py:
from setuptools import setup
APP = ['magnolia.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True,'iconfile': 'robot.icns'}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
After $open magnolia.app in terminal:
You didn't give your os version so I will just give you the information that worked for me on MacOS X 10.10 Yosemite:
$pip3 virtualenv
$cd target/appsource/folder
$virtualenv env
$. env/bin/activate
$pip install py2app==0.11
$py2applet --make-setup appName.py
edit your settings to include any info you want
$python setup.py py2app -A
test everything to make sure your options are set up proper and everything is working as expected
$rm -rf build dist
$python setup.py py2app
$deactivate
If you are running Yosemite, you should be off to the races. If you are rocking something newer, there may be a better version of py2app for you to use.
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