Меню Рубрики

How to install numpy on windows

Installing NumPy

The only prerequisite for 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 other commonly used packages for scientific computing and data science.

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

conda

If you use conda , you can install it with:

If you use pip , you can install it with:

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.

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

Windows or macOS

  • Install Miniconda.
  • 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.
  • Unless you’re fine with only the packages in the defaults channel, make conda-forge your default channel via setting the channel priority.

Linux

If you’re fine with slightly outdated packages and prefer stability over being able to use the latest versions of libraries:

  • Use your OS package manager for as much as possible (Python itself, NumPy, and other libraries).
  • Install packages not provided by your package manager with pip install somepackage —user .
  • Install Miniconda.
  • 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.
  • Use the defaults conda channel ( conda-forge doesn’t have good support for GPU packages yet).
  • 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, for example, 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.

Troubleshooting ImportError

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

Building from source

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 pip does not have a dependency resolver (this is expected to change in the near future), while conda does. For simple cases (e.g. you just want NumPy, SciPy, Matplotlib, Pandas, Scikit-learn, and a few other packages) that doesn’t matter, however, for complicated cases conda can be expected to do a better job keeping everything working well together. The flip side of that coin is that installing with pip is typically a lot faster than installing with conda.

The fourth 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

Making the installation of all the packages your analysis, library or application depends on reproducible is important. Sounds obvious, yet most users don’t think about doing this (at least until it’s too late).

The problem with Python packaging is that sooner or later, something will break. It’s not often this bad,

XKCD illustration — Python environment degradation

but it does degrade over time. Hence, it’s important to be able to delete and reconstruct the set of packages you have installed.

Best practice is to use a different environment per project you’re working on, and record at least the names (and preferably versions) of the packages you directly depend on in a static metadata file. Each packaging tool has its own metadata format for this:

Sometimes it’s too much overhead to create and switch between new environments for small tasks. In that case we encourage you to not install too many packages into your base environment, and keep track of versions of packages some other way (e.g. comments inside files, or printing numpy.__version__ after importing it in notebooks).

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, but it may still be important to understand how the packaging is done and how it affects performance and behavior users see.

The NumPy wheels on PyPI, which is what pip installs, are built with OpenBLAS. The OpenBLAS libraries are shipped within the wheels itself. This makes those wheels 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. That MKL package is a lot larger than OpenBLAS, several hundred MB. MKL is typically a little faster and more robust than OpenBLAS.

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.

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

Источник

Installing NumPy on Windows

I’m simply unable to install NumPy on Windows. I keep getting this error —

I had Python 64 bit version earlier and I was not sure if NumPy version was compatible with 64 bit Python. So I uninstalled it and installed 32 bit Python version. But still I’m getting the same error. Though my Python 32 bit version is working fine.

I tried «pip install numpy» but that give me the following error at the end —

Please tell me what I might be doing wrong.

5 Answers 5

Some explanations

In the first case, I didn’t check but I guess that pip directly downloads the resource corresponding to the given URL: http://sourceforge.net/projects/numpy/file/NumPy/. The server returns a HTML document, while pip expects an archive one. So that can’t work.

Then there are basically two ways to install Python packages:

  • from sources, as you tried then
  • from pre-compiled packages

The first case, you tried it with the command pip install numpy , but since this package contains native code, it requires development tools to be installed properly (which I always found to be a pain in the neck to do on Windows, but I did it so it’s clearly feasible). The error you have error: Unable to find vcvarsall.bat means you don’t have the tools installed, or the environment properly set up.

For the second case, you have different kinds of pre-compiled packages:

  • wheels, which you install with pip as well
  • installers, which you use as standard installers on Windows

For both, you need to check that the binary has been strictly compiled for your Python architecture (32 or 64 bits) and version.

An easy solution

You can find there several wheels for numpy : http://www.lfd.uci.edu/

gohlke/pythonlibs/#numpy. To get the proper architecture, check in the name win32 for 32 bits and amd64 for 64 bits. To get the proper Python version, check cpXX : first X is major version, and second X is minor version, so for instance cp27 means CPython 2.7.

Example: pip install numpy‑1.9.2rc1+mkl‑cp27‑none‑win32.whl

The hard solution: installing and using development tools

DISCLAIMER: all the following explanations might not be quite clear. They result from several investigations at different moments, but in my configuration they led to a working solution. Some links might be useless, or redundant, but that’s what I noted. All of this requires a bit of cleaning, and probably generalization too.

First, you need to understand that disutils — which is the pre-installed package which handles packages workflow at lower level than pip (and which is used by the latter) — will try to use a compiler that strictly matches the one that was used to build the Python machine you installed.

Official distributions of Python use Microsoft Visual C++ for Microsoft Windows packages. So you will need to install this compiler in this case.

How to find proper version of Visual C++

The string printed by Python with this command python -c «import sys; print(sys.version)» (or when you invoke the interactive shell) will look like this:

3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)]

The last part between square brackets is the identification part of the compiler. Unfortunately, this is not quite straightforward, and you have correspondence lists there:

In the example I gave above, this means Microsoft Visual C++ 2010 64 bits.

How to install Visual C++

You cannot find anymore a standalone package of Visual C++ for modern versions. So you will need to install the Windows SDK itself.

Here are some reference links:

Troubleshooting

You might have an error at the installation of the SDK: DDSet_Error: Patch Hooks: Missing required property ‘ProductFamily’: Setup cannot continue. DDSet_Warning: Setup failed while calling ‘getDLLName’. System error: Cannot create a file when that file already exists.

They have been reported in several questions already:

The thing is to remove all conflicting (understand: the ones that the SDK installer tries to install itself) version of the Visual C++ redistributable.

Use development tools

Normally you should run vsvarsall.bat (located inside the VC folder of the installation path of Visual Studio — example: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat ) to set up the proper environment variables so that the execution of distutils doesn’t fail when trying to compile a package.

This batch script accepts a parameter, which should set the wanted architecture. However I saw that with the free versions of the SDK some additional scripts were missing when trying several of these parameters.

Источник

Building and installing NumPyВ¶

Binary installersВ¶

In most use cases the best way to install NumPy on your system is by using an installable binary package for your operating system.

WindowsВ¶

Good solutions for Windows are, Enthought Canopy, Anaconda (which both provide binary installers for Windows, OS X and Linux) and Python (x, y). Both of these packages include Python, NumPy and many additional packages.

A lightweight alternative is to download the Python installer from www.python.org and the NumPy installer for your Python version from the Sourceforge `download site .

The NumPy installer includes binaries for different CPU’s (without SSE instructions, with SSE2 or with SSE3) and installs the correct one automatically. If needed, this can be bypassed from the command line with

or sse2 or sse3 instead of nosse .

LinuxВ¶

All major distributions provide packages for NumPy. These are usually reasonably up-to-date, but sometimes lag behind the most recent NumPy release.

Mac OS XВ¶

Universal binary installers for NumPy are available from the `download site , and wheel packages from PyPi. With a recent version of `pip` `_ this will give you a binary install (from the wheel packages) compatible with at python.org Python, Homebrew and MacPorts:

Building from sourceВ¶

A general overview of building NumPy from source is given here, with detailed instructions for specific platforms given seperately.

PrerequisitesВ¶

Building NumPy requires the following software installed:

Python 2.6.x, 2.7.x, 3.2.x or newer

On Debian and derivatives (Ubuntu): python, python-dev (or python3-dev)

On Windows: the official python installer at www.python.org is enough

Make sure that the Python package distutils is installed before continuing. For example, in Debian GNU/Linux, installing python-dev also installs distutils.

Python must also be compiled with the zlib module enabled. This is practically always the case with pre-packaged Pythons.

To build any extension modules for Python, you’ll need a C compiler. Various NumPy modules use FORTRAN 77 libraries, so you’ll also need a FORTRAN 77 compiler installed.

Note that NumPy is developed mainly using GNU compilers. Compilers from other vendors such as Intel, Absoft, Sun, NAG, Compaq, Vast, Porland, Lahey, HP, IBM, Microsoft are only supported in the form of community feedback, and may not work out of the box. GCC 4.x (and later) compilers are recommended.

Linear Algebra libraries

NumPy does not require any external linear algebra libraries to be installed. However, if these are available, NumPy’s setup script can detect them and use them for building. A number of different LAPACK library setups can be used, including optimized LAPACK libraries such as ATLAS, MKL or the Accelerate/vecLib framework on OS X.

Basic InstallationВ¶

To install NumPy run:

To perform an in-place build that can be run from the source folder run:

The NumPy build system uses distutils and numpy.distutils . setuptools is only used when building via pip or with python setupegg.py . Using virtualenv should work as expected.

Note: for build instructions to do development work on NumPy itself, see :ref:`development-environment`.

Parallel buildsВ¶

From NumPy 1.10.0 on it’s also possible to do a parallel build with:

This will compile numpy on 4 CPUs and install it into the specified prefix. to perform a parallel in-place build, run:

The number of build jobs can also be specified via the environment variable NPY_NUM_BUILD_JOBS .

FORTRAN ABI mismatchВ¶

The two most popular open source fortran compilers are g77 and gfortran. Unfortunately, they are not ABI compatible, which means that concretely you should avoid mixing libraries built with one with another. In particular, if your blas/lapack/atlas is built with g77, you must use g77 when building numpy and scipy; on the contrary, if your atlas is built with gfortran, you must build numpy/scipy with gfortran. This applies for most other cases where different FORTRAN compilers might have been used.

Choosing the fortran compilerВ¶

To build with gfortran:

For more information see:

How to check the ABI of blas/lapack/atlasВ¶

One relatively simple and reliable way to check for the compiler used to build a library is to use ldd on the library. If libg2c.so is a dependency, this means that g77 has been used. If libgfortran.so is a a dependency, gfortran has been used. If both are dependencies, this means both have been used, which is almost always a very bad idea.

Disabling ATLAS and other accelerated librariesВ¶

Usage of ATLAS and other accelerated libraries in Numpy can be disabled via:

Supplying additional compiler flagsВ¶

Additional compiler flags can be supplied by setting the OPT , FOPT (for Fortran), and CC environment variables.

Building with ATLAS supportВ¶

UbuntuВ¶

You can install the necessary package for optimized ATLAS with this command:

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

  • How to install maven on windows
  • How to install from usb windows 7
  • How to install bash on windows
  • How to install apache on windows
  • How to get help in windows 10