PyObjc and Cocoa on Snow Leopard
Asked Answered
S

6

12

I am about to start my A-Level Computing project (High School Level) which will hopefully be a point-of-sale application for Mac OS. Unfortunately, Objective-C is a little out of my league at the moment and should I get stuck with it in the project I have no one to help out so I would fail the section of the course and not get into University. So this is quite important to me.

I want to use Python to develop a Cocoa app. I know that I need PyObjc, however all details on the net seem to assume it is pre-installed. Apparently this is the case with Leopard and Snow Leopard but I don't seem to have it on Snow Leopard and never noticed it on Leopard. Also, I have tried installing the latest beta of PyObjc by following the instructions on the Sourceforge page, but with no luck.

I would really appreciate it if anyone could shed some light on what needs to be installed, how, and links to any resources or tutorials that could help me.

Thanks in advance for the help!

Update: I see that this is a popular question, I just got the 'Notable Question' badge for it so I thought I would update anyone coming to this page on what I did after getting the answers.

Unfortunately, I wasn't able to use Python to create a Mac application. This was rather disappointing at the time, but probably a good thing. I made a Windows app in C# for my project, it was a tool for creating and running Assembly apps in a simulated environment. My course teacher has now started to use my tool to teach the course instead of his own! I got a very high score on the computing project (over 90%) and this contributed to me getting an A* in my computing A-Level (the highest grade available) and I consequently got in to Southampton University to study Computer Science.

This summer, I decided to make an iPad app (soon to be released) and I am glad to say that I know think I could make a Mac OS application in Objective-C as I feel I have learnt enough. I am glad that I took the time to learn it, it is a great language and really useful with iOS becoming so popular.

Sorry for all the boasting, but I am really happy about it. What I really want to say is, if you are coming to this page hoping to use PyObjc to create Mac apps easily, don't bother. It takes some time and some effort, but once you have learnt Objective-C, it is really satisfying to create apps with it. Good Luck!

Sedation answered 31/8, 2009 at 20:19 Comment(5)
Have you tried using macports to install PyObjC?Phocomelia
Have you installed the latest version of the developers tools? I haven't ever used PyObjc, but I don't think it will be any easier than using Objective-C. It's an easy language to learn and since the Mac OS X APIs were designed with it in mind they work very well with it. You can even use garbage collection if you don't want to worry about memory management, but the built-in reference counting is simple enough that I've never felt like using garbage collection. It's also something you should know if you want to continue Mac development.Pokeberry
Thanks for the reply, I will try using macports to install PyObjc, and I do have the latest Xcode 3.2, dev tools and SDKs. I have tried Objective-C and I have a book on it, but having only done basic programming in the past as a hobby and as a High School course, I have struggled with it. It seems a lot more difficult that C# .NET that I have done. Also, if I don't get the software working, there is a lot at stake and I don't know anyone that can help me if things go wrong. At least I have a friend that is a bit of a Python guru if I choose to use PyObjc.Sedation
That's good, but Python expertise ≠ PyObjC expertise. I have a friend (now at Amazon) that's probably the biggest Python expert I've known, but he was utterly stumped when it came to PyObjC and came to me for help. He might be able to help you design a Python back end, but don't expect him to know anything about interfacing with Cocoa. Good luck!Evin
PyObjC is installed by default on Snow Leopard, at least as part of the Xcode Tools. Make sure you've done that. Also, be wary of third-party sources of Python like Fink, MacPorts, and building it yourself, because those installations will not have PyObjC—if you install another Python, you would indeed need to install another PyObjC as well.Jeremiah
R
18

Allow me to echo what has already been said. I too am a student who just started a Cocoa development project, and at the beginning I thought "Well, I already know Python, I'll just use PyObjC and save myself from having to learn Objective-C, which looks beyond my grasp." I learned quickly that it can't be done. You can develop for OS X without learning Objective-C, but not without learning the Cocoa libraries, which constitute 99% of what you need to learn to write a Cocoa app in Objective-C. Objective-C itself isn't that hard; it's the Cocoa libraries that you need to invest in learning.

PyObjC basically uses Cocoa libraries and Python syntax. I gave up with it quickly and decided that if I was going to have to learn Cocoa, I may as well use Objective-C.

If you're looking to learn, Aaron Hillegass's book is a good place to start. Good luck!

