Creating an OSX PyQt app using Pyinstaller 2, PyQt4 and Qt5 - macos

I am trying to package a PyQt program for OSX using PyInstaller 2, where PyQt4 (4.10) has been built against Qt 5.0.2 (from Git). The following simple example doesn't work.
import sys
from PyQt4.QtGui import QApplication, QMessageBox
def main():
print "Hello"
a = QApplication(sys.argv)
m = QMessageBox(QMessageBox.Information, "Title", "Hello")
m.exec_()
if __name__=="__main__":
main()
Spec file generated using pyinstaller-2.0/utils/MakeSpec.py and modified to add the BUNDLE class.
a = Analysis(['hello.py'],
pathex=['/Users/glenn/rp/src/demo'],
hiddenimports=[],
hookspath=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
exclude_binaries=1,
name=os.path.join('build/pyi.darwin/hello', 'hello'),
debug=False,
strip=None,
upx=True,
console=False )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=None,
upx=True,
name=os.path.join('dist', 'hello'))
app = BUNDLE(coll,
name=os.path.join('dist', 'hello.app'),
appname="Hello",
version = '0.1'
)
Packaging command
> python pyinstaller.py --windowed hello.spec
Running the binary directly from the terminal gives this output before it crashes:
$ ./dist/hello.app/Contents/MacOS/hello
Hello
Failed to load platform plugin "cocoa". Available platforms are:
Abort trap: 6
and this is the stack trace:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
abort() called
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x9a671a6a __pthread_kill + 10
1 libsystem_c.dylib 0x93163b2f pthread_kill + 101
2 libsystem_c.dylib 0x9319a4ec abort + 168
3 QtCore 0x03db156b qt_message_fatal(QtMsgType, QMessageLogContext const&, QString const&) + 11
4 QtCore 0x03db19df QMessageLogger::fatal(char const*, ...) const + 63
5 QtGui 0x068abceb QGuiApplicationPrivate::createPlatformIntegration() + 3547
6 QtGui 0x068abd16 QGuiApplicationPrivate::createEventDispatcher() + 38
7 QtCore 0x03f4f2c4 QCoreApplication::init() + 100
8 QtCore 0x03f4f23b QCoreApplication::QCoreApplication(QCoreApplicationPrivate&) + 59
9 QtGui 0x068aa0d0 QGuiApplication::QGuiApplication(QGuiApplicationPrivate&) + 32
10 QtWidgets 0x06c695de QApplication::QApplication(int&, char**, int) + 238
11 PyQt4.QtGui.so 0x06394454 init_QApplication + 196
12 sip.so 0x007bc7d5 sipSimpleWrapper_init + 266
13 Python 0x0385c174 type_call + 340
14 Python 0x0380d401 PyObject_Call + 97
15 Python 0x0389c093 PyEval_EvalFrameEx + 10131
16 Python 0x038a0490 fast_function + 192
17 Python 0x0389beae PyEval_EvalFrameEx + 9646
18 Python 0x038998b2 PyEval_EvalCodeEx + 1922
19 Python 0x03899127 PyEval_EvalCode + 87
20 Python 0x038be06e PyRun_StringFlags + 126
21 Python 0x038bdfb1 PyRun_SimpleStringFlags + 81
22 Python 0x038bf619 PyRun_SimpleString + 25
23 hello 0x00003240 runScripts + 240
24 hello 0x0000280a main + 442
25 hello 0x00001eb9 _start + 224
26 hello 0x00001dd8 start + 40
The issue appears to be that it can't find the libqcocoa.dylib plugin. This is not surprising as it is not packaged. Is that the actual issue here and do I need to include this plugin? If so where does it need to go? I have tried putting it in demo.app/Contents/plugins but that doesn't help.

The right place to put libqcocoa.dylib is in Contents/MacOS/qt4_plugins/platforms:
extralibs = [("qt4_plugins/platforms/libqcocoa.dylib", "/path/to/libqcocoa.dylib", "BINARY")
]
coll = COLLECT(exe,
a.binaries + extralibs,
a.zipfiles,
a.datas,
strip=None,
upx=False,
name=os.path.join('dist', 'hello'))
The app now starts but the dialog window never appears. Edit: This is because PyInstaller (v 2.0) adds LSBackgroundOnly=true to the apps Info.plist. Removing this allows the window to show.

