Python REPL Enhancement
This tip comes from here.
You can get tab completion and command history similar to that available in bash itself by creating registering a start up script for python. Create the following as ~/.pythonstartup
# python startup file
import readline
import rlcompleter
import atexit
import os
# tab completion
readline.parse_and_bind('tab: complete')
# history file
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
Then add the following to you ~/.bash_profile
export PYTHONSTARTUP=~/.pythonstartup
Now you can use tab to autocomplete and use tab-tab to show suggestions:
geoffs-mac:~ geoff$ python Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import pygame >>> pygame.display. <-- I pressed tab here after pyg and the after .dis, but you can't see itpygame.display.Info pygame.display.get_caption pygame.display._PYGAME_C_API pygame.display.get_driver pygame.display.__PYGAMEinit__ pygame.display.get_init ... and more ...
You can also use the up and down arrows to cycle through previous commands, including those from previous sessions.
Pygame on OS X Leopard
Skip to successful instructions
Tonight I wanted to start a new Pygame project to learn basic game development. I thought this would be rather easy, but apparently I’m not the only one who has had trouble.
Attempt 1 – Macports
Reading the Pygame download page I notice that it mentioned Macports. So I fired up Terminal, typed in sudo port install py-game and then waited about 5 mins for it to download and build everything.
Time to try it out.
geoffs-mac:~ geoff$ python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named pygame
Not cool. A little bit of searching and I found that for some reason Macports installed pygame under /opt/local/lib/python2.4/site-packages/pygame. This might be good if you use the Macports python but clearly not suitable for the default pre-installed Python 2.5.
As a last ditch effort to use the Macport Pygame I tried copying the /opt/local/lib/python2.4/site-packages/pygame into /Library/Python/2.5/site-packages which resulted in a whole heap of Python C API version mismatch warnings.
Oh well, rm -rf /Library/Python/2.5/site-packages/pygame
Attempt 2
Ok, time to try the pre-compiled installers.
I downloaded the OS X 10.5 installer from the Pygame downloads. However when I ran it, on the select destination screen it kept telling me that my startup volume was not acceptable as “System Python 2.5 is required”. Yet python was clearly running Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
I installed the Python package linked to on this page. I’m not sure what the package does that the default Python didn’t, but others were recommending it worked for me as well.
Then I ran the Pygame installer again and all was good. That is, until I tried importing pygame again.
geoffs-mac:~ geoff$ python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/__init__.py", line 37, in
_check_darwin()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/__init__.py", line 34, in _check_darwin
raise ImportError("PyObjC 1.2 or later is required to use pygame on Mac OS X. http://pygame.org/wiki/PyObjC")
ImportError: PyObjC 1.2 or later is required to use pygame on Mac OS X. http://pygame.org/wiki/PyObjC
>>>
So back to the Pygame downloads page to grab pyobjc-1.4-py2.5-macosx10.4.mpkg.zip. Don’t be put of by the 10.4 in the filename – this is the one you want. The installer completed without troubles, and I could finally import pygame properly.
The Instructions
Without the waffle.
- Download and install python-2.5-macosx.dmg
- Download and install pyobjc-1.4-py2.5-macosx10.4.mpkg.zip
- Download and install pygame-1.8.1release-py2.5-macosx10.5.zip
- Test it in Terminal:
geoffs-mac:~ geoff$ python Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import pygame >>>
What should have been five minutes, was more than 30 minutes of hassle. Now, time to start writing my game.
Git on OS X
Git is a fantastic DVCS with a flexible approach to workflow.
Today I went through the process of installing it on OS X Leopard using Macports. I know that there is an OS X installer available, but I love apt-get on Ubuntu and the simple way it lets you manage your packages. Macports has a similar approach to package management.
Getting Macports.
Download the latest Macports binary installer. After running the install run:
sudo port -v selfupdate
This will ensure that Macports has updated itself and all its dowwnload and package sources.
Getting Git
Simply run
sudo port install git-core
For most people this should be all that is needed. Simply sit back and wait a good few minutes, and then you can start gitting.
However I ran into a small issue with the following error:
Error: Target org.macports.activate returned: Image error:
/opt/local/lib/perl5/5.8.9/darwin-2level/auto/List/Util/Util.bs is being used by the
active perl5.8 port. Please deactivate this port first, or use the -f flag to force the
activation.
It appears that both the Perl 5.8 installation and the p5-scalar-list-utils package are both wanting to use the same file.
The solution is to deactivate the Perl package, install the p5 package, and then force reactivate the Perl package, using the -f flag.
geoffs-mac:~ geoff$ sudo port deactivate perl5.8
---> Deactivating perl5.8
geoffs-mac:~ geoff$ sudo port install p5-scalar-list-utils
---> Activating p5-scalar-list-utils @1.19_1
---> Cleaning p5-scalar-list-utils
geoffs-mac:~ geoff$ sudo port activate -f perl5.8
---> Activating perl5.8
Warning: File /opt/local/lib/perl5/5.8.9/darwin-2level/auto/List/Util/Util.bs already exists.
... a number of other warnings ...
geoffs-mac:~ geoff$ sudo port install git-core
...
---> Activating git-core @1.6.1_1+doc
---> Cleaning git-core
geoffs-mac:~ geoff$