Installation
Methods differ in ease of use, coverage, maintenance of old versions, system-wide versus local environment use, and control. With pip or Anaconda’s conda, you can control the package versions for a specific project to prevent conflicts. Conda also controls non-Python packages, like MKL or HDF5. System package managers, like apt-get , install across the entire computer, often have older versions, and don’t have as many available versions. Source compilation is much more difficult but is necessary for debugging and development. If you don’t know which installation method you need or prefer, we recommend the Scientific Python Distribution Anaconda.
Scientific Python Distributions (recommended)#
Python distributions provide the language itself, along with the most commonly used packages and tools. These downloadable files require little configuration, work on almost all setups, and provide all the commonly used scientific Python tools.
Anaconda works on Windows, Mac, and Linux, provides over 1,500 Python packages, and is used by over 15 million people. Anaconda is best suited to beginning users; it provides a large collection of libraries all in one.
For more advanced users who will need to install or upgrade regularly, Mambaforge is a more suitable way to install the conda (and mamba , a faster conda alternative) package manager.
Other options include:
- WinPython: Another free distribution including scientific packages and the Spyder IDE; Windows only, but more actively maintained and supports the latest Python 3 versions.
- Pyzo: A free distribution based on Anaconda and the IEP interactive development environment; Supports Linux, Windows, and Mac.
Installing with Pip#
You can install SciPy from PyPI with pip :
python -m pip install scipy
Installing via Conda#
You can install SciPy from the defaults or conda-forge channels with conda :
conda install scipy
Install system-wide via a package manager#
System package managers can install the most common Python packages. They install packages for the entire computer, often use older versions, and don’t have as many available versions.
Ubuntu and Debian#
sudo apt-get install python3-scipy
Fedora#
sudo dnf install python3-scipy
macOS#
macOS doesn’t have a preinstalled package manager, but you can install Homebrew and use it to install SciPy (and Python itself):
brew install scipy
Source packages#
A word of warning: building SciPy from source can be a nontrivial exercise. We recommend using binaries instead if those are available for your platform. For details on how to build from source, see this guide in the SciPy docs.
Как установить библиотеку SciPy на Windows
Обновление: собранные wheels для Windows доступны для scipy-1.0+ на PyPI, то есть стандартную команду для установки можно использовать:
T:\> pip install scipy
старая версия ответа:
- Заходим на https://scipy.org
- Нажимаем кнопку Install
- Читаем инструкцию для Windows.
Инструкция рекомендует, особенно на Windows, установить не один пакет, а сразу целый набор пакетов (Scientific Python distribution) такой как Anaconda.
Если вы хотите индивидуально numpy, scipy пакеты ставить, то инструкция рекомендует бинарные установщики с Christoph Gohlke сайта, которые доступны в виде бинарных wheel файлов, которые можно напрямую с помощью pip (c версией 8+) поставить:
T:\> pip install numpy‑1.12.0b1+mkl‑cp36‑cp36m‑win_amd64.whl T:\> pip install scipy‑0.18.1‑cp36‑cp36m‑win_amd64.whl
Если у вас 64-битная Windows используйте wheel, которые в имени содержат amd64. Если у вас Python 3.6 стоит, то используйте wheel, который cp36m в названии имеет. Перед установкой scipy, необходимо поставить numpy.
Не смешивайте установку бинарных wheel файлов (таких как на Christoph Gohlke сайте) и установку через conda.
Там есть файлы с cp27, cp34, cp35, cp36. Интересно, что это обозначает?
Соглашения для имён wheel описаны в PEP-427.
Сами метки описаны в PEP-425.
Метки существуют, чтобы указать системы, где соответствующие бинарные пакеты должны работать.
cp36m—это ABI метка, которая указывает на CPython реализацию ( sys.implementation.name ), версию 3.6 ( sys.version[:3] ) как я выше упомянул, и m буква ( sys.abiflags ) в метке указывает на —with-pymalloc опцию см. PEP-3149.
И какие нужно выбирать для 32 битной Windows?
Метка платформы определяется distutils.util.get_platform() значением согласно PEP-425.
На Windows возможны три (значения из help(distutils.util.get_platform) ):
- win-amd64 (64bit Windows на AMD64 (aka x86_64, Intel64, EM64T)
- win-ia64 (64bit Windows на Itanium)
- win32 (все другие)
то есть для 32 битной Windows следует win32 метку выбрать.
Installation¶
Methods differ in ease of use, coverage, maintenance of old versions, system-wide versus local environment use, and control. With pip or Anaconda’s conda, you can control the package versions for a specific project to prevent conflicts. Conda also controls non-Python packages, like MKL or HDF5. System package managers, like apt-get , install across the entire computer, often have older versions, and don’t have as many available versions. Source compilation is much more difficult but is necessary for debugging and development. If you don’t know which installation method you need or prefer, we recommend the Scientific Python Distribution Anaconda .
Scientific Python Distributions (recommended)¶
Python distributions provide the language itself, along with the most commonly used packages and tools. These downloadable files require little configuration, work on almost all setups, and provide all the commonly used scientific python tools.
Anaconda works on Windows, Mac, and Linux, provides over 1,500 Python/R packages, and is used by over 15 million people. Anaconda is best suited to beginning users; it provides a large collection of libraries all in one.
For more advanced users who will need to install or upgrade regularly, Miniconda is a more suitable way to install the conda package manager.
Other options include:
- WinPython: Another free distribution including scientific packages and the Spyder IDE; Windows only, but more actively maintained and supports the latest Python 3 versions.
- Pyzo: A free distribution based on Anaconda and the IEP interactive development environment; Supports Linux, Windows, and Mac.
Installing via pip¶
Python comes with an inbuilt package management system, pip. Pip can install, update, or delete any official package.
You can install packages via the command line by entering:
python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
We recommend using an user install, sending the —user flag to pip. pip installs packages for the local user and does not write to the system directories. Preferably, do not use sudo pip , as this combination can cause problems.
Pip accesses the Python Package Index, PyPI , which stores almost 200,000 projects and all previous releases of said projects. Because the repository keeps previous versions, you can pin to a version and not worry about updates causing conflicts. Pip can also install packages in local virtualenv, or virtual environment.
Install system-wide via a package manager¶
System package managers can install the most common Python packages. They install packages for the entire computer, often use older versions, and don’t have as many available versions.
Ubuntu and Debian¶
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
Fedora 22 and later¶
sudo dnf install numpy scipy python-matplotlib ipython python-pandas sympy python-nose atlas-devel
Mac¶
Mac doesn’t have a preinstalled package manager, but there are a couple of popular package managers you can install.
For Python 3.5 with Macports , execute this command in a terminal:
sudo port install py35-numpy py35-scipy py35-matplotlib py35-ipython +notebook py35-pandas py35-sympy py35-nose
Homebrew has an incomplete coverage of the SciPy ecosystem, but does install these packages:
brew install numpy scipy ipython jupyter
Source packages¶
You can build any of the packages from source. Those involved in development may take this route to get developmental versions or alter source code. Refer to individual projects for more details.
Binaries¶
Binary files can directly install the packages. These can either come from the direct source, like GitHub or PyPI , or third-party repositories. Linux operating systems, like Ubuntu , have package repositories where you can search for and download individual binaries. For Windows, Christoph Gohlke provides pre-built Windows installers for many packages.
SciPy¶
SciPy — библиотека, в которой реализовано множество процедур и численных алгоритмов для решения таких задач, как численное интегрирование, интерполяция, оптимизация, линейной алгебры, статистики и т.д. Если в рамках вашей научной деятельности возникает необходимость применить какой-то численный алгоритм, то стоит проверить не реализован ли он уже в SciPy .
Установка SciPy¶
Чтобы установить SciPy , наберите в Anaconda Prompt команду
conda install scipy
python -m pip install scipy
Импортирование SciPy¶
SciPy состоит из подмодулей для решения похожих задач определенного вида. Отметим ряд из них:
- scipy.integrate: численное интегрирование, численное решение ОДУ;
- scipy.interpolate: интерполяция;
- scipy.linalg: линейная алгебра, решение СЛАУ, задачи на собственные числа, сингулярное разложение и многое другое;
- scipy.optimize: оптимизационные алгоритмы, поиск корней уравнения, аппроксимация данных, задачи линейного программирования и др.;
- scipy.special: специальные функции;
- scipy.constants: константы (в том числе и физические);
- scipy.stats: статистка;
Более подробно про эти и остальные подмодули можно почитать в документации, курсе лекций по SciPy или в книге Elegant SciPy.
Пространство имен в SciPy устроено не совсем обычным образом. Принято импортировать не библиотеку целиком, а только её подмодули ( submodule ) или даже определенные функции этих подмодулей. Подробнее об API можно почитать здесь.
from scipy import optimize from scipy import integrate from scipy.stats import distributions