Installing R on OSX

Install Homebrew (if you still don't have it) 
ruby -e "$(curl -fsSL" 

Install R 
brew tap homebrew/science 
brew install r

When running r, I got the following error message:

dyld: Library not loaded: /usr/local/opt/gcc/lib/gcc/6/libgfortran.3.dylib
  Referenced from: /usr/local/Cellar/r/3.3.1/R.framework/Versions/3.3/Resources/lib/libR.dylib
  Reason: image not found

Trace/BPT trap: 5

To fix this error, I had to do this:
brew reinstall gcc --with-fortran

Fastest Factorial Function in Python

from functools import reduce
from operator import mul

def fastest_factorial(n):
     return reduce(mul, range(1, n+1), 1)

Tutorial: virtualenvwrapper

0) Make sure you have pip & virtualenv

sudo easy_install pip
sudo pip install virtualenv

1) Install virtualenvwrapper

sudo pip install virtualenvwrapper

2) Add the following lines in your shell startup file (.bashrc or .profile file).

export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/
### or ###
source /usr/bin/
### if you installed virtualenvwrapper in that directory
### you can use sudo find / -name
### to locate virtualenvwrapper if you installed it somewhere else

Tutorial: pyenv

How to Install pyenv


Replace .bashrc to .bash_profile if that is the configuration file you are using.
git clone git:// .pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc


curl -L | bash


~$ pyenv global
~$ pyenv versions
* system (set by /home/user/.pyenv/version)
'pyenv global' shows you what python version is set as the default python version. 'pyenv versions'
shows you all available python versions.
To install a new version:
~$ pyenv install 3.4.0
Installing readline-6.3...
Installed readline-6.3 to /home/user/.pyenv/versions/3.4.0

Installing Python-3.4.0...
Installed Python-3.4.0 to /home/user/.pyenv/versions/3.4.0
To show all available Python versions you can install:
~$ pyenv install --list
~$ pyenv versions
* system (set by /home/user/.pyenv/version)
pyenv now lists two python versions. To use python 3.4 as the default version:
pyenv global 3.4.0
You can also use pyenv to define a project-specific, or local, version of Python:
~$ pyenv global system

~$ mkdir cuting_edge
~$ cd cuting_edge/
~/cutting_edge$ pyenv local 3.4.0
~/cutting_edge$ python -V
Python 3.4.0
~/cutting_edge$ cd ..
~$ python -V
Python 2.7.6

Virtual Environments

To other virtualenv users, the idea of a local Python might seem familiar. Indeed, a local Python created from pyenv is almost like a Python virtual environment. The main difference is that pyenv actually copies an entire Python installation every time you create a new pyenv version. In contrast, virtualenv makes use of symbolic links to decrease the size of the virtualenv’s. If you can’t function without your virtual environments anymore then fear not, for there is a plugin for that:pyenv-virtualenv. This plugin adds complete virtualenv functionality to pyenv:
git clone ~/.pyenv/plugins/pyenv-virtualenv
source ~/.bashrc

~$ mkdir virtual_env
~$ cd virtual_env/
~/virtual_env$ pyenv virtualenv 3.4.0 venv
Ignoring indexes:
Requirement already satisfied (use --upgrade to upgrade): setuptools in /home/user/.pyenv/versions/venv/lib/python3.4/site-packages
Requirement already satisfied (use --upgrade to upgrade): pip in /home/user/.pyenv/versions/venv/lib/python3.4/site-packages
Cleaning up...

~/virtual_env$ pyenv versions
* system (set by /home/user/.pyenv/version)
If you want to create a virtualenv from the system Python, then virtualenv needs to be installed at the system level as well.
~/virtual_env$ pyenv activate venv
(venv) ~/virtual_env$ python -V
Python 3.4.0
(venv) ~/virtual_env$ pip list
pip (1.5.4)
setuptools (2.1)
(venv) ~/virtual_env$ pyenv deactivate
This last command is the recommended way to deactivate the virtualenv. This ensures that pyenv remains working as normal after you leave the virtualenv.
pyenv’s magic works because it actually redefines your Python command:
~$ which python
When you try to run Python, it first looks for a .python-version in the current directory to decide which version of python to run. If it doesn’t find this file, then it looks for the user-level file ~/.pyenv/version.
And this is essentially all there is to it. Have fun developing Python code in a safe, environment-friendly way.



PISIKA Copyright © 2009