Renee answered 31/8, 2009 at 22:0 Comment(6)
Ok, I won't post comments on all the questions, but let me say thanks to the support from everyone. I really appreciate it! I have installed the developer stuff from the disc already, but the PyObjc stuff isn't there in Xcode. The reason I am reluctant to use Objc is because if I get stuck there is possibly a Uni place at stake, and considering I want to study CS, I can't afford to not get an A in this work. Also, thanks to Koen! It is actually a POS app I am going to write and Checkout inspired me to use PyObjc. Thanks to everyone again, you have persuaded me to use pure Objc I think.Sedation
Oh, and I already have Aaron Hillegass' book, but the fact it includes the code for memory management scared me a little.Sedation
FYI, the biggest reason for us to write Checkout in Python was SQLAlchemy, a great ORM. I think if that wasn't the case, I would use Obj-C too.Casserole
As the maintainer of PyObjC for nearly 15 years, I will say it bluntly. Use Objective-C. You will need to know Objective-C to really understand Cocoa anyway and PyObjC is just going to add a layer of bugs & issues that are alien to 99% of Cocoa programmers.Vaulted
If you don't want to deal with the memory management, turn on garbage collection and either ignore the MM code in the Hillegass book, or include it in your program. If you have GC turned on, the MM code won't do anything.Renee
It certainly true. To learn Cocoa, you need to learn Objective-c. PyObjC might be a good solution to port a python application to osx; it would be good to know how to get started with PyObjC on Snow Leopard... E.g, Where are the xcode template for PyObjC. I remember them on Leopard (i think). I can't find them on Snow Leopard.Positron
E
7

You mean like Checkout? :-) I only mention it because Checkout is gorgeous and written with PyObjC...

Your concerns are valid, although probably not as much of a potential showstopper as you'd think. Using PyObjC still requires you to learn some Objective-C, and definitely requires you to understand at least some of the Cocoa frameworks, since you need to call into the Cocoa frameworks whenever you need to do some sort of Cocoa-specific task.

I recommend you read and consider the SO question "Why is the PyObjC documentation so bad?" and "PyObjc vs RubyCocoa for Mac development: Which is more mature?" before you completely convince yourself that "just PyObjC" will make things much easier. I refuse to disparage PyObjC because it is quite powerful and incredibly useful, but realize that nothing is a silver bullet, and no language or technology is best for all problems.

The Objective-C language is simple and pretty straightforward. The Cocoa frameworks generally dominate the learning curve for new Cocoa programmers. Plus, you have StackOverflow and lots of other resources to help answer your questions. (Judging by the activity of the "pyobjc" tag, you also stand a better chance of getting good Objective-C help on SO.)

Evin answered 31/8, 2009 at 21:0 Comment(0)
C
4

And as one of the Checkout developers I'll weigh in too (hi Quinn!). From what we've seen PyObjC runs fairly well on Snow Leopard. We've built one of the latest SVN revisions 2.2b with some customizations on Leopard and just moved over the site-packages folder.

Theoretically you should be able to use the built in Python/PyObjC (just do import objc, Foundation, AppKit) but as we ship/work with custom versions of both Python and PyObjC I'm not sure what the status exactly is. The mailing list doesn't mention a lot of people having issues (just a few) so that could be a good sign.

Good luck with the project, and if you have specific POS questions shoot me an email ;-)

Casserole answered 31/8, 2009 at 21:48 Comment(0)
K
3

I hardly use PyObjC myself, but I believe you need to run the Xcode installer on the Snow Leopard DVD in order to use PyObjC.

Also, as Quinn said, you will need to understand at least some Objective-C in order to use a Cocoa bridge like PyObjC without tearing your hair out. It just doesn't insulate you that completely.

Knitted answered 31/8, 2009 at 21:6 Comment(0)
S
3

I'm going to agree with Quinn here. Even if you're already proficient in Python, learning how to interface Python and Cocoa is not going to be any easier than learning Cocoa with Objective-C.

Objective-C is a simple, clean language that is quite easy to grok. Building the GUI and hooking it up to the back-end will be harder than learning the Objective-C to write the back-end, and building the GUI and hooking it up isn't that hard.

Follow the Cocoa app tutorial (you should be able to get through it in a day, or maybe a weekend if you go slow) and you'll be well on your way.

Scaramouch answered 31/8, 2009 at 21:41 Comment(0)
I
3

I'm a long time python developer who's been doing iPhone apps for awhile now (and only using my python knowledge to package up build files for the apps in run scripts), then who started making some PyObjC apps.

I'd have to say, PyObjC is pretty much STILL having to learn objective C (which I already know via iPhone dev), however you get several pretty cool benefits if you use it instead

  • Easy use of python libraries you know (faster for you)
  • Option to drop it and go to wxPython if styimied by Cocoa
  • Somewhat faster development time (you're writing less code, and the translation between the two languages is pretty darn easy to get used to).

Additionally, interface builder is a little tricky to get used to comparatively speaking, but if you're a python dev, it's not like you're exactly used to a functional gui builder anyhow :oP

Inofficious answered 15/12, 2009 at 5:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.