Python linux install numpy

numpy Getting started with numpy Installation on Linux

NumPy is available in the default repositories of most popular Linux distributions and can be installed in the same way that packages in a Linux distribution are usually installed.

Some Linux distributions have different NumPy packages for Python 2.x and Python 3.x. In Ubuntu and Debian, install numpy at the system level using the APT package manager:

sudo apt-get install python-numpy sudo apt-get install python3-numpy 

For other distributions, use their package managers, like zypper (Suse), yum (Fedora) etc.

numpy can also be installed with Python’s package manager pip for Python 2 and with pip3 for Python 3:

pip install numpy # install numpy for Python 2 pip3 install numpy # install numpy for Python 3 

pip is available in the default repositories of most popular Linux distributions and can be installed for Python 2 and Python 3 using:

sudo apt-get install python-pip # pip for Python 2 sudo apt-get install python3-pip # pip for Python 3 

After installation, use pip for Python 2 and pip3 for Python 3 to use pip for installing Python packages. But note that you might need to install many dependencies, which are required to build numpy from source (including development-packages, compilers, fortran etc).

Besides installing numpy at the system level, it is also common (perhaps even highly recommended) to install numpy in virtual environments using popular Python packages such as virtualenv . In Ubuntu, virtualenv can be installed using:

sudo apt-get install virtualenv 

Then, create and activate a virtualenv for either Python 2 or Python 3 and then use pip to install numpy :

virtualenv venv # create virtualenv named venv for Python 2 virtualenv venv -p python3 # create virtualenv named venv for Python 3 source venv/bin/activate # activate virtualenv named venv pip install numpy # use pip for Python 2 and Python 3; do not use pip3 for Python3 

pdf

PDF — Download numpy for free

Источник

Как установить NumPy на Ubuntu 20.04

NumPy — это библиотека python, используемая для научных вычислений. Которая предлагает следующее функции.

  • объект многомерного массива
  • маскированные массивы и матрицы
  • манипуляция формой
  • сортировка
  • выбор
  • дискретные преобразования Фурье
  • основы линейной алгебры
  • основные статистические операции
  • случайное моделирование

В этой пошаговой инструкции вы узнаете, как установить NumPy на Ubuntu 20.04 Linux.

NumPy Ubuntu

Установить pip на Ubuntu

Pip — это официальный инструмент для управления пакетами python. Он помогает установить, удалить и обновить определенный пакет до последней версии. Разработчики находят эту утилиту очень полезной, когда речь заходит об установке всего пакета зависимостей проекта.

Читайте также:  Astra linux text editor

Установка pip на Python 2

Скачать pip для python 2 можно с помощью команды wget:

$ wget https://bootstrap.pypa.io/2.7/get-pip.py -O get-pip27.py

Теперь чтобы установить pip выполните следующую команду:

Установка pip на Python 3

Что касается установки pip для python3, то процесс тот же.

Скачать скрипт для pip:

$ wget https://bootstrap.pypa.io/get-pip.py -O get-pip.py

Чтобы установить pip для python 3, Введите:

Установить NumPy на Ubuntu

Утилита pip помогает установить NumPy для обеих версий python. Что касается версии python 2.x, то следующая команда устанавливает пакет NumPy.

Опция -m помогает использовать определенный пакет python; в нашем случае pip.

В случае успеха на вашей консоли должно быть отображено следующее.

Collecting numpy
Downloading numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl (17.0 MB)
|████████████████████████████████| 17.0 MB 12.2 MB/s
Installing collected packages: numpy
WARNING: The scripts f2py, f2py2 and f2py2.7 are installed in ‘/home/linoxide/.local/bin’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use —no-warn-script-location.
Successfully installed numpy-1.16.6

Для установки numpy на python 3 выполните следующую команду.

Проверьте правильность установки.

Опция show помогает идентифицировать установленный пакет python.

Пакет numpy для python3

Импорт numpy из интерактивной оболочки python

Следующая команда импортирует библиотеку под именем np. Это работает как для python 2, так и для python 3.

Импорт numpy

Обновите NumPy до последней версии

Утилита pip имеет опцию которая помогает обновить установленный пакет до последней версии.

Чтобы обновить numpy для python 2, введите команду:

Для python 3 выполните следующую команду:

Заключение

Из этой инструкции вы узнали, как правильно установить пакет numpy как для python 2, так и для python 3. Вы также узнали, как обновить пакет numpy до последней версии.

Так же рекомендую к прочтению Сканер портов на Python

Источник

Installing NumPy

The only prerequisite for installing NumPy is Python itself. If you don’t have Python yet and want the simplest way to get started, we recommend you use the Anaconda Distribution — it includes Python, NumPy, and many other commonly used packages for scientific computing and data science.

NumPy can be installed with conda , with pip , with a package manager on macOS and Linux, or from source. For more detailed instructions, consult our Python and NumPy installation guide below.

If you use conda , you can install NumPy from the defaults or conda-forge channels:

# Best practice, use an environment rather than install in the base env conda create -n my-env conda activate my-env # If you want to install from conda-forge conda config --env --add channels conda-forge # The actual install command conda install numpy 

If you use pip , you can install NumPy with:

