Nugroho's blog.

Monday, December 12, 2011

The Journey of Installing Matplotlib Python on Mac OS X Lion (continued)

To install Matplotlib, I have to install numpy first. To install numpy, I need GCC. Lion installer package didn't come with XCode, it has to be downloaded separately from MacAppStore for free. I don't dare to even trying it with my sluggish itnternet connection, so I tried others possibility without success untill I found my SnowLeopard DVD.

Finally, I am able to install GCC. I used XCode 3.2 on Snow Leopard DVD in Lion, :). So, the journey is continue…

Check (just for show off, :))



Nugrohos-MacBook-Pro:mysite nugroho$ gcc
gcc         gcc-4.0     gcc-4.2     gccmakedep  
Nugrohos-MacBook-Pro:mysite nugroho$ gcc

Now install numpy, oh no… look at this.

Last login: Sun Dec 11 19:11:11 from 192.168.2.2
Nugrohos-MacBook-Pro:mysite nugroho$ pip install numpy
Downloading/unpacking numpy
  Downloading numpy-1.6.1.tar.gz (2.6Mb): 2.6Mb downloaded
  Running setup.py egg_info for package numpy
    Running from numpy source directory.non-existing path in 'numpy/distutils': 'site.cfg'
    F2PY Version 2
    blas_opt_info:
      FOUND:
        extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
        define_macros = [('NO_ATLAS_INFO', 3)]
        extra_compile_args = ['-faltivec', '-I/System/Library/Frameworks/vecLib.framework/Headers']


    building extension "numpy.core._sort" sources
      adding 'build/src.macosx-10.6-intel-2.7/numpy/core/include/numpy/config.h' to sources.
      adding 'build/src.macosx-10.6-intel-2.7/numpy/core/
py/core/include/numpy/__multiarray_api.h']
    building extension "numpy.core.multiarray" sources
      adding 'build/src.macosx-10.6-intel-2.7/numpy/core/include/numpy/config.h' to sources.


error: could not delete '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__config__.py': Permission denied