Try adding (but changed for PyQt):
from PySide import QtCore, QtGui
At least that works for me (PySide 1.1.1, Qt 4.8.1, latest dev Pyinstaller, OSX 10.7.5, with no changes to the spec file and --onefile --windowed arguments to pyinstaller.) And without this snippet, it also crashes for me.
I suppose that pulls in more dependencies.
Found this in another answer.

Related

unrecognised selector sent to instance when attaching GLFW Cocoa Window to IPlugView (VST3SDK)

I'm doing some work with the Steinberg VST3SDK and have bumped into an error I don't really understand:
[GLFWWindow window]: unrecognized selector sent to instance 0x7fe10430a830
2022-12-22 08:11:08.981 MyHost[1593:20791] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GLFWWindow window]: unrecognized selector sent to instance 0x7fe10430a830'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff37903a17 __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff70468a9e objc_exception_throw + 48
2 CoreFoundation 0x00007fff37982e36 -[NSObject(NSObject) __retain_OA] + 0
3 CoreFoundation 0x00007fff37868190 ___forwarding___ + 1427
4 CoreFoundation 0x00007fff37867b68 _CF_forwarding_prep_0 + 120
5 Digitalis 0x000000010a9dc990 GetPluginFactory + 1922288
6 Digitalis 0x000000010a9dbb85 GetPluginFactory + 1918693
7 Digitalis 0x000000010a80db6e GetPluginFactory + 26318
8 MyHost 0x000000010a624641 _ZN6Plugin4loadERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE + 2065
9 MyHost 0x000000010a624e9d main + 61
10 libdyld.dylib 0x00007fff71608cc9 start + 1
11 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
i guess this leads me to question whether the kPlatformType “NSView” is equivalent to glfwGetCocoaWindow()'s “NSWindow” return value?
heres the snippet of code thats causing me errors:
if (!glfwInit()) {
std::cout << "Failed to initialise Editor Window" << std::endl;
return false;
}
auto view = controller->createView(Steinberg::Vst::ViewType::kEditor);
Steinberg::ViewRect dimensions;
view->getSize(&dimensions);
editorWindow = glfwCreateWindow(dimensions.getWidth(), dimensions.getHeight(), "VST 3 SDK", nullptr, nullptr);
view->attached(glfwGetCocoaWindow(editorWindow), Steinberg::kPlatformTypeNSView);
can also confirm that the windows equivalent of this works fine:
view->attached(glfwGetWin32Window(editorWindow), Steinberg::kPlatformTypeHWN
any type of explanation whether it be for debugging the error message itself or the VST3SDK side would be greatly appreciated!
i tried:
view->attached(glfwGetCocoaWindow(editorWindow), Steinberg::kPlatformTypeNSView);
and expected the vst3 view to be attached to my GLFW window

Cannot InsertText with Message App Extension

I'm creating a Message App Extension in Xamarin and am getting a NSException error when trying to InsertText from the MessagesViewController. I do not see error messages when building, just when this InsertText code is executed. Appreciate your help/expertise.
InsertText code
public void InsertMessage(string message)
{
ActiveConversation.InsertText(message, (err) => {
if (err != null)
{
Console.WriteLine("ERROR: " + err.ToString());
}
});
Console.WriteLine("Inserted text");
}
Console Error Message
2022-10-19 14:17:02.869031-0700 MobileSMS[40085:1435095] -[CKIMDaemonController preWarm]: unrecognized selector sent to instance 0x60000326aa80
2022-10-19 14:17:02.871325-0700 MobileSMS[40085:1435095] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CKIMDaemonController preWarm]: unrecognized selector sent to instance 0x60000326aa80'
*** First throw call stack:
(
0 CoreFoundation 0x00007ff800427378 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007ff80004dbaf objc_exception_throw + 48
2 CoreFoundation 0x00007ff800436588 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3 CoreFoundation 0x00007ff80042b83d ___forwarding___ + 1431
4 CoreFoundation 0x00007ff80042db38 _CF_forwarding_prep_0 + 120
5 IMCore 0x00007ff810903f11 IMCoreSimulatedEnvironmentEnabled + 155997
6 ChatKit 0x00000001098998c0 __46-[CKChatInputController _startEditingPayload:]_block_invoke + 591
7 ChatKit 0x00000001099f25ae __69+[CKComposition compositionWithShelfPluginPayload:completionHandler:]_block_invoke + 115
8 libdispatch.dylib 0x00007ff80013b7fb _dispatch_call_block_and_release + 12
9 libdispatch.dylib 0x00007ff80013ca3a _dispatch_client_callout + 8
10 libdispatch.dylib 0x00007ff80014c32c _dispatch_main_queue_drain + 1338
11 libdispatch.dylib 0x00007ff80014bde4 _dispatch_main_queue_callback_4CF + 31
12 CoreFoundation 0x00007ff8003869f7 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
13 CoreFoundation 0x00007ff8003813c6 __CFRunLoopRun + 2482
14 CoreFoundation 0x00007ff800380637 CFRunLoopRunSpecific + 560
15 GraphicsServices 0x00007ff809c0f28a GSEventRunModal + 139
16 UIKitCore 0x00000001145c4425 -[UIApplication _run] + 994
17 UIKitCore 0x00000001145c9301 UIApplicationMain + 123
18 MobileSMS 0x0000000106198220 MobileSMS + 131616
19 dyld 0x00000001063ed2bf start_sim + 10
20 ??? 0x000000010d42a52e 0x0 + 4517438766
)
libc++abi: terminating with uncaught exception of type NSException
The error seems to be related to using the iPhone simulator, as I got it to work on a connected device without any errors.

