I am attempting to build a python application with binary modules on OS X. I want to build versions for Snow Leopard and Leopard from Lion. I have XCode 4 installed with the 10.5 and 10.6 sdks and have been attempting to build using the MACOSX_DEPLOYMENT_TARGET flag set to 10.6. I receive an error from distutils complaining that python was built with a different deployment target.
I tried building a separate python binary with the deployment target set to 10.6 and then used virtualenv to try to build from that, but virtualenv expected a lib directory under the base env directory that was not there.
I am a total newb at developing on Mac and not even sure if what I want to do is possible. Am I going to have to break down and have someone still running Snow Leopard build my distributions?
I really appreciate any assistance.
The system Pythons shipped by Apple in OS X 10.7 are built for 10.7 only. The simplest solution is to download the most recent Python 2.7 or 3.2 64-bit/32-bit installer from python.org and use it since it is a universal binary that will run on either 10.6 or 10.7. If you are making an app bundle, you'll need to install a copy of py2app for it and any other 3rd-party packages like Distribute (aka easy_install) or pip.
I found the solution, go into your /System/Library/Frameworks/Python.framework/Versions/2.7/lib/distutils/sysconfig.py
Goto line 408 that says "raise DistutilsPlatformError" and add a '#' to comment out that line of code... This will "unleash the python"
You are basically telling python "don't worry its not 10.7, I know" there could be some crashes as a result but I think otherwise. My very complex python applicaiton now compiles on MacOSX 10.8 with no troubles and it seems to do the job, QA still has to test it though.
Related
I am running a MacBook Pro with 8gb of memory and a 2.5GHz processor. I run OS X Mavericks, but this problem has happened on other operating systems as well. when I try to open the editor, or even open a python file, this happens:
This has been a problem since I got into python. I have tried as many versions as I can, and the same screen pops up. Please help
I recently also upgraded a friends iMac to OS X 10.9 Mavericks and her Python to 2.7.6. If you mount the python-2.7.6-macosx10.6.dmg disk image there's a text file named ReadMe.txt. If you ahem, actually read it, right near the beginning it says:
**** IMPORTANT ****
Update your version of Tcl/Tk to use IDLE or other Tk applications
To use IDLE or other programs that use the Tkinter graphical user
interface toolkit, you may need to install a newer third-party version
of the Tcl/Tk frameworks. Visit
http://www.python.org/download/mac/tcltk/ for current information
about supported and recommended versions of Tcl/Tk for this version of
Python and of Mac OS X.
Here's what http://www.python.org/download/mac/tcltk currently looks like (my highlighting):
To summarize: You need to download and install ActiveTcl 8.5.15.1 (which is mislabeled ActiveTcl 8.5.15.0) from ActiveState's webpage. After doing that you should be able to run IDLE:
I haven't actually tried to do it yet, but from what I read it sounds like the same process applies to Python 3.3.3 and its IDLE app.
I was having the exact same problem.
I was finally able to install Python (and IDLE) via MacPorts by also installing a package called "pyXX-tkinter" -- where XX is the version, e.g. py34-tkinter for Python 3.4.
I am sure on my Mac 0SX 10.9 I have more than one version of Python 2.7.5.
When I type in
which python
in the terminal, I get /Library/Frameworks/Python.framework/Versions/2.7/bin/python
When I am doing a pip.install it seems those are loading in a different path, they are all under /Library/Python/2.7/site-packages.
When I am in IDLE or my IDE (Sypder) and type
import sys
print sys.path
I get lots and lots of paths that start with /Library/Python/2.7/site-packages.
My problem is when I do a help() or import() on one of the modules I can see in /Library/Python/2.7/site-packages, I get a NameError: name 'Module' is not defined. Examples that I can see loaded in .../site.packages are pandas, nympy, and PyMySQL. But all give me "name of module not found".
Ideal python distribution control on a Mac: use a (free) scientific python environment like Enthought or Anaconda, and use either the real virtualenv package or the provided virtualenv package to control 'virtual environments' in which you can install packages. Virtualenvs really help keep the python distribution clean.
Good Luck.
Python development on a Mac can be a pain in the butt. That's why I set up a Arch Linux through Virtual Box and I'm quite happy with it. However, iOS development with Python using Kivy requires XCode (as far as I know) to deploy the apps on the iOS devices. So I'm in the same boot as you are.
Long story short: Running brew doctor (as in homebrew) in the terminal helped me a lot cleaning up my Python installations on the Mac.
This has been a recurring, strange issue for me when accessing URLs using py-appscript, first in Safari and now in Chrome.
Whenever I run the script command to get the current URL in the terminal, for example,
appscript.app("Google Chrome").windows.active_tab.URL()
a bouncing instance of the "Python" application appears in the Dock. I have verified that this "Python" application is found in:
/Library/Frameworks/Python.framework/Versions/2.6/Resources
How do I get the current URL without this thing popping up?
The background on this problem is explained here by the author of appscript. Assuming you are on OS X 10.5 or higher, the solution is to use a Python that has been built using a minimum deployment target of 10.5 or higher. From the path you supplied, it appears likely you are using a Python 2.6 from a python.org installer. Traditionally, python.org Pythons are built to run on multiple versions from 10.3 on up and so appscript running under it will show this problem. Starting with Python 2.7 (and additionally soon with Python 3.2), python.org is providing a second installer variant, one that only runs on OS X 10.6 or higher. Those variants should not have the bouncing icon problem. Other options are to install a Python 2.6 using MacPorts, Fink, or HomeBrew or build it yourself (a little tricky to get all the batteries included). Or, if you are on OS X 10.6, you can use the Python 2.6 supplied by Apple in /usr/bin.
I'm trying to compile a variety of python extensions (pycrypto, paramiko, subvertpy...) on Mac OS X 10.6, such that they will be compatible with Mac OS X 10.5 and its built-in python 2.5, for including in a product installer targetted at Mac OS X 10.5.
I'm really not sure how to go about this. I dug around on Google and found a question here on stackoverflow, which led me to setting MACOSX_DEPLOYMENT_TARGET=10.5 in my environment before building, but that just gave me the error:
distutils.errors.DistutilsPlatformError: $MACOSX_DEPLOYMENT_TARGET mismatch: now "10.5" but "10.6" during configure
I am using python2.5 on Mac OS X 10.6 to run the builds, for example:
$ python2.5 setup.py install
I also came across references to /Developer/SDKs/MacOSX10.5.sdk but I'm not really sure how to make use of it.
I managed to get distutils to believe that Python was built on Leopard, by inserting the following code before the call to setup() in setup.py:
# XXXHACK: make distutils believe that Python was built on Leopard.
from distutils import sysconfig
their_parse_makefile = sysconfig.parse_makefile
def my_parse_makefile(filename, g):
their_parse_makefile(filename, g)
g['MACOSX_DEPLOYMENT_TARGET'] = '10.5'
sysconfig.parse_makefile = my_parse_makefile
Then pycrypto builds well on Snow Leopard, using python2.5, after setting MACOSX_DEPLOYMENT_TARGET to "10.5". I can't guarantee it will work well but pycrypto's bundled test suite passed with this build on my Macbook Air running Leopard, so it seems OK.
I want to get started trying to develop a few simple applications with PyObjC. I installed PyObjC and the Xcode templates. I know that PyObjC itself works, since I've run this script successfully. When I tried to create a project from the Cocoa-Python Application template and ran it, I got this error:
Traceback (most recent call last):
File "main.py", line 10, in
import objc
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyObjC/objc/__init__.py", line 25, in
from _convenience import *
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyObjC/objc/_convenience.py", line 21, in
from itertools import imap
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/itertools.so, 2): no suitable image found. Did find:
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/itertools.so: mach-o, but wrong architecture
2010-02-08 19:40:09.280 TestApplication[3229:a0f] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '/Users/icktoofay/Desktop/TestApplication/main.m:44 main() PyRun_SimpleFile failed with file '/Users/icktoofay/Desktop/TestApplication/build/Debug/TestApplication.app/Contents/Resources/main.py'. See console for errors.'
When I tried opening a normal Python prompt and importing itertools, there was no error. I'm using Python 2.6.4 from MacPorts on Mac OS X 10.6 Snow Leopard.
I'd appreciate any help.
You have a 32-bit vs 64-bit problem. It appears you are using a Python 2.6 installed from MacPorts and apparently it was not a universal (32-bit/64-bit) build. Either your app is running as 64-bit and the Python is only 32-bit or the reverse. You can check by using file:
cd /opt/local/Library/Frameworks/Python.framework/Versions/2.6/
cd lib/python2.6/lib-dynload/
file itertools.so
itertools.so: Mach-O universal binary with 2 architectures
itertools.so (for architecture x86_64): Mach-O 64-bit bundle x86_64
itertools.so (for architecture i386): Mach-O bundle i386
The easiest fix is likely to re-install the MacPorts Python and the additional packages you installed like PyObjC:
sudo port selfupdate
sudo port -u install python26 +universal ...
EDIT: Since you report that the Python is 64-bit, the problem then is almost certainly due to a problem with the Xcode template setup for your Python PyObjC project. The startup code is probably loading the Apple-supplied Python interpreter which is universal. You can check by adding something like this prior to the import objc:
import sys
sys.stderr.write(sys.executable)
For MacPorts, it should be
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
I'm not familiar enough with the ins-and-outs of using the templates under Xcode to know what might need to be changed and I doubt that many people use them with a MacPorts Python, especially under 10.6.
Another thought, the Apple-suppied Python 2.6.1 comes with a version of PyObjC already installed. Perhaps using it would be simpler. Or don't use Xcode and use py2app or another solution to run it.