It's look like my gcc think it's on Snow Leopard platform, :(. But, there is small hope; the error warning just mentions permission, hm, how about sudo?

ok, let's try again

Nugrohos-MacBook-Pro:mysite nugroho$ sudo pip install numpy
Password:
Downloading/unpacking numpy
  Running setup.py egg_info for package numpy
    Running from numpy source directory.non-existing path in 'numpy/distutils': 'site.cfg'


      adding 'build/scripts.macosx-10.6-intel-2.7/f2py' to scripts
    changing mode of /Library/Frameworks/Python.framework/Versions/2.7/bin/f2py to 755
Successfully installed numpy
Cleaning up...
Nugrohos-MacBook-Pro:mysite nugroho$ 


hm, still in doubt

Nugrohos-MacBook-Pro:mysite nugroho$ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> 

yeahh…
(don't know if it works as it compiled using GCC designed for Snow Leopard. At least no news is good news, :) )

So here it is

Nugrohos-MacBook-Pro:mysite nugroho$ pip install matplotlib
Downloading/unpacking matplotlib
  Downloading matplotlib-1.0.1.tar.gz (13.3Mb): 13.3Mb downloaded

BUILDING MATPLOTLIB
            matplotlib: 1.0.1
                python: 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
                        [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
              platform: darwin
REQUIRED DEPENDENCIES
                 numpy: 1.6.1
             freetype2: found, but unknown version (no pkg-config)
                        * WARNING: Could not find 'freetype2' headers in any
                        * of '.', './freetype2'.
OPTIONAL BACKEND DEPENDENCIES
                libpng: found, but unknown version (no pkg-config)
                        * Could not find 'libpng' headers in any of '.'
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /Users/nugroho/.pip/pip.log
Nugrohos-MacBook-Pro:mysite nugroho$ 

Hm, still long way to go, have to install freetype2 and lbpng. Ugh…






Tux and Beasty

Tux is Linux mascot while Beasty is FreeBSD mascot (have same pronounciation like BSD)

Sunday, December 11, 2011

Creating Django Apps on OS X Lion 10.7.2

As this is my first time using Django, I have to take care of some initial setup. Namely, I’ll need to auto-generate some code that establishes a Django project – a collection of settings for an instance of Django, including database configuration, Django-specific options and application-specific settings.


From the command line, cd into a directory where you’d like to store your code, I use my python directory,then run the following command:
django-admin.py startproject mysite
This will create a mysite directory in my python. Here tho result.
Nugrohos-MacBook-Pro:python nugroho$ pwd
/Users/nugroho/python
Nugrohos-MacBook-Pro:python nugroho$ ls
appender.py distribute-0.6.24.tar.gz graphy graphy.pyc
apprunner.py f.py graphy.py
Nugrohos-MacBook-Pro:python nugroho$ django-admin.py startproject mysite
Nugrohos-MacBook-Pro:python nugroho$ ls
appender.py distribute-0.6.24.tar.gz graphy graphy.pyc
apprunner.py f.py graphy.py mysite
Nugrohos-MacBook-Pro:python nugroho$ cd mysite/
Nugrohos-MacBook-Pro:mysite nugroho$ ls
__init__.py manage.py settings.py urls.py
Nugrohos-MacBook-Pro:mysite nugroho$
These files in mysite directory are:
__init__.py: An empty file that tells Python that this directory should be considered a Python package. (Read more about packages in the official Python docs if you're a Python beginner.)
manage.py: A command-line utility that lets you interact with this Django project in various ways. You can read all the details about manage.py in django-admin.py and manage.py.
settings.py: Settings/configuration for this Django project. Django settings will tell you all about how settings work.
urls.py: The URL declarations for this Django project; a "table of contents" of your Django-powered site. You can read more about URLs in URL dispatcher.
To verify that it works do this
Nugrohos-MacBook-Pro:mysite nugroho$ python manage.py runserver
Validating models...


0 errors found
Django version 1.3.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Yup, it works…
Try to access http://127.0.0.1:8000 with your browser, :)
Here screenshot from Safari on my Lion









From Blogsy Photos



If we want to show off on other computer, use command below. It will listen on all public IP's

Nugrohos-MacBook-Pro:mysite nugroho$ python manage.py runserver 0.0.0.0:8000
Validating models...


0 errors found
Django version 1.3.1, using settings 'mysite.settings'
Development server is running at http://0.0.0.0:8000/
Quit the server with CONTROL-C.


Here screenshot from my iPad

Django Python Module on OS X Lion 10.7.2

As python programmer, I wish I could build a web using it too. I used to use CMS based portal, but eventually I want python thing in my site. Fortunately, it can be done, using Django.

According it site, Django (https://www.djangoproject.com/) is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.

Developed by a fast-moving online-news operation, Django was designed to handle two challenges: the intensive deadlines of a newsroom and the stringent requirements of the experienced Web developers who wrote it. It lets you build high-performing, elegant Web applications quickly.

So I finally give it a try, it isn't hurt anyway, :). Installing Django in my Python 2.7 on my 13' Macbook Pro with OS X Lion 10.7.2 is fairly easy, using pip from pypi (pypi.python.org/). All I have to do is typing in terminal: pip install django. Of course, we need pip to be installed first.

Nugrohos-MacBook-Pro:python nugroho$ pip django
Usage: pip COMMAND [OPTIONS]


pip: error: No command by the name pip django
(maybe you meant "pip install django")
Nugrohos-MacBook-Pro:python nugroho$ pip install django
Downloading/unpacking django
Downloading Django-1.3.1.tar.gz (6.5Mb): 6.5Mb downloaded
Running setup.py egg_info for package django

Installing collected packages: django
Running setup.py install for django
changing mode of build/scripts-2.7/django-admin.py from 644 to 755

changing mode of /Library/Frameworks/Python.framework/Versions/2.7/bin/django-admin.py to 755
Successfully installed django
Cleaning up...
Nugrohos-MacBook-Pro:python nugroho$python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print django.get_version()
1.3.1
>>> exit()
Nugrohos-MacBook-Pro:python nugroho$

That's it.


Double Tap Dragging on Lion


I wrote about missing single-tap-hold on Lion to dragging. However, after googling around, I found that it's still has capability to do it, just you will find it at the most unpredictable place in System Preferences

To enable one finger drag by double-tap-hold, go to System Preferences, click on Universal Access, and then the Mouse & Trackpad tab. Click on the “Trackpad Options…” at the bottom section of window. Enable dragging option; we can select the desired dragging behaviour from the drop down list. I wonder why this preference is here, not on trackpad section instead.









From Blogsy Photos

Lion have more Finger Gesture than Snow Leopard


Migrating from Snow Leopard to Lion is confusing and annoying but fun experience. One feature of Lion that I noticed very much is new finger gesture as it's a whole different experience than Snow Leopard.



I noticed first bad feeling when I browsing through Safari and can't double-tap-hold todragging a text to highlight it. I think, oh my God, my trackpad is broken. Calming down, go to preferences panel. I can't find double tap option, hm. Drag n Drop now can be done by three finger, uh. Highlighting text using three finger seems wrong to me. So, no double-tap-hold. (edit: there is double-tap-hold )

Two finger gesture to scroll and zoom is intact. Hm, not really. Scroll direction now has default option to 'natural', iPad like scroll.

No Exposé or Space, just Mission Control. Mission Control contain apps on current active desktop, just like Exposé, and all full screen apps, including other desktop.

Sweeping down four finger now show windows from same apps while sweeping up bring us to Mission Control. Sweeping left or right will bring us to next full screen apps (Desktop's treated as fullscreen apps).

A new gesture is pinching with four finger; pinching down will bring up Launchpad, an apps list just like iOS. A reverse pinching, spread (not sure what it's named), will push all windows to side to show Desktop.

I'm a bit missing the time when I could switch apps by sweeping down my four finger. Moving apps through spaces has gone too, but I guess it's a sacrifice to be able jump too next step.

Operasi Vektor di Python


Di python terdapat operasi dot dan cross untuk array. Namun ketika saya terapkan, ternyata operasi tersebut bukan merupakan operasi vektor melainkan operasi untuk matrik. Mungkin saya yang kurang mempelajari lebih mendalam atau mungkin memang demikian sifat operasi tersebut, akhirnya saya mendefinisikan sendiri operasi dot dan cross untuk vektor menggunakan def (semacam implementasi python untuk function atau procedure).



Berikut adalah contoh perbandingan operasi vektor di python. Kode yang atas adalah operasi bawaan dari Python sedangkan yang bawah adalah operasi dot dan cross dengan definisi yang baru

from numpy import *
from numpy.linalg import *
a=array((4,5,7),float)
b=array((2,3,4),float)
c=array((1,2,3),float)
print 'axb',a*b
print 'bxa',b*a
print 'dot(a,b)',dot(a,b)
print 'c.(axb)',dot(c,(a*b))
print '(bxa).c',dot((b*a),c)
print 'ax(bxc)',a*(b*c)
print '(axb)xc',(a*b)*c
print '(a.c)b-(a.b)c',(dot(a,c)*b)-(dot(a,b)*c)
print 'a=',a,'2a=',2*a
d=7*a+11*b
print 'd',d

def cross(v, w):
x = v[1]*w[2] - v[2]*w[1]
y = v[2]*w[0] - v[0]*w[2]
z = v[0]*w[1] - v[1]*w[0]
return (x, y, z)

def dott(v, w):
return v[0]*w[0] + v[1]*w[1] + v[2]*w[2]

print 'axb',cross(a,b)
print 'bxa',cross(b,a)
print 'dot(a,b)',dott(a,b)
print 'c.(axb)',dott(c,cross(a,b))
print '(bxa).c',dott(cross(b,a),c)
print 'ax(bxc)',cross(a,cross(b,c))
print '(axb)xc',cross(cross(a,b),c)
print '(a.c)b-(a.b)c',((dott(a,c)*b)-(dot(a,b)*c))
print 'a=',a,'2a=',2*a
print '(axb)x(cxb)=b[b.(cxa)]'
print cross(cross(a,b),cross(c,b))
print b*(dott(b,cross(c,a)))


323f (5) amp (1) android (12) apple (7) arduino (18) art (1) assembler (21) astina (4) ATTiny (23) blackberry (4) camera (3) canon (2) cerita (2) computer (106) crazyness (11) debian (1) delphi (39) diary (286) flash (8) fortran (6) freebsd (6) google apps script (8) guitar (2) HTML5 (10) IFTTT (7) Instagram (7) internet (12) iOS (5) iPad (6) iPhone (5) java (1) javascript (1) keynote (2) LaTeX (6) lazarus (1) linux (29) lion (15) mac (28) macbook air (8) macbook pro (3) macOS (1) Math (3) mathematica (1) maverick (6) mazda (4) microcontroler (35) mountain lion (2) music (37) netbook (1) nugnux (6) os x (36) php (1) Physicist (29) Picture (3) programming (189) Python (109) S2 (13) software (7) Soliloquy (125) Ubuntu (5) unix (4) Video (8) wayang (3) yosemite (3)