Is it possible to use Cocoa API with Python? - python

I was wondering if it is possible to use Cocoa (Apple's API) with Python, so being able to run any code like in this link, so NSWorkspace functions and so on, this might be a super stupid question, but I was still wondering if it was possible...

Yes.
There are Python packages, kind of wrappers around Objective-C, install them like:
$ pip install pyobjc-core
$ pip pyobjc-framework-Cocoa
$ pip pyobjc-framework-Quartz
https://pypi.org/project/pyobjc-framework-Cocoa/

MacOS by default comes with python 2.7 and pyObjC 2.5, and has done for years. If you want a newer version of either python, such as python 3, or the newest version of pyObjC, then you have to install it yourself.
The latest version of pyObjC is 5.2.
However, on a default installation of MacOS from at least Snow Leopard onward, the following should work:
python
>>> import Appkit
>>> AppKit.NSWorkspace.sharedWorkspace().runningApplications()
Catalina is stated to be the last version to contain python bundled.

Related

Installing Python packages with 64 bit Windows and Python 3.3

I've read that there's a nice text-to-speech package called pyttsx that can be included in my Python scripts. As soon as I try to install pyttsx things start falling apart fast. pyttsx is for Python 2.6 (2.7 maybe?) not 3.3. I have 2.7 and 3.3 (also Portable Python 2.7 and 3.2) installed but I can't get setuptools or easy_install to work. I got distribute partly installed but I'm might have seen some errors at the end of its installation so I'm not sure it's working and it won't install pyttsx anyway. There's a Windows .exe program that will let you install Python packages but it won't work for 64-bit Python. I've been searching for answers for days can can't come up with anything specific enough.
How do I install Python packages with 64-bit Python 3.3 on 64-bit Windows 7, or is that even possible?
Best source ever!
this man is a wicked fellow.
With distribute installed, launch the python.exe you want to use.
From within python interactive, run the following code:
from setuptools.command import easy_install
easy_install.main(["-U", "package"])
Substitute "package" for whatever you wish to install.

Python Versions on Mac

I'm working on Mac Os 10.7 (Lion) and I have some questions:
What is the pre-installed version of python on Lion?
I've been working on this computer for some time now, and i've installed lots of software in order to do college work many times I didn't know what I was really doing. The thing is: now I hava on the /Library/Frameworks/Python.framework/Versions/ a folder called "7.0" I'm pretty sure there no python version 7. Is this folder native or a third-part program installation. Can I delete it? (it's using 1 Gb on disk).
Where is located the original python that comes with mac os?
I've choose Homebrew as my package manager, is there a easy way to manage python versions with it?
Lion uses Python 2.7 by default; 2.5 and 2.6 are also available.
/Library/Frameworks/Python.framework does not exist on a stock install of Lion. My guess is that you've ended up with this by installing some application.
The default Python install is primarily installed in /System/Library/Frameworks/Python.framework, although some components are located elsewhere.
Yes - you can brew install python#2 to get a Python 2.7 separate from the system version, or brew install python to get Python 3.7. Both will install to /usr/local, like any other Homebrew recipe.
I think that is Python 2.7 but you can check typing python on a command terminal. It will tell you the version.
I couldn't tell that you can deleting it, because I don't know what it has... can you give more info about it?
Just type "which python" and it will tell you
You should use virtualenv and pip: http://jontourage.com/2011/02/09/virtualenv-pip-basics/

using python 2.6?

i have no way of upgrade to python 2.7 or 3.1 so i am stuck with python 2.6 on my ubuntu 10.04 machine.
will i still be able to find host that supports python 2.6?
is using python 2.6 still consider outdated or bad practice?
2.6 will be around for a long time. There are many machines that still run even 2.4, so you're fine.
Python 2.6 will probably still be around for a while, as Python 2.7 was released only a few months ago.
You can always use from __future__ import ... to make use of some of the newer features from Python 3.x
will i still be able to find host that
supports python 2.6?
Yes. No problems whatsoever.
is using python 2.6 still consider
outdated or bad practice?
No, it is not.
However:
I have no way of upgrade to python 2.7
Yes you do. You download the source code from www.python.org and install it.
What you should be careful to do in not to overwrite the system Python.
Install it either with "altinstall" (will not override the system python) or even better,
use a custom prefix. For example:
$ ./configure --prefix = /opt/python27
$ make
$ sudo make install
It is often a good idea to use a separate Python install for development, as you can do whatever you want with it including deleting it and reinstalling it without affecting the system Python.
You are NOT stuck. :)
I'm Using Ubuntu 10.04 as well I have Python 2.3.7, 2.4.6, 2.5.5, 2.6.6, 2.7.1, 3.0.1, 3.1.2 and 3.2b2+ installed. No problems. Yes, I use all of them, even though it's mostly 2.4 and 2.6.
Python3.1 is in the repositories for 10.04
$ apt-cache show python3
Package: python3
Priority: optional
Section: python
Installed-Size: 76
Maintainer: Ubuntu Developers <ubuntu-devel-discuss#lists.ubuntu.com>
Original-Maintainer: Matthias Klose <doko#debian.org>
Architecture: all
Source: python3-defaults
Version: 3.1.2-0ubuntu1
Depends: python3.1 (>= 3.1.2), python3-minimal (= 3.1.2-0ubuntu1)
Suggests: python3-doc (>= 3.1.2-0ubuntu1), python3-tk (>= 3.1.2-0ubuntu1), python3-profiler (>= 3.1.2-0ubuntu1)
Filename: pool/main/p/python3-defaults/python3_3.1.2-0ubuntu1_all.deb
Size: 11096
MD5sum: 81f3f3bf790f5d7756b76c8d92fcea86
SHA1: 32e12dc7f9500456e063f22645c1cfed76b8845c
SHA256: 0f541352ace2fcf1929a93320ffbe2f1de4e1d140bbe70a7c5a709403b73341c
Description: An interactive high-level object-oriented language (default python3 version)
Python, the high-level, interactive object oriented language,
includes an extensive class library with lots of goodies for
network programming, system administration, sounds and graphics.
.
This package is a dependency package, which depends on Debian's default
Python version (currently v3.1).
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 3y

Python2.6 Backtrack/Ubuntu wxPython

I wrote a python app and it needs python2.6. I'm trying to get it to run in Backtrack 4 which is a pen-testing linux distro based on debian/ubuntu. I'v managed to install python2.6 along side of python2.5. Now I'm trying to install wxPython for 2.6 from the repos but I can't get it to install it for python2.6 rather than 2.5. Is there some way i can set a flag to specify what python installation to target? Or do I just need to install it from source?
There is pre-built version of python, wxwidgets, wxpython in ubuntu packages.
You don't need to build from the sources(unless you have special reasons), you can install it from the following links.
http://packages.ubuntu.com/jaunty/python2.6
http://packages.ubuntu.com/jaunty/libwxgtk2.8-0
http://packages.ubuntu.com/jaunty/python-wxgtk2.8
And also wxPython 2.8 is recommended, you still can find 2.6 though.

Install PyObjC on Python 2.6 on OS X 10.5?

OS X 10.5.8 came with Python 2.5, and had PyObjC already installed.
I installed Python 2.6 from the python.org site, and PyObjC isn't there.
I can't find a download to install PyObjC on my Python 2.6 install. Is checking out the PyObjC trunk and trying to build it my only choice? Will that work "out of the box"?
Apple includes PyObjC with their Pythons that come with OS X 10.5 and 10.6. It is not part of the python.org installers. But it should be easy enough to install. Just install setuptools to the python.org python 2.6 following the instructions here. Then use easy_install-2.6 (which will have been installed in /Library/Frameworks/Python.framework/Versions/2.6/bin and may already be on your $PATH) to do:
easy_install-2.6 pyobjc==2.2b2
as described here. If you want to live on the bleeding edge, you could try installing directly from the svn repository as there has been a lot of work recently, primarily in support of 10.6.
If that seems like too much work, you could install an older version and all dependencies including python via MacPorts:
sudo port install py26-pyobjc2
You should probably try to build PyObjC from trunk, which will work fine on the official Python 2.6 distribution, but not on Python 2.5. There are quite a lot of fixes in the trunk right now that weren't in 2.2b2, which afaik. is the most current version available through easy_install.
There are some little snags that you may run into when building with py2app on 10.5 + 2.6 + PyObjC 2.2 (which for a lot of reasons is what you should probably do, instead of using the Xcode templates from 10.5 that build differently), especially if you still have Python 2.5 installed somewhere, so you'll probably want to build and install py2app from trunk as well, this particular issue I ran into with PyObjC 2.2 on 2.6 on 10.5 has been fixed by now.
If your goal is to write software that will work on other people's computers, you shouldn't touch the default Python installation. If you simply cannot live without 2.6, then you're responsible for re-creating everything on your own, and that's not going to be a point-and-click process by any means.

Categories

Resources