How to install a SciPy stack using pip and homebrew?

I am trying to install the scipy base stack (numpy, scipy, matplotlib, pandas, sympy, ipython, nose) in virtualenv; I am currently using OSX Mountain Lion. On the installation pages for these packages, as well as in various threads here and on the Internet, it seems that pandas, sympy and nose can be easily installed with a simple pip (although some of them are numpy / scipy / etc as dependencies),

However, there seem to be conflicting and somewhat confusing instructions for properly installing numpy, scipy, matplotlib and, to some extent, ipython *. Pip-only installation does not seem to be the proper way to install these packages; it seems that some dependencies need to be installed using homebrew, but in different places various packages are listed before brew to install before installing numpy / scipy / etc. Is there a comprehensive and current list of package dependencies that you need to install using homebrew before pip installs numpy, scipy, and matplotlib?

As a remark, I looked at pressing homebrew / python to install numpy, scipy and matplotlib correctly using homebrew, but I want to install in virtualenv, and I don't think I can use homebrew to do this.

Any help would be greatly appreciated; thanks in advance!

* In addition, for ipython, the installation page indicates that pip install ipython [all] should be sufficient, but some other sources ( http://www.coderstart.com/setup/python-setup.html ; http: // www .lowindata.com / 2013 / installing-scientific-python-on-mac-os-x / ) seems to suggest that qt, pyqt and zmq packages must be installed by brew before installing ipython; do i need a home installation or is it just to just install pip according to ipython installation page?

+6
source share
2 answers

Answering my own question here, but hopefully this is helpful; Feel free to fix if there are any errors. The original version is a giant wall with text, so I added tl; dr at the top with only steps to hopefully make the process more understandable.

tl; dr: In the / bash terminal, go to virtualenv (if you want to install it in one) and enter these commands in order. This is tested for OSX Mountain Lion.

pip install numpy brew install gcc pip install scipy brew install freetype pip install matplotlib pip install nose pip install pandas pip install sympy pip install ipython[all] brew install pyqt brew install qt brew install sip echo "export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH" >> ~/.bash_profile source ~/.bash_profile 

* Notes: brew pyqt installation can already install qt and sip; if so, do not need to install qt and sip after installing pyqt. For the second to the last line, the direct c / p line in ~ / .bash_profile may be more reliable, since it may appear at the top of the contents of ~ / .bash_profile. In addition, brew does not have to install pandoc, but the ipython laptop nbconvert command needs to work correctly.

edit 10/13/14 [see edit below]: editing PYTHONPATH in ~ / .bash_profile forces virtual environments to inherit global packages; if you want to be able to create isolated environments, do not take the last two steps. Instead, assuming virtualenvwrapper is installed, edit the local postactivate and predeactivate scripts in the bin directory under virtualenv, which contains scipy.

In postactivate, type:

 export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH 

In predeactivate, type:

 unset PYTHONPATH 

This should edit PYTHONPATH when virtualenv is activated with scipy stuff, so ipton qtconsole works, but should reset PYTHONPATH when virtualenv is deactivated, so other variables do not affect PYTHONPATH changes.


The following is a long narrative version.

In any case, from some trial and error after I originally posted this question, I found that the following steps work; I used the two sets of instructions that I linked above as general guides, and this has been tested on OSX Mountain Lion.

After activating virtualenv in which the packages will be installed, first specify install numpy; this should work as expected and you need to install numpy (note that numpy should be installed first, since many other packages in the scipy stack are numpy dependent).

Now, before installing scipy, several sources note that gfortran (this seems to be the most common, but I think that any fortran compiler should work) needs to be installed; brew install gfortran returns an error saying gcc now includes gfortran, so the gfortran formula is deprecated. Therefore, we brew install gcc (note that although the xcode command-line tools that are usually installed before homebrew already include gcc, its version of gcc somehow does not work or does not include gfortran). After installing gcc, pip install scipy works as expected and scipy should be installed. Quickly open: brew install gcc installs gcc, as well as a bunch of dependencies, namely cloog, gcc, gmp, isl, libmpc, mpfr. [They should all be installed in / usr / local / Cellar, which is the default installation location for homebrew.]

To install matplotlib, you must first install freetype, so brew install freetype; this should install freetype and libpng, which seems to be freetype dependent. Subsequently, pip install matplotlib works as expected by successfully installing matplotlib. Note that matplotlib is installed using mock (required to run the matplotlib test suite), pyparsing (required to support mathtext), python-dateutil (required to support the date axis), six (for no reason) with it. [All of them must be installed along with any other pip installation inside virtualenv in the package sites directory in virtualenv.]

Installing the nose, sympy and pandas just requires installing pip, since they have no dependencies that brew needs to install. However, it should be noted from them that at least pandas depends on numpy, so installing pandas (not sure about others) after installing numpy is probably preferable. Also note that pandas is installed using pytz (for calculating time zones).

Installing ipython is pretty simple, but configuring it is a bit confusing. As heads-up, ipython can be used with both the qt console and the ipython laptop, which has various advantages. You can simply install ipython with pip install ipython and install additional dependencies later, but I installed all the basic optional dependencies with pip install ipython [all]. This installs ipython along with many other package dependencies (installs with backports.ssl-match-hostname (from the tornado), certifi (from the tornado), docutils (from the sphinx), gnureadline, ipython, jinja2, markupsafe (from jinja2), numpydoc ( from ipython [all]), pigments, pyzmq, sphinx, tornado). This should be a good basis for using ipython as both the standard ipython shell and the qt console and ipython laptop. However, it is not fully configured if you want to use the qt console or laptop.

To use the qt console, the pyqt, qt, and sip packages must have brew installed, as these are dependencies that cannot be installed using pip; from experience, brew install pyqt seems to install all three packages, but installing these three individually can be safer. After that, go to the ~ / .bash_profile file and add the line 'export PYTHONPATH = / usr / local / lib / python2.7 / site-packages: $ PYTHONPATH' to it; then 'source ~ / .bash_profile' in the terminal to reload the shell. This should successfully start the qt console. [I'm not quite sure why this line should be added since I already edited the PATH variable to put / usr / local / bin in front of / usr / bin, but maybe qt / pyqt / sip was still trying to relate to system python by default, not with homebrew installed by python.]

The laptop seems to work fine out of the box, as far as I saw, but there is one note: to use nbconvert (convert the laptop to different file formats), you need to install the pandoc package, presumably with homebrew. Like qt / pyqt / sip, it cannot be installed using pip, so it was not installed with pip install ipython [all].

edit 10/13/14: Thus, editing PYTHONPATH will destroy empty virtual environments, which will make global packages also available in virtualenv ( how to isolate virtualenv from local dist packages? ); this, for the most part, defeats the goal of virtualenv by assuming that you want to create a new environment, but that ipton qtconsole needs to work correctly.

The fix is ​​to edit (assuming virtualenvwrapper is installed) the local postactivate and predeactivate scripts in the bin file of your virtualenv. In postactivate, enter the line "export PYTHONPATH = / usr / local / lib / python2.7 / site-packages: $ PYTHONPATH; in predeactivate, enter the line" reset PYTHONPATH ". Do not do the last two steps the original sequence or delete the line that was added To the ~ / bash_profile file.This should make sure that changes to PYTHONPATH are made only when virtual machines are activated with our installed packages, so qtconsole works, but reset to virtualenv deactivates so that other environments will not be affected.

+10
source

I am on OSX 10.9, but I was lucky to follow these instructions and get about the same environment that you described above http://hackercodex.com/guide/python-development-environment-on-mac-osx/

Hope this helps

+1
source

Source: https://habr.com/ru/post/976624/


All Articles