Check the installation of Python 2.7, and then install/reinstall pip which is described here. Then a open command line windows and write:
pip install numpy
Or
pip install scipy
If already installed, try this:
pip install -U numpy
Answer from acs on Stack OverflowCheck the installation of Python 2.7, and then install/reinstall pip which is described here. Then a open command line windows and write:
pip install numpy
Or
pip install scipy
If already installed, try this:
pip install -U numpy
Answer from acs on Stack OverflowCheck the installation of Python 2.7, and then install/reinstall pip which is described here. Then a open command line windows and write:
pip install numpy
Or
pip install scipy
If already installed, try this:
pip install -U numpy
Installing extension modules can be an issue with pip. This is why Conda exists. Conda is an open-source BSD-licensed cross-platform package manager. It can easily install NumPy.
Two options:
- Install Anaconda here
- Install Miniconda here and then go to a command line and type
conda install numpy(make sure your PATH includes the location Conda was installed to).
How to Install Numpy
How to install NumPy using official python IDLE? - Stack Overflow
Install python on windows 10 experience is horrible -- how do i get numpy?
python - Installing NumPy on Windows - Stack Overflow
Videos
A coworker sent me a Python file that uses numpy, so when I tried to run it, I got the error "No module named 'numpy'". So I looked up numpy, and it said in order to get that, I needed either conda or pip. so I looked up how to get conda, and it said I had to first download Anaconda. So I download Anaconda. I look in there and it would seem to me that both conda and numpy are already in there: Under Environments, both conda and numpy are listed as installed. But then I went back and tried to run the program again, and I got the same error. What else do I need to do to access numpy?
Also, idk if this matters, but I'm running Python on IDLE. Do I need to use a different IDE?
» pip install numpy
You have to install numpy from Command Prompt, not IDLE.
Follow these steps on Windows:
- Press the Windows key on your keyboard.
- Type CMD and open Command Prompt. A black terminal should open up.
- Type 'pip install numpy' and hit enter.
- It should start the installation. After you see the "Successfully Installed" message, go back to your IDLE and try importing numpy, it should work.
NOTE: In case you get a message saying "pip" is not recognized, refer to: https://stackoverflow.com/a/56678271/13699502
You write pip install numpy in the command prompt (CMD) if you are on Windows.
And, most of the times py -m pip install numpy helps more on Windows.
On macOS/Unix, you can use python -m pip install numpy in terminal/console.
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
pipas 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:
- windows - What version of Visual Studio is Python on my computer compiled with? - Stack Overflow
- visual studio - Detecting compiler versions during compile time - Stack Overflow3
- Pre-defined Compiler Macros / Wiki / Compilers
- WinCvt - Windows Converter toolkit
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:
- Download Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 from Official Microsoft Download Center: for Visual C++ 15.00 (Visual Studio 2008). Corresponds to WinSDK 7.
- Download Microsoft Windows SDK for Windows 7 and .NET Framework 4 from Official Microsoft Download Center: for Visual C++ 16.00 (Visual Studio 2010). Corresponds to WinSDK 7.1.
- installation - where can I download the full installer for Visual C++ Express? - Super User
- Visual Studio & co. downloads
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:
- Windows 7 SDK Installation Failure
- Error installing Windows 7 SDK 7.1 with VS2008, VS2010 Premium on Win 7 32bit
As a solution, you can check this link: Windows SDK Fails to Install with Return Code 5100
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.
Just to say that if you are compiling for a 32 bits architecture, simply calling vsvarsall.bat should work. If you need to compile for 64 bits, you can directly call SetEnv.cmd, located somewhere under inside the SDK installation path - example: "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64.
On Windows, pip is great for installing packages that do not require compiling. Otherwise, seriously, save yourself the hassle of building and maintaining packages, and take advantage of the work others did for you. I recommend using either of these Python distributions:
- ActivePython
- Anaconda
Anaconda is a little larger to download and install, but it includes many useful third-party packages by default (such as numpy). ActivePython includes a package manager which allows you to easily install pre-compiled binaries (installing numpy is as easy as pypm install numpy).
The advantage of using these Python distributions is that you can get a working installation running in minutes, in an easily reproducible manner.
Installing NumPy on Windows is a common problem if you don't have the right build setup. Instead, I always go to Christoph Gohlke's website to download the wheels you can install for your computer. Christoph generously builds the libraries himself with the right build environment, and he posts them on his website. These are specifically pre-compiled wheels made for Windows. I've found that Christoph Gohlke's website of pre-compiled wheels is the best way to install the NumPy and SciPy packages on Windows.
Currently, Christoph Gohlke hosts those wheels on his Github page found here: https://github.com/cgohlke/numpy-mkl-wheels/
Visit the Releases page. In the section that is the most up-to-date, make sure you click on the "Show all assets" link to uncover all of the wheels he has built, including NumPy and SciPy.
Right-click on the one that is specifically for your computer and download it. For example, numpy-1.26.3-cp311-cp311-win_amd64.whl indicates that this is NumPy 1.26.3, Python 3.11, Windows 64-bit.
Once downloaded, use pip to install the wheel:
pip install numpy-1.26.3-cp311-cp311-win_amd64.whl
This assumes you run the command in the same directory where you saved the wheel file. On the Releases page, search for the filename that is specifically for your machine according to the suitable Python, NumPy, and bit versions suitable for your environment and download the file, then run pip install as above.
These instructions are now out of date - keeping these for prosperity
First, install pipwin from PyPI which will install a utility that acts like pip but it will download the actual package you're interested in from his website, then use pipwin install to install the package you want.
First do:
pip install pipwin
When that's installed, you can then do:
pipwin install numpy
This will install the latest version of NumPy on your system. This way you don't have to specifically search for the version of NumPy that is for your specific version of Python.
Starting 24 November 2021, latest numpy require at least Python 3.8
Note: This might not be the original question asked, but it might help anyone come here.
To use python 3.7, latest numpy you can use is v1.21.4. So, to install it, use:
pip install numpy==1.21.4
If you write requirements that you hope compatible with python 3.7, you can use numpy<=1.21.4
EDIT: in 20 December 2021, numpy release version 1.21.5 that support Python 3.7
From comment section, by @sam, numpy 1.21.5 support Python 3.7. It was released after 1.22.0rc1 (the latest numpy version as the writing of the original post) that only support Python 3.8++.
Lesson learned from this experience, it would be better to use <,
pip install numpy<1.22.0
or
install_requires = [
"numpy<1.22.0", # lates version to support python 3.7
],
EDIT: 1.21.6 released on Apr 12, 2022.
UPDATE: Problem fixed. Thanks for the help, everyone.
For those having the same issue: My problem was that the virtual environment in PyCharm was preventing me from accessing my installation of numpy. If you are using PyCharm, be sure to use the in-built menus to install numpy from within the app (tutorial linked by someone in the comments below)!
Hello all,
I have been having some troubles attempting to install and use the NumPy module. I would like to create some arrays/matrices to use in the project I am working on. However, I cannot seem to get it to work...
So I looked it up, apparently I managed to grab a Python package that does not already have NumPy. That's fine, I can install it myself. But when I tried to type pip install numpy, it gives me the following error message (I tried just typing pip, pip install, but nothing seems to work):
Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> pip
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'pip' is not defined
>>> pip install
File "<stdin>", line 1
pip install
^
SyntaxError: invalid syntax
>>> pip install numpy
File "<stdin>", line 1
pip install numpy
^
SyntaxError: invalid syntax
>>>
I did some looking around on google, and found someone who said to try importing pip before attempting the install, and so I did just that in my python cmd window (this is the python shell that I can launch from my start menu, but I have also tried this on the regular windows cmd window), et voila, it installed it. Problem solved, or so it seemed...
So I then go to try and use import numpy and even from numpy import * in my script in PyCharm, but I get the following messages:
"No module named numpy" or "Unresolved reference 'numpy'."
What gives? Now, I will say that there seems to be something up with my PATH, because if I type py into my Windows cmd window, python loads up, but if I type out python, it pulls up the windows store. I remember that the shell said something about the PATH while "installing" numpy, but I didn't think anything of it because it still completed the installation, so I did not copy down the exact message.
Any help would be appreciated. I feel like it's something to do with the PATH stuff, or I somehow messed up my original python installation. But everything else works fine, I've been writing code for the past four days with no issues.