Jupyter notebook Conda error running MoviePy code

On my macOS v 10.11.6, I got an error running moviepy on jupyter notebook
Python v 3.5.2
Conda v 4.3.8
Jupyter 4.2.1
I'm importing and running a simple cell:
from moviepy.editor import VideoFileClip
from IPython.display import HTML
new_clip_output = 'test_output.mp4'
test_clip = VideoFileClip("test.mp4")
new_clip = test_clip.fl_image(lambda x: cv2.cvtColor(x, cv2.COLOR_RGB2YUV)) #NOTE: this function expects color images!!
%time new_clip.write_videofile(new_clip_output, audio=False)
The error is:
TypeError Traceback (most recent call last)
<ipython-input-8-27aee53c99d8> in <module>()
1 new_clip_output = 'test_output.mp4'
--> 2 test_clip = VideoFileClip("test.mp4")
3 new_clip = test_clip.fl_image(lambda x: cv2.cvtColor(x, cv2.COLOR_RGB2YUV)) #NOTE: this function expects color images!!
4 get_ipython().magic('time new_clip.write_videofile(new_clip_output, audio=False)')
/Users/<username>/anaconda3/envs/carnd-term1/lib/python3.5/site-packages/moviepy/video/io/VideoFileClip.py in __init__(self, filename, has_mask, audio, audio_buffersize, audio_fps, audio_nbytes, verbose)
80 buffersize= audio_buffersize,
81 fps = audio_fps,
--> 82 nbytes = audio_nbytes)
83
84 def __del__(self):
/Users/<username>/anaconda3/envs/carnd-term1/lib/python3.5/site-packages/moviepy/audio/io/AudioFileClip.py in __init__(self, filename, buffersize, nbytes, fps)
61 self.filename = filename
62 reader = FFMPEG_AudioReader(filename,fps=fps,nbytes=nbytes,
--> 63 buffersize=buffersize)
64
65 self.reader = reader
/Users/<username>/anaconda3/envs/carnd-term1/lib/python3.5/site-packages/moviepy/audio/io/readers.py in __init__(self, filename, buffersize, print_infos, fps, nbytes, nchannels)
68 self.buffer_startframe = 1
69 self.initialize()
--> 70 self.buffer_around(1)
71
72
/Users/<username>/anaconda3/envs/carnd-term1/lib/python3.5/site-packages/moviepy/audio/io/readers.py in buffer_around(self, framenumber)
232 else:
233 self.seek(new_bufferstart)
--> 234 self.buffer = self.read_chunk(self.buffersize)
235
236 self.buffer_startframe = new_bufferstart
/Users/<username>/anaconda3/envs/carnd-term1/lib/python3.5/site-packages/moviepy/audio/io/readers.py in read_chunk(self, chunksize)
121 result = (1.0*result / 2**(8*self.nbytes-1)).\
122 reshape((len(result)/self.nchannels,
--> 123 self.nchannels))
124 #self.proc.stdout.flush()
125 self.pos = self.pos+chunksize
TypeError: 'float' object cannot be interpreted as an integer
Is it because of some conflict in versions of various libraries?