Also when using pip, it’s good practice to use a virtual environment — see Reproducible Installs below for why, and this guide for details on using virtual environments.

Python and NumPy installation guide

Installing and managing packages in Python is complicated, there are a number of alternative solutions for most tasks. This guide tries to give the reader a sense of the best (or most popular) solutions, and give clear recommendations. It focuses on users of Python, NumPy, and the PyData (or numerical computing) stack on common operating systems and hardware.

Читайте также:  Nginx config linux path

Recommendations

We’ll start with recommendations based on the user’s experience level and operating system of interest. If you’re in between “beginning” and “advanced”, please go with “beginning” if you want to keep things simple, and with “advanced” if you want to work according to best practices that go a longer way in the future.

Beginning users

On all of Windows, macOS, and Linux:

  • Install Anaconda (it installs all packages you need and all other tools mentioned below).
  • For writing and executing code, use notebooks in JupyterLab for exploratory and interactive computing, and Spyder or Visual Studio Code for writing scripts and packages.
  • Use Anaconda Navigator to manage your packages and start JupyterLab, Spyder, or Visual Studio Code.

Advanced users

Conda

  • Install Miniforge.
  • Keep the base conda environment minimal, and use one or more conda environments to install the package you need for the task or project you’re working on.

Alternative if you prefer pip/PyPI

For users who know, from personal preference or reading about the main differences between conda and pip below, they prefer a pip/PyPI-based solution, we recommend:

  • Install Python from python.org, Homebrew, or your Linux package manager.
  • Use Poetry as the most well-maintained tool that provides a dependency resolver and environment management capabilities in a similar fashion as conda does.

Python package management

Managing packages is a challenging problem, and, as a result, there are lots of tools. For web and general purpose Python development there’s a whole host of tools complementary with pip. For high-performance computing (HPC), Spack is worth considering. For most NumPy users though, conda and pip are the two most popular tools.

Pip & conda

The two main tools that install Python packages are pip and conda . Their functionality partially overlaps (e.g. both can install numpy ), however, they can also work together. We’ll discuss the major differences between pip and conda here — this is important to understand if you want to manage packages effectively.

The first difference is that conda is cross-language and it can install Python, while pip is installed for a particular Python on your system and installs other packages to that same Python install only. This also means conda can install non-Python libraries and tools you may need (e.g. compilers, CUDA, HDF5), while pip can’t.

The second difference is that pip installs from the Python Packaging Index (PyPI), while conda installs from its own channels (typically “defaults” or “conda-forge”). PyPI is the largest collection of packages by far, however, all popular packages are available for conda as well.

The third difference is that conda is an integrated solution for managing packages, dependencies and environments, while with pip you may need another tool (there are many!) for dealing with environments or complex dependencies.

Читайте также:  Логи линукс что это

Reproducible installs

As libraries get updated, results from running your code can change, or your code can break completely. It’s important to be able to reconstruct the set of packages and versions you’re using. Best practice is to:

  1. use a different environment per project you’re working on,
  2. record package names and versions using your package installer; each has its own metadata format for this:
    • Conda: conda environments and environment.yml
    • Pip: virtual environments and requirements.txt
    • Poetry: virtual environments and pyproject.toml

NumPy packages & accelerated linear algebra libraries

NumPy doesn’t depend on any other Python packages, however, it does depend on an accelerated linear algebra library — typically Intel MKL or OpenBLAS. Users don’t have to worry about installing those (they’re automatically included in all NumPy install methods). Power users may still want to know the details, because the used BLAS can affect performance, behavior and size on disk:

  • The NumPy wheels on PyPI, which is what pip installs, are built with OpenBLAS. The OpenBLAS libraries are included in the wheel. This makes the wheel larger, and if a user installs (for example) SciPy as well, they will now have two copies of OpenBLAS on disk.
  • In the conda defaults channel, NumPy is built against Intel MKL. MKL is a separate package that will be installed in the users’ environment when they install NumPy.
  • In the conda-forge channel, NumPy is built against a dummy “BLAS” package. When a user installs NumPy from conda-forge, that BLAS package then gets installed together with the actual library — this defaults to OpenBLAS, but it can also be MKL (from the defaults channel), or even BLIS or reference BLAS.
  • The MKL package is a lot larger than OpenBLAS, it’s about 700 MB on disk while OpenBLAS is about 30 MB.
  • MKL is typically a little faster and more robust than OpenBLAS.

Besides install sizes, performance and robustness, there are two more things to consider:

  • Intel MKL is not open source. For normal use this is not a problem, but if a user needs to redistribute an application built with NumPy, this could be an issue.
  • Both MKL and OpenBLAS will use multi-threading for function calls like np.dot , with the number of threads being determined by both a build-time option and an environment variable. Often all CPU cores will be used. This is sometimes unexpected for users; NumPy itself doesn’t auto-parallelize any function calls. It typically yields better performance, but can also be harmful — for example when using another level of parallelization with Dask, scikit-learn or multiprocessing.

Troubleshooting

If your installation fails with the message below, see Troubleshooting ImportError.

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy c-extensions failed. This error can happen for different reasons, often due to issues with your setup. 

Источник

Оцените статью
Adblock
detector