Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 21st, 2012  |  syntax: None  |  size: 10.06 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. =================================
  2. OSX Developer System installation
  3. =================================
  4.  
  5. This guide assumes a fresh install of Mac OSX 10.7 Lion.
  6.  
  7.  
  8. Homebrew
  9. ========
  10.  
  11. Follow https://github.com/mxcl/homebrew/wiki/installation to get the basic setup up and running.
  12. (the default, not the alternate installs).
  13.  
  14. Don't forget to install the requirements (Xcode, X11, Java Developer Update) mentioned in the installation guide.
  15.  
  16. Please note the recommendations below.
  17.  
  18.  
  19. Dedicated ``brew`` user
  20. -----------------------
  21.  
  22. Installing as root is not recommended by the homebrew authors. But I hate nothing more than accidentally installing a
  23. python package globally when I forget activating a virtualenv. To prevent this I decided to create a dedicated user
  24. called ``brew`` who has control over ``/usr/local/``. So for everything brew related and to install global
  25. python/ruby/whatever packages it is necessary to ``su`` to ``brew``: ``sudo su - brew``.
  26.  
  27.  
  28. python and stuff
  29. ================
  30.  
  31. See https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python and
  32. https://github.com/mxcl/homebrew/wiki/Gems%2C-Eggs-and-Perl-Modules for details.
  33.  
  34. the basics::
  35.  
  36.     brew install python
  37.     /usr/local/share/python/easy_install pip
  38.     /usr/local/share/python/pip install --upgrade distribute
  39.  
  40. `homebrew`_ sets things up so that all packages installed via ``python setup.py install``, ``easy_install`` or ``pip``
  41. get their commands installed to ``/usr/local/share/python/`` by default (see the above link for an explanation). So the
  42. first rule of business is to add that path to your ``PATH``. Also if you want to use your homebrew python (and other
  43. homebrew stuff) by default, ``/usr/local/bin`` should be all the way at the front of your ``PATH``.
  44. If you decided to make a dedicated ``brew`` user, do this for this user as well.
  45.  
  46. ``~/.bash_profile`` or ``~/.profile`` (I recommend ``.profile`` because it works in ``bash`` and ``zsh``::
  47.  
  48.     PATH=/usr/local/bin:/usr/local/share/python:$PATH
  49.     export PATH
  50.  
  51. .. NOTE::
  52.    remember to open a new terminal or call ``source ~/.bash_profile`` in all of your open terminal windows to get
  53.    ``PATH`` updated.
  54.  
  55. Before installing stuff with pip, make sure the above ``PATH`` changes worked and you are using the correct version.::
  56.  
  57.     pip --version
  58.  
  59. should return something like (a path with ``/usr/local/``)::
  60.  
  61.     pip 1.1 from /usr/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg (python 2.7)
  62.  
  63.  
  64. PIL
  65. ---
  66.  
  67. install some dependencies::
  68.    
  69.     brew install libjpeg
  70.     brew install lcms
  71.     brew install libtiff
  72.  
  73. If you don't need FREETYPE support, the regular ``pip install PIL`` will work. There is no real need to install PIL
  74. globally then.
  75.  
  76. If you need FREETYPE, choose one of these three options. I recommend `PIL with patching setup.py`_:
  77.  
  78.  
  79. .. _PIL with patching setup.py:
  80.  
  81. PIL with patching setup.py
  82. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  83.  
  84. Since `PIL`_ is not packaged correctly, setup.py needs to be tweaked.
  85.  
  86. Use the newest source version of PIL from http://www.pythonware.com/products/pil/ , download, upack and edit
  87. ``FREETYPE_ROOT = ("/usr/x11/lib","/usr/x11/include",)`` in ``setup.py``. Then::
  88.  
  89.     python setup.py build_ext -i
  90.     python setup.py install
  91.  
  92. This method has the advantage, that other packages that have `PIL`_ as a dependency will detect that it is already
  93. installed.
  94.  
  95.  
  96. Pillow
  97. ^^^^^^
  98.  
  99. Pillow is an alternative Distribution of PIL::
  100.  
  101.     pip install Pillow
  102.  
  103. Pillow does a great job of finding all the dependencies it needs in OSX. But it sucks a bit if an other packages list
  104. PIL as a dependency, because Pillow will not be recognized as a valid PIL installation and PIL will be installed again.
  105.  
  106.  
  107. PIL globally with homebrew
  108. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  109.  
  110. Homebrew has a formula for PIL::
  111.  
  112.     brew install pil
  113.  
  114. .. ATTENTION::
  115.    This may produce the dreaded ``AccessInit: hash collision: 3 for both 1 and 1`` error if some apps import PIL
  116.    as ``from PIL import Image`` and others as ``import Image``.
  117.  
  118.  
  119. PIL compatibility
  120. -----------------
  121.  
  122. Some python packages don't work when PIL is installed with the ``PIL`` prefix. Add a ``PIL.pth`` file in
  123. ``/usr/local/lib/python2.7/site-packages/PIL.pth`` containing the string ``PIL``. Now both ``from PIL import Image`` and
  124. ``import Image`` will work.
  125.  
  126. This oneliner will do exactly that::
  127.  
  128.     echo "PIL" > /usr/local/lib/python2.7/site-packages/PIL.pth
  129.  
  130.  
  131. Aggdraw
  132. -------
  133.  
  134. `aggdraw`_ provides much better anti-aliasing than `PIL`_ . And lots of other stuff.
  135.  
  136. use this version: http://bitbucket.org/2degrees/aggdraw-64bits/src
  137.  
  138. this needs `mercurial`_ to be installed (``pip install mercurial``) ::
  139.    
  140.     mkdir ~/tmp
  141.     cd ~/tmp
  142.     hg clone https://stefanfoulis@bitbucket.org/2degrees/aggdraw-64bits
  143.     cd aggdraw-64bits
  144.     /usr/local/bin/python setup.py build_ext -i
  145.     /usr/local/bin/python setup.py install
  146.    
  147. Enabling freetype does not work for me. Please share if you find a way :-)
  148.  
  149.  
  150. Other graphics related stuff
  151. ----------------------------
  152.  
  153. ::
  154.  
  155.     brew install ghostscript
  156.     brew install imagemagick
  157.     # barcode (qrcode and others) reading lib
  158.     brew install zbar
  159.     pip install zbar
  160.  
  161.  
  162. MySQL
  163. =====
  164.  
  165. server::
  166.  
  167.     brew install mysql
  168.     # look at the instructions brew prints after installation. this is the short version:
  169.     unset TMPDIR
  170.     mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
  171.     mkdir -p ~/Library/LaunchAgents
  172.     cp /usr/local/Cellar/mysql/5.5.14/com.mysql.mysqld.plist ~/Library/LaunchAgents/
  173.     launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
  174.     # set a root password
  175.     /usr/local/Cellar/mysql/5.5.20/bin/mysqladmin -u root password 'new_password'
  176.  
  177. client::
  178.  
  179.     brew install mysql-connector-c
  180.  
  181. On my machine brew did not link ``mysql_client`` in ``/usr/local/bin``, so I had to do it manually. This is probably a bug homebrew and is likely to be fixed soon.::
  182.  
  183.     cd /usr/local/bin
  184.     ln -x ../Cellar/mysql/<mysql-version>/bin/mysql_config ./
  185.     pip install mysql-python
  186.  
  187.  
  188. Postgres
  189. ========
  190.  
  191. server::
  192.  
  193.     PYTHON=/usr/local/bin/python  brew install postgresql
  194.     # look at the instructions brew prints after installation. this is the short version:
  195.     initdb /usr/local/var/postgres
  196.     mkdir -p ~/Library/LaunchAgents
  197.     cp /usr/local/Cellar/postgresql/9.1.3/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
  198.     launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  199.     createuser # create the initial postgres user
  200.  
  201. python client bindings (does not work without the server)::
  202.  
  203.     pip install psycopg2
  204.  
  205.  
  206. postgis / geodjango
  207. -------------------
  208.  
  209. packages::
  210.  
  211.     brew install postgis # this will handle installing postgres, geos, proj4, and postgis
  212.     pip install numpy
  213.     brew install gdal
  214.  
  215. creating a spatially-enabled database template::
  216.  
  217.     createdb template_postgis # create a standard postgres db
  218.     createlang plpgsql template_postgis # enable the PL/pgSQL PostGIS functions
  219.     psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/postgis.sql
  220.     psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/spatial_ref_sys.sql
  221.  
  222. Creating a new database based on ``template_postgis``::
  223.  
  224.     createdb -T template_postgis [yourdatabase]
  225.  
  226. Alternatively it is possible to enable spatial functions on a existing databases by calling the above commands for
  227. creating ``template_postgis`` (except ``createdb``, of course). Just use your existing database name instead of
  228. ``template_postgis``.
  229.  
  230.  
  231. solr
  232. ====
  233.  
  234. ::
  235.  
  236.     brew install solr
  237.  
  238.  
  239. MongoDB
  240. =======
  241.  
  242.     brew install mongodb
  243.     # look at the instructions brew prints after installation. this is the short version:
  244.     cp /usr/local/Cellar/mongodb/1.8.2-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents/
  245.     launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
  246.  
  247. Mongohub (http://mongohub.todayclose.com/) is an awesome OSX ui for mongodb.
  248.  
  249.  
  250. Other useful tools
  251. ==================
  252.  
  253. general::
  254.  
  255.     brew install wget
  256.  
  257. `hub`_ is a useful extension to make git `github`_ aware.
  258. `gist`_ is a commandline interface to `github gists`_.
  259.  
  260. git::
  261.  
  262.     brew install git
  263.     brew install hub
  264.     brew install git-flow
  265.     brew install gist
  266.     brew install git-extras git-hg git-multipush git-sh git-svn-abandon git-utils
  267.  
  268. mercurial (hg)::
  269.  
  270.     pip install mercurial
  271.  
  272. .. ATTENTION::
  273.    Installation of the `mercurial 2.1.1 package`_ from pypi does not work.
  274.    See http://mercurial.selenic.com/bts/issue3277 for details. Until ``2.1.2`` is released I recommend downloading
  275.    the source and running ``python setup.py install``.
  276.  
  277. .. ATTENTION::
  278.    I had problems installing mercurial with pip on a 32bit MacBook Pro (Core Duo and less) because it failed to compile
  279.    the 64bit version of the `mercurial.base85` extension. So I downloaded the `mercurial 1.8.2 package`_ from pypi and
  280.    removed ``-arch x86_64`` near the end of ``setup.py`` and the ran ``python setup.py install`` and it worked fine.
  281.  
  282.  
  283. xgettext
  284. --------
  285.  
  286. install and make the command globally available::
  287.  
  288.     brew install gettext
  289.     brew link gettext
  290.  
  291. more useful stuff
  292. -----------------
  293.  
  294. ::
  295.  
  296.     brew install ssh-copy-id
  297.     brew install vcprompt
  298.     pip install virtualenv
  299.     pip install virtualenvwrapper
  300.     brew install bash-completion
  301.     pip install ipython
  302.     pip install bpython
  303.  
  304. virtualenv
  305. ^^^^^^^^^^
  306.  
  307. and virtuelenvwrapper. See http://www.doughellmann.com/docs/virtualenvwrapper/ for details.
  308. ::
  309.  
  310.     pip install virtualenv
  311.     pip install virtualenvwrapper
  312.  
  313. Add this to you shell (``.bash_profile`` or similar)::
  314.  
  315.     export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
  316.     source /usr/local/share/python/virtualenvwrapper.sh
  317.  
  318.  
  319. the best packagage ever
  320. ^^^^^^^^^^^^^^^^^^^^^^^
  321.  
  322. the most useful package. this one is a must.::
  323.  
  324.     brew install cowsay
  325.     cowsay You can now code python on OSX. Congratulations!
  326.  
  327.  
  328. .. _aggdraw: http://effbot.org/zone/aggdraw-index.htm
  329. .. _github: https://github.com/
  330. .. _hub: https://github.com/defunkt/hub
  331. .. _mercurial: http://mercurial.selenic.com/
  332. .. _PIL: http://pypi.python.org/pypi/PIL/
  333. .. _mercurial 1.8.2 package: http://pypi.python.org/pypi/Mercurial/1.8.2
  334. .. _mercurial 2.1.1 package: http://pypi.python.org/pypi/Mercurial/2.1.1
  335. .. _github gists: https://gist.github.com/
  336. .. _gist: https://github.com/defunkt/gist