Python is installed by default in Mountain Lion. However, if you want to use the latest Python environment but want to keep the Python that is installed as standard on your Mac, you will not be able to install the latest Python. This time, I would like to write about "virtualenv" and "pythonz" that can leave the Python that is installed as standard on the Mac as it is and can use various Python environments.
-Easy_install must be installed
*) If easy_install is not installed, run the following command.
$ curl -O https://svn.apache.org/repos/asf/oodt/tools/oodtsite.publisher/trunk/distribute_setup.py
$ sudo python distribute_setup.py
(1) Install virtualenv using easy_install.
$ sudo easy_install virtualenv
(2) Execute the following command to install pythonz.
$ curl -kL https://raw.github.com/saghul/pythonz/master/pythonz-install | bash
(3) Add the following contents to .bashrc.
[[ -s $HOME/.pythonz/etc/bashrc ]] && source $HOME/.pythonz/etc/bashrc
(4) Reflect the modified contents of .bashrc.
$ source ~/.bashrc
(1) cleanup
$ pythonz cleanup
(2) install
$ pythonz install (version)
*) You can check the installable Python version using the following command.
$ pythonz list -a
(3) list
$ pythonz list #Show the currently installed version of Python
$ pythonz list -p #Show the path of the currently installed Python
$ pythonz list -a #Installable with pythonz shows Python version
(4) uninstall
$ pythonz uninstall (version)
(5) update
$ pythonz update
(1) Create a working folder for virtualenv. This time, create a .virtualenv folder on your home directory.
$ mkdir ~/.virtualenv
$ cd ~/.virtualenv
(2) Create a Python virtual environment with the virtualenv command.
#Basic commands
$ virtualenv -p (Installation path for Python executable files) (Virtual environment name) # 「-If you do not specify "p", the Python version is 2..It will be 5.
#Example of use
$ virtualenv -p ~/.pythonz/pythons/CPython-2.7.5/bin/python py27
(3) Start up the Python virtual environment with the following command.
$ source py27/bin/activate #"Py27" is the virtual environment name created above. Please read as appropriate.
(4) To terminate the Python virtual environment, execute the following command.
$ deactivate
Recommended Posts