I've been indebted to ActivePython for a long time, but since various microprojects have been completed, I wanted to manage python versions and packages more flexibly, so I moved to an environment that uses pythonbrew and virtualenv. Here, I will write the memorandum and leave it as a reminder. In addition, since everything is executed in the terminal, it does not make sense to read it if you want to do it with gui. (So, I welcome you to point out, but I did it this way, but I don't want to be complained that it didn't work.)
Postscript (2013/10/02): pythonbrew is becoming obsolete as the author announces that it will not continue development. However, the idea of pythonz, which is being developed as a successor, is different, and the specifications on mac Even after knowing this fact, I think it's worth making pythonbrew because pythonbrew is easier to use.
I would like to mourn the Active Python that has been taken care of so far.
Based on the above page, run the following command to uninstall ActivePython.
$ sudo /Library/Frameworks/Python.framework/Versions/2.6/Resources/Scripts/uninstall
In the case of 2.7, it is OK if the 2.6 part in the middle of the path is changed to 2.7.
From here, I proceeded with reference to the following page.
Put it in crispy.
$ curl -kLO https://github.com/utahta/pythonbrew/raw/master/pythonbrew-install
$ chmod +x pythonbrew-install
Add the following line to ~ / .bashrc to get through the ./pythonbrew-install path. For csh, tcsh, and zsh people, add them to their respective rc files.
source ~/.pythonbrew/etc/bashrc
If you want to continue, reload ~ / .bashrc.
$ source ~/.bashrc
We only install one version of python here, but pythonbrew allows you to install different versions of python and switch between active python versions. Please refer to it if you are interested because it is listed on the link page.
$ pythonbrew install 2.7.2 --framework
$ pythonbrew switch 2.7.2
$ sudo xcodebuild -license
virtualenv is software that can virtually prepare an environment such as a group of packages when executing python.
It may not come as a pinch, but since python version control and package dependency resolution are relatively rough, it works with this version combination of this package, but it does not work elsewhere. Sometimes there is. It is indispensable for heavy users because it is irresistible to reinstall the package every time.
$ pip install virtualenv
$ pip install virtualenvwrapper
That's it, but finally, let's take a look at a simple way to use virtualenv.
$ virtualenv sandbox
$ cd sandbox
$ source bin/activate
(sandbox) $ pip install numpy
(sandbox) $ python
Python 2.7.2 (default, Sep 26 2013, 15:18:47)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
(sandbox) $ deactivate
$ python
>>> import numpy
Traceback (most recent call last):File "<stdin>", line 1, in <module>ImportError: No module named numpy
In the above, a virtual environment is built in a directory called sandbox. To use the built virtual environment, read the file bin / activate in the virtual environment (with source). After reading, it will be in a state with the prefix (environment name). The package installed in this state is installed in the virtual environment, but it is not installed in the environment returned by the command deactivate that can be used in the virtual environment.
By using different virtual environments in this way, more flexible software development becomes possible. If you are a heavy python user, please do. It is also useful for checking dependencies when testing software.
That said, I think most heavy users are using it, so I'm the only one who's late ...
Recommended Posts