Swift + Parse: 'Can't use nil for keys or values on PFObject. Use NSNull for values.'

So I have a Swift application that I am working on (in Xcode 7.3).
It uses Parse and in it I have a function that is generating the error message stated in the title.
The code appears as follows;
#IBAction func callUber(sender: AnyObject) {
let riderRequest = PFObject(className:"riderRequest")
riderRequest["username"] = PFUser.currentUser()?.username
riderRequest["location "] = PFGeoPoint(latitude:latitude, longitude:longitude)
riderRequest.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
self.callUberButton.setTitle("Cancel Uber", forState: UIControlState.Normal)
} else {
let alert = UIAlertController(title: "Could not call Uber", message: "Please try again", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
}
Now somewhere in this code nil is being applied to a value, and this causes the error message (or so I think). I have been looking around on SO for solutions to this problem, however I could not find any similar threads for this error message and Swift, only Objective-C.
I'm guessing that I have to introduce some sort of error handling or check where I make sure that the value of the object is not nil, however I cant seem to figure out where, or how to apply this.
The error is only triggered when I press the "callUber" button, and the full output from the debug console follows below.
2016-04-15 12:21:01.900 ParseStarterProject-Swift[8781:2591354] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use nil for keys or values on PFObject. Use NSNull for values.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ca98d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010eca0deb objc_exception_throw + 48
2 CoreFoundation 0x000000010ca98cbd +[NSException raise:format:] + 205
3 ParseStarterProject-Swift 0x000000010c1042a8 -[PFObject(Private) _setObject:forKey:onlyIfDifferent:] + 122
4 ParseStarterProject-Swift 0x000000010c107d01 -[PFObject setObject:forKey:] + 53
5 ParseStarterProject-Swift 0x000000010c107d46 -[PFObject setObject:forKeyedSubscript:] + 50
6 ParseStarterProject-Swift 0x000000010c0c847f _TFC25ParseStarterProject_Swift19RiderViewController8callUberfPs9AnyObject_T_ + 671
7 ParseStarterProject-Swift 0x000000010c0c89d6 _TToFC25ParseStarterProject_Swift19RiderViewController8callUberfPs9AnyObject_T_ + 54
8 UIKit 0x000000010d726a8d -[UIApplication sendAction:to:from:forEvent:] + 92
9 UIKit 0x000000010d899e67 -[UIControl sendAction:to:forEvent:] + 67
10 UIKit 0x000000010d89a143 -[UIControl _sendActionsForEvents:withEvent:] + 327
11 UIKit 0x000000010d899263 -[UIControl touchesEnded:withEvent:] + 601
12 UIKit 0x000000010d79999f -[UIWindow _sendTouchesForEvent:] + 835
13 UIKit 0x000000010d79a6d4 -[UIWindow sendEvent:] + 865
14 UIKit 0x000000010d745dc6 -[UIApplication sendEvent:] + 263
15 UIKit 0x000000011dfe0b15 -[UIApplicationAccessibility sendEvent:] + 77
16 UIKit 0x000000010d71f553 _UIApplicationHandleEventQueue + 6660
17 CoreFoundation 0x000000010c9be301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
18 CoreFoundation 0x000000010c9b422c __CFRunLoopDoSources0 + 556
19 CoreFoundation 0x000000010c9b36e3 __CFRunLoopRun + 867
20 CoreFoundation 0x000000010c9b30f8 CFRunLoopRunSpecific + 488
21 GraphicsServices 0x0000000111eb0ad2 GSEventRunModal + 161
22 UIKit 0x000000010d724f09 UIApplicationMain + 171
23 ParseStarterProject-Swift 0x000000010c0cc712 main + 114
24 libdyld.dylib 0x000000010f7a792d start + 1
25 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
A couple of things that may be the issue:
Double check your class name is "riderRequest", I think "RiderRequest" could possibly be the actual name.
Second is to check all your key names are correct by going to the parse dashboard and having a look at your class
Last thing is to confirm that all your values for things like username and latitude and longitude are not nil before setting them.
Maybe try:
if let username = PFUser.currentUser()?.username && latitude != nil && longitude != nil {
riderRequest.setObject(username, forKey: "username")
riderRequest.setObject(PFGeoPoint(latitude: latitude, longitude: longitude), forKey: "location")
//then run the rest of the code as you have been
}

nearby places swift 2 error

I work on a ios application that requires to use nearby places api from google. It worked very well with swift but now , when i updated my xcode to xcode 7 and it changed from swift to swift 2 it doesn't work anymore. I am stuck with this , any help will be apreciated .
Here is the request for the api :
func fetchPlacesNearCoordinate(coordinate: CLLocationCoordinate2D, radius: Double, name : String){
var urlString = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=\(44.942149),\(26.02453)&radius=\(radius)&types=food"
urlString += "&key=\(apiServerKey)"
urlString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
if placesTask.taskIdentifier > 0 && placesTask.state == .Running {
placesTask.cancel()
}
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
do{
//******************Here's the line that displays error
placesTask = session.dataTaskWithURL(NSURL(string: urlString)!) {
(data, response, error) -> Void in
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
//var placesArray = [GooglePlace]()
do {
if let json = try NSJSONSerialization.JSONObjectWithData(data!, options:[]) as? NSDictionary {
if let results = json["results"] as? NSArray {
for rawPlace:AnyObject in results {
print(rawPlace)
var placename = ""
if let name = rawPlace["name"] as? NSString {
placename = name as String
}
}
}
}
} catch {
//handle error
}
/*dispatch_async(dispatch_get_main_queue()) {
completion(placesArray)
}*/
}
}catch{
}
placesTask.resume()
}
And the errors i get :
2015-10-02 16:57:54.586 QR Code[4331:67414] -[NSURLSessionDataTask taskIdentifier]: unrecognized selector sent to instance 0x7fe791c3b840
2015-10-02 16:57:54.591 QR Code[4331:67414] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURLSessionDataTask taskIdentifier]: unrecognized selector sent to instance 0x7fe791c3b840'
*** First throw call stack:(
0 CoreFoundation 0x0000000111a8ef65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000111506deb objc_exception_throw + 48
2 CoreFoundation 0x0000000111a9758d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001119e4f7a ___forwarding___ + 970
4 CoreFoundation 0x00000001119e4b28 _CF_forwarding_prep_0 + 120
5 QR Code 0x000000010f57b3ff _TFC7QR_Code17MapViewController25fetchPlacesNearCoordinatefS0_FTVSC22CLLocationCoordinate2D6radiusSd4nameSS_T_ + 1215
6 QR Code 0x000000010f57bfd3 _TFC7QR_Code17MapViewController11viewDidLoadfS0_FT_T_ + 1555
7 QR Code 0x000000010f57c552 _TToFC7QR_Code17MapViewController11viewDidLoadfS0_FT_T_ + 34
8 UIKit 0x00000001122ae931 -[UIViewController loadViewIfRequired] + 1344
9 UIKit 0x00000001122b4923 -[UIViewController __viewWillAppear:] + 120
10 UIKit 0x00000001122e418a -[UINavigationController _startCustomTransition:] + 1177
11 UIKit 0x00000001122f37c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
12 UIKit 0x00000001122f467d -[UINavigationController __viewWillLayoutSubviews] + 57
13 UIKit 0x000000011248c63d -[UILayoutContainerView layoutSubviews] + 248
14 UIKit 0x00000001121d411c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
15 QuartzCore 0x000000010fe7536a -[CALayer layoutSublayers] + 146
16 QuartzCore 0x000000010fe69bd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
17 QuartzCore 0x000000010fe69a4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
18 QuartzCore 0x000000010fe5e1d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
19 QuartzCore 0x000000010fe8b9f0 _ZN2CA11Transaction6commitEv + 508
20 UIKit 0x000000011211e1b6 _UIApplicationHandleEventQueue + 7183
21 CoreFoundation 0x00000001119bb0a1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x00000001119b0fcc __CFRunLoopDoSources0 + 556
23 CoreFoundation 0x00000001119b0483 __CFRunLoopRun + 867
24 CoreFoundation 0x00000001119afe98 CFRunLoopRunSpecific + 488
25 GraphicsServices 0x0000000115770ad2 GSEventRunModal + 161
26 UIKit 0x0000000112123676 UIApplicationMain + 171
27 QR Code 0x000000010f5782bd main + 109
28 libdyld.dylib 0x0000000113dd192d start + 1)
libc++abi.dylib: terminating with uncaught exception of type NSException
Please do not call the Places API Web Services directly from a mobile device - it opens up the potential for external parties to steal your API key from your application. Please follow the Proxy Server pattern laid out in this tutorial by Ray Wenderlich's team.

Resources