Python not found numpy

Error «Import Error: No module named numpy» on Windows

I have a very similar question to this question, but I am still one step behind. I have only one version of Python 3 installed on my Windows 7 (sorry) 64-bit system. I installed NumPy following this link — as suggested in the question. The installation went fine but when I execute

Check if there’s a numpy directory under C:\Python3x\Libs\site-packages (I might remember the path name wrong).

After trying many suggestions from various sites and similar questions, what worked for me was to uninstall all Python stuff and reinstall Anaconda only (see https://stackoverflow.com/a/38330088/1083292) The previous Python installation I had was not only redundant but only caused me trouble.

Check the libraries loaded by typing python -c ‘import sys; print sys.path’ — for me I realized, I used the wrong python version, had to execute the script with python3 instead of python 🙂

Читайте также:  Compile function in javascript

I had the same problem. I had numpy installed but was getting error ‘no module named numpy’. I used pyCharm instead of VSCode and it was solved. Not sure where was the problem.

27 Answers 27

After doing this, and seeing it install, it still says ImportError: No module named ‘numpy’. I tried installing a second time, it said it was already installed.

In my case, pip install numpy or pip3 install numpy did not work as they defaulted the installation to python 3’s package folders (for unknown reasons). I used pip2 install numpy to resolve the errors for «no module found. «.

pip3 install numpy» results in «Requirement already satisfied: numpy in c:\users\peter\appdata\local\programs\python\python36-32\lib\site-packages». You’d expect python’s «import numpy» would be able to find it, but no. ModuleNotFoundError: No module named ‘numpy’ So this answer may work in some narrow context, but not in general. There seems to be a lot more to do: configuring paths, etc.

@PeterLeopold Maybe you are having two versions of python in your system, and when you run pip3 install numpy the numpy package was installed into a specific version, and when you tried import numpy you used another python version. This happens to me all the time. Make sure that the environment / python version where you install/run the package is the same.

Support for Python 3 was added in NumPy version 1.5.0, so to begin with, you must download/install a newer version of NumPy.

python3 -m pip install numpy 

if you use pip3 install numpy by default it installs the numpy version 1.18.4, use specific version instead like this — pip install numpy==1.8.2 . check official doc for details- pypi.org/project/numpy/1.8.2

In my case I get «requirement already satisfied» when I install numpy. But I still get «module not found» when I try to use it.

At this time on windows, «py -m pip install numpy» is working for me. Seems python3 is no more relevent.

Installing Numpy on Windows

  1. Open Windows command prompt with administrator privileges (quick method: Press the Windows key. Type «cmd». Right-click on the suggested «Command Prompt» and select «Run as Administrator)
  2. Navigate to the Python installation directory’s Scripts folder using the «cd» (change directory) command. e.g. «cd C:\Program Files (x86)\PythonXX\Scripts»

This might be: C:\Users\\AppData\Local\Programs\Python\PythonXX\Scripts or C:\Program Files (x86)\PythonXX\Scripts (where XX represents the Python version number), depending on where it was installed. It may be easier to find the folder using Windows explorer, and then paste or type the address from the Explorer address bar into the command prompt.

You should see something similar to the following text appear as the package is downloaded and installed.

Collecting numpy Downloading numpy-1.13.3-2-cp27-none-win32.whl (6.7MB) 100% |################################| 6.7MB 112kB/s Installing collected packages: numpy Successfully installed numpy-1.13.3 

Источник

Как исправить: нет модуля с именем numpy

Одна распространенная ошибка, с которой вы можете столкнуться при использовании Python:

Import error: no module named ' numpy ' 

Эта ошибка возникает, когда Python не обнаруживает библиотеку NumPy в вашей текущей среде.

В этом руководстве представлены точные шаги, которые вы можете использовать для устранения этой ошибки.

Шаг 1: pip установить numpy

Поскольку NumPy не устанавливается автоматически вместе с Python, вам нужно будет установить его самостоятельно. Самый простой способ сделать это — использовать pip , менеджер пакетов для Python.

Вы можете запустить следующую команду pip для установки NumPy:

Для python 3 вы можете использовать:

В большинстве случаев это исправит ошибку.

Шаг 2: Установите пип

Если вы все еще получаете сообщение об ошибке, вам может потребоваться установить pip. Используйте эти шаги , чтобы сделать это.

Вы также можете использовать эти шаги для обновления pip до последней версии, чтобы убедиться, что он работает.

Затем вы можете запустить ту же команду pip, что и раньше, чтобы установить NumPy:

На этом этапе ошибка должна быть устранена.

Шаг 3: проверьте версию NumPy

После успешной установки NumPy вы можете использовать следующую команду для отображения версии NumPy в вашей среде:

pip show numpy Name: numpy Version: 1.20.3 Summary: NumPy is the fundamental package for array computing with Python. Home-page: https://www.numpy.org Author: Travis E. Oliphant et al. Author-email: None License: BSD Location: /srv/conda/envs/notebook/lib/python3.7/site-packages Requires: Required-by: tensorflow, tensorflow-estimator, tensorboard, statsmodels, seaborn, scipy, scikit-learn, PyWavelets, patsy, pandas, matplotlib, Keras-Preprocessing, Keras-Applications, imageio, h5py, bqplot, bokeh, altair Note: you may need to restart the kernel to use updated packages. 

Дополнительные ресурсы

В следующих руководствах объясняется, как исправить другие распространенные проблемы в Python:

Источник

No module named ‘numpy’: Visual Studio Code

Also, is there python interactive window in VS Code? How to open it.

I don’t see where you said you installed numpy. (Does it come with Anaconda or Visual Studio Code? I’m not familiar with those.)

see solution stackoverflow.com/questions/29987840/… for using anaconda python environment and python libraries.

15 Answers 15

Changing python environment in VS code helped me. Default the visual studio code takes original Python environment, it requires numpy to install. If you have anaconda python (numpy comes with it) installed, you could switch the original python environment to anaconda python environment in visuals studio code. This can be done from the command palette Ctrl+Shift+P in visual studio

Check this link for how to switch from original python to anaconda python environment, specifically:

Snippet from VSCode instructions enter image description here

I’m getting the same error even after creating a separate environment via anaconda and then choosing that environment in VS Code

You may not have numpy installed on the version of python you are running.

Is the printed version Anaconda? If you installed Anaconda python, it should come with numpy already installed. If it turns out to be another version of python you are accessing inside Visual Studio Code that doesn’t have numpy installed, then that’s what you need to fix.

The version of python that is called depends on which version of python comes up in your PATH variable first. Type into a terminal: echo $PATH . The output should look like this with Anaconda bin first: /Users/jlzhang/anaconda/bin:/usr/local/bin:/usr/bin:/bin

If you do not have Anaconda bin first, you can add this to your ~/.bashrc file: echo

# Use Anaconda python

export PATH=»/Users/jlzhang/anaconda/bin:$PATH»

Restart a terminal and Visual Studio Code and see if you are now running Anaconda python.

Hope it helps/ Did it work?

Источник

ModuleNotFoundError: No module named numpy

Stephen Allwright

ModuleNotFoundError: No module named numpy

The error “ModuleNotFoundError: No module named numpy» is a common error experienced by data scientists when developing in Python. The error is likely an environment issue whereby the numpy package has not been installed correctly on your machine, thankfully there are a few simple steps to go through to troubleshoot the problem and find a solution.

ModuleNotFoundError: No module named numpy

Your error, whether in a Jupyter Notebook or in the terminal, probably looks like one of the following:

No module named ‘numpy’
ModuleNotFoundError: No module named ‘numpy’

In order to find the root cause of the problem we will go through the following potential fixes:

  1. Upgrade pip version
  2. Upgrade or install numpy package
  3. Check if you are activating the environment before running
  4. Create a fresh environment
  5. Upgrade or install Jupyer Notebook package

Are you installing packages using Conda or Pip package manager?

It is common for developers to use either Pip or Conda for their Python package management. It’s important to know what you are using before we continue with the fix.

If you have not explicitly installed and activated Conda, then you are almost definitely going to be using Pip. One sanity check is to run conda info in your terminal, which if it returns anything likely means you are using Conda.

Upgrade or install pip for Python

First things first, let’s check to see if we have the up to date version of pip installed. We can do this by running:

Upgrade or install numpy package via Conda or Pip

The most common reason for this error is that the numpy package is not installed in your environment or an outdated version is installed. So let’s update the package or install it if it’s missing.

Activate Conda or venv Python environment

It is highly recommended that you use isolated environments when developing in Python. Because of this, one common mistake developers make is that they don’t activate the correct environment before they run the Python script or Jupyter Notebook. So, let’s make sure you have your correct environment running.

Create a new Conda or venv Python environment with numpy installed

During the development process, a developer will likely install and update many different packages in their Python environment, which can over time cause conflicts and errors.

Therefore, one way to solve the module error for numpy is to simply create a new environment with only the packages that you require, removing all of the bloatware that has built up over time. This will provide you with a fresh start and should get rid of problems that installing other packages may have caused.

Upgrade Jupyter Notebook package in Conda or Pip

If you are working within a Jupyter Notebook and none of the above has worked for you, then it could be that your installation of Jupyter Notebooks is faulty in some way, so a reinstallation may be in order.

Best practices for managing Python packages and environments

Managing packages and environments in Python is notoriously problematic, but there are some best practices which should help you to avoid package the majority of problems in the future:

  1. Always use separate environments for your projects and avoid installing packages to your root environment
  2. Only install the packages you need for your project
  3. Pin your package versions in your project’s requirements file
  4. Make sure your package manager is kept up to date

References

Stephen Allwright

Stephen Allwright Twitter

I’m a Data Scientist currently working for Oda, an online grocery retailer, in Oslo, Norway. These posts are my way of sharing some of the tips and tricks I’ve picked up along the way.

Источник

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