No module named numpy python linux

[Solved] No Module Named Numpy in Python

Python has many external modules which are helpful to manage data efficiently. Numpy is one of those modules to handle arrays or any collection of data with ease. With many available methods, you can directly modify and edit the data according to your need. Even many universities, teach numpy as a part of their programming course. But many times, the users face, No Module Named Numpy Error. In this post, we’ll have a look at the causes and solutions for this error.

No Module Named Numpy is one of the persistent errors if you have multiple pythons installed or a virtual environment set up. This error mainly arises due to the unavailability of files in the Python site-packages. This error is easily solved by installing numpy in your working environment. But as installing numpy in the working environment is a tricky job, this error is one of the most irritating ones.

What is No Module Named Numpy?

Whenever an external module (numpy) is imported in python, it checks the package in the site packages folder if it’s available. If not, then ImportError No Module Named Numpy is raised. Moreover, if your local files in your directly have numpy.py, it can cause these issues too.

Although fixing this error requires a simple command to be used, it still can harass programmers if they are using a virtual environment. In the following section, we’ll learn about why this error is generated and the causes for it.

Why do I get No Module Named Numpy?

There are known reasons for the cause of this error. The most observed reason is due to the unavailability of Numpy in your working directory. But that’s not it, if your python file is named numpy.py, it can throw this error too. So the question arises –

Am I the only one facing this error?

No, thousands of programmers face this error either due to their IDE’s environment or they just haven’t installed Numpy.

Causes for No Module Named Numpy

As we mentioned earlier, there are some known causes for this No Module Named Numpy error to appear. Some of them are due to your mistake and some of them are not. Following are the most probable cause of this error –

Numpy Not Installed

Can you run games without installing them? No. Similarly, to use the numpy in your python program, you need to install it first. Numpy is not included in your build-in modules for python. As a result, you need to tell the package management system (pip) to install it!

Working on different Virtual Environment

Often, many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm tend to install their own virtual environment of python to keep things clean and separated from your global python.

As a result, even if you have Numpy installed in your global python, you cannot use it in your virtual environment since it has separate package management. There are different methods to install numpy on each of these IDEs, all of them are mentioned in the next section.

Solutions for No Module Named Numpy

Following are the respective solutions according to your OS or IDEs for No Module Named Numpy error –

Читайте также:  Hklm software wow6432node microsoft windows currentversion run

Windows

Installing modules can be tricky on Windows sometimes. Especially, when you have path-related issues. First of all, make sure that you have Python Added to your PATH (can be checked by entering python in command prompt). Follow these steps to install numpy in Windows –

  1. Firstly, Open Command Prompt from the Start Menu.
  2. Enter the command pip install numpy and press Enter.
  3. Wait for the installation to finish.
  4. Test the installation by using import numpy command in Python Shell.

Ubuntu or Linux or Mac

Generally, in Ubuntu, there are multiple versions of Python installed. This causes great confusion in installing Numpy. Check your version of python by entering the command python —version in your terminal. Follow these steps to install numpy in Linux –

  1. Firstly, Open terminal in your Linux machine.
  2. Enter the command pip install numpy in the terminal and hit Enter (Use pip3 if you have multiple pythons installed).

Anaconda

Anaconda installs its own conda environment to run python. This environment is separated from your outside installed python and can lead to import No Module Named Numpy errors. Usually, numpy is already installed in anaconda but to install numpy again in Anaconda –

  1. Open Anaconda Prompt from Start Menu.
  2. Enter the command conda install numpy and Hit Enter.
  3. Wait for the setup to complete, and restart the Anaconda application once.

Jupyter

If you have installed Jupyter from the conda environment, it’ll use Anaconda’s virtual environment for the execution of python codes. Following is the way to install numpy in Jupyter Notebook –

  1. Open Anaconda Prompt and enter conda install numpy .
  2. Restart Jupyter Notebook and Anaconda.

VsCode

In VsCode, the Integrated Terminal uses the %PATH% of python.exe to run the python programs by default. As a result, if don’t have numpy installed in your python, it’ll throw ImportError No Module Named Numpy. Either you need to change the environment to Anaconda’s environment or install numpy on the default environment. The process to install numpy on the default environment is already mentioned in the above (Windows) section.

PyCharm

PyCharm has its own set of mini Anaconda environments. If numpy is missing in this environment, it’ll throw an error No Module Named Numpy. To install numpy in Pycharm –

  1. Firstly, Open Settings of Pycharm.
  2. Under Python Interpreter, press the Python Packages option.
  3. Search for numpy in the list and select install. If it’s already installed, check if it has an update available.
  4. Wait for its finishes and restarts your PyCharm once.

No Module Named Numpy Still Not Resolved?

Tried all the above methods and still import numpy not working? Then there might be some python related issues with your computer. But don’t be sad, we’ve got a universal solution for you!

Using Google Colab for your Python Projects will prevent you to install numpy on your system. Colab has its own powerful virtual environment with thousands of modules preinstalled and numpy is one of them. Follow these steps to use Google Colab for numpy –

  1. Firstly, log in to your Google Account.
  2. Head over to colab.research.google.com and start a new notebook.
  3. Test your program by running import numpy code.

Some Other Child Modules Error

Numpy has many other child libraries which can be installed externally. All of these libraries look like a part of numpy, but they need to be installed separately. Following are some of the examples –

No module named numpy.core._multiarray_umath

This error can be resolved by using p ip install numpy —upgrade command and upgrading your numpy version. Other libraries like TensorFlow and scikit-learn depend on new APIs inside the module, that’s why your module needs to be updated.

No module named numpy.testing.nosetester

Run the following commands in your terminal to resolve this error –

Читайте также:  Grand theft auto san andreas linux

No module named numpy.distutils._msvccompiler

Use Python version 3.7 to solve this error. The newer versions 3.8 and 3.9 are currently unsupported in some of the numpy methods.

See Also

Final Words

Errors are part of a programmer’s life and they’ll never leave. Numpy has already blessed us with many powerful methods to easily handle data. But sometimes, we’ll get import errors and possibly other errors too. We’ve mentioned all possible solutions for the No Module Named Numpy in the post.

Источник

Ошибка импорта: нет модуля с именем numpy

У меня очень похожий вопрос к этот вопрос, но все еще на шаг позади. У меня есть только одна версия Python 3, установленная на моем Windows 7 (жаль) 64-разрядная система.

Я установил numpy после этого ссылке — как предложено в вопросе. Установка прошла нормально, но когда я выполняю

Я получил следующую ошибку:

ошибка импорта: нет модуль с именем и NumPy

Я знаю, что это, вероятно, супер основной вопрос, но я все еще учусь.

15 ответов

поддержка Python 3 была добавлена в NumPy версии 1.5.0, поэтому для начала вы должны загрузить / установить более новую версию NumPy.

Вы можете просто использовать

или для python3 используйте

Я думаю, что что-то не так с установкой numpy. Вот мои шаги, чтобы решить эту проблему.

  1. зайти на этот сайт, чтобы скачать нужный пакет: http://sourceforge.net/projects/numpy/files/
  2. распаковать пакет
  3. перейти к документу
  4. используйте эту команду для установки numpy: python setup.py install

У меня также была эта проблема (ошибка импорта: нет модуля с именем numpy), но в моем случае это была проблема с моими переменными пути в Mac OS X. Я сделал более раннее редактирование моего .bash_profile файл, который вызвал пути для моей установки Anaconda (и другие), чтобы не быть добавлены должным образом.

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

вы установили версию Numpy для Python 2.6-поэтому вы можете использовать ее только с Python 2.6. Вы должны установить Numpy для Python 3.x, например: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/numpy-1.6.1-win32-superpack-python3.2.exe/download

У меня тоже была эта проблема после установки Numpy. Я решил это, просто закрыв интерпретатор Python и снова открыв его. Если у кого-то еще есть эта проблема, возможно, это сэкономит несколько минут!

1) пожалуйста, установите numpy через командную строку (в windows) 2)Перейдите в папку Scripts и введите следующую команду

C:\Python27\Scripts>pip установить numpy

установка начинается как ниже: Сбор и NumPy Скачивание numpy-1.13.3-2-cp27-none-win32.whl (6,7 МБ) 100% |################################| 6.7 Мб 112кб/с Установка собранных пакетов: numpy Успешно установлен numpy-1.13.3

Я не уверен, почему я получаю эту ошибку, но pip3 uninstall numpy затем pip3 install numpy решил проблему для меня.

для установки NumPy через Anaconda (используйте команды ниже):

  • conda install — c conda-forge numpy
  • conda install — c conda-forge / этикетка / сломанный numpy

Я тоже столкнулся с вышеуказанной проблемой с phyton 3 при настройке python для машинного обучения.

я следовал приведенным ниже шагам : —

установить python-2.7.13.компания MSI

загружено: — — numpy-1.13.1 + mkl-cp27-cp27m-win32.whl

установки numpy: очко установите numpy-1.13.1+mkl-cp27-cp27m-win32.whl

установка scipy: pip установить scipy-0.18.0-cp27-cp27m-win32.whl

вы можете проверить правильность, используя ниже cmds: —

это проблема версии numpy, пожалуйста, проверьте $CAFFE_ROOT / python / требование.формат txt. Затем exec: sudo apt-get install python-numpy>=x.X. x, эта проблема будет sloved.

те, кто использует xonsh , do xpip install numpy .

Я получил это, хотя я знал, что numpy был установлен и безуспешно пробовал все советы выше. Исправление для меня было удалить как np и непосредственно обратитесь к модулям . (python 3.4.8 на Centos) .

попробовав много предложений с разных сайтов и подобных вопросов, мне удалось удалить все материалы Python и переустановить только Anaconda (см. https://stackoverflow.com/a/38330088/1083292)

предыдущая установка Python у меня была не только избыточной, но и вызвала у меня проблемы.

Источник

ImportError: No module named numpy.distutils.core (Ubuntu xgboost installation) #820

Comments

sidsvash26 commented Feb 11, 2016

I am a new user to Ubuntu and recently downloaded Ubuntu 14.04 desktop version alongside Windows 10.

Читайте также:  White room with no doors or windows

My PC configs are: 4 GB RAM, 64 bit

I installed Anaconda using the following command from the terminal (after downloading from website):
bash Anaconda3-2.5.0-Linux-x86_64.sh

Installation was successful.

  1. Installed a recent GNU C++ compiler —>successful
  2. git clone —recursive https://github.com/dmlc/xgboost cd xgboost; make -j4
    Building was also successful and I could build ‘libxgboost.so’
  3. sudo apt-get install python-setuptools (Successful)
  4. cd python-package
  5. sudo python setup.py install

The 5. command returns an error after a number of lines. The error is as follows:

‘ImportError: No module named numpy.distutils.core’

Can anyone suggest how to get rid of this error so that I can install xgboost ?

The full log after step 5. is as follows:

/xgboost/python-package$ sudo python setup.py install
Install libxgboost from: [‘/home/sidvash/xgboost/python-package/xgboost/../../lib/libxgboost.so’]
running install
running bdist_egg
running egg_info
writing requirements to xgboost.egg-info/requires.txt
writing xgboost.egg-info/PKG-INFO
writing top-level names to xgboost.egg-info/top_level.txt
writing dependency_links to xgboost.egg-info/dependency_links.txt
reading manifest file ‘xgboost.egg-info/SOURCES.txt’
reading manifest template ‘MANIFEST.in’
warning: no files found matching ‘‘ under directory ‘xgboost/include’
warning: no files found matching ‘‘ under directory ‘xgboost/src’
warning: no previously-included files matching ‘xgboost/build/
‘ found anywhere in distribution
warning: no previously-included files matching ‘xgboost/.o’ found anywhere in distribution
warning: no previously-included files matching ‘
.pyo’ found anywhere in distribution
warning: no previously-included files matching ‘_.pyc’ found anywhere in distribution
writing manifest file ‘xgboost.egg-info/SOURCES.txt’
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/xgboost
copying build/lib.linux-x86_64-2.7/xgboost/libpath.py -> build/bdist.linux-x86_64/egg/xgboost
copying build/lib.linux-x86_64-2.7/xgboost/VERSION -> build/bdist.linux-x86_64/egg/xgboost
copying build/lib.linux-x86_64-2.7/xgboost/build-python.sh -> build/bdist.linux-x86_64/egg/xgboost
copying build/lib.linux-x86_64-2.7/xgboost/init.py -> build/bdist.linux-x86_64/egg/xgboost
copying build/lib.linux-x86_64-2.7/xgboost/training.py -> build/bdist.linux-x86_64/egg/xgboost
copying build/lib.linux-x86_64-2.7/xgboost/compat.py -> build/bdist.linux-x86_64/egg/xgboost
copying build/lib.linux-x86_64-2.7/xgboost/core.py -> build/bdist.linux-x86_64/egg/xgboost
copying build/lib.linux-x86_64-2.7/xgboost/sklearn.py -> build/bdist.linux-x86_64/egg/xgboost
copying build/lib.linux-x86_64-2.7/xgboost/plotting.py -> build/bdist.linux-x86_64/egg/xgboost
byte-compiling build/bdist.linux-x86_64/egg/xgboost/libpath.py to libpath.pyc
byte-compiling build/bdist.linux-x86_64/egg/xgboost/init.py to init.pyc
byte-compiling build/bdist.linux-x86_64/egg/xgboost/training.py to training.pyc
byte-compiling build/bdist.linux-x86_64/egg/xgboost/compat.py to compat.pyc
byte-compiling build/bdist.linux-x86_64/egg/xgboost/core.py to core.pyc
byte-compiling build/bdist.linux-x86_64/egg/xgboost/sklearn.py to sklearn.pyc
byte-compiling build/bdist.linux-x86_64/egg/xgboost/plotting.py to plotting.pyc
installing package data to build/bdist.linux-x86_64/egg
running install_data
copying /home/sidvash/xgboost/python-package/xgboost/../../lib/libxgboost.so -> build/bdist.linux-x86_64/egg/xgboost
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying xgboost.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xgboost.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xgboost.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xgboost.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xgboost.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xgboost.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
creating ‘dist/xgboost-0.4-py2.7.egg’ and adding ‘build/bdist.linux-x86_64/egg’ to it
removing ‘build/bdist.linux-x86_64/egg’ (and everything under it)
Processing xgboost-0.4-py2.7.egg
removing ‘/usr/local/lib/python2.7/dist-packages/xgboost-0.4-py2.7.egg’ (and everything under it)
creating /usr/local/lib/python2.7/dist-packages/xgboost-0.4-py2.7.egg
Extracting xgboost-0.4-py2.7.egg to /usr/local/lib/python2.7/dist-packages
xgboost 0.4 is already the active version in easy-install.pth

Installed /usr/local/lib/python2.7/dist-packages/xgboost-0.4-py2.7.egg
Processing dependencies for xgboost==0.4
Searching for scipy
Reading https://pypi.python.org/simple/scipy/
Best match: scipy 0.17.0
Downloading https://pypi.python.org/packages/source/s/scipy/scipy-0.17.0.zip#md5=28a4fe29e980804db162524f10873211
Processing scipy-0.17.0.zip
Writing /tmp/easy_install-2YPTnH/scipy-0.17.0/setup.cfg
Running scipy-0.17.0/setup.py -q bdist_egg —dist-dir /tmp/easy_install-2YPTnH/scipy-0.17.0/egg-dist-tmp-z4NE5c
Traceback (most recent call last):
File «setup.py», line 39, in
url=’https://github.com/dmlc/xgboost’)
File «/usr/lib/python2.7/distutils/core.py», line 151, in setup
dist.run_commands()
File «/usr/lib/python2.7/distutils/dist.py», line 953, in run_commands
self.run_command(cmd)
File «/usr/lib/python2.7/distutils/dist.py», line 972, in run_command
cmd_obj.run()
File «/usr/lib/python2.7/dist-packages/setuptools/command/install.py», line 73, in run
self.do_egg_install()
File «/usr/lib/python2.7/dist-packages/setuptools/command/install.py», line 96, in do_egg_install
cmd.run()
File «/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py», line 381, in run
self.easy_install(spec, not self.no_deps)
File «/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py», line 597, in easy_install
return self.install_item(None, spec, tmpdir, deps, True)
File «/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py», line 648, in install_item
self.process_distribution(spec, dist, deps)
File «/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py», line 694, in process_distribution
[requirement], self.local_index, self.easy_install
File «/usr/lib/python2.7/dist-packages/pkg_resources.py», line 620, in resolve
dist = best[req.key] = env.best_match(req, ws, installer)
File «/usr/lib/python2.7/dist-packages/pkg_resources.py», line 858, in best_match
return self.obtain(req, installer) # try and download/install
File «/usr/lib/python2.7/dist-packages/pkg_resources.py», line 870, in obtain
return installer(requirement)
File «/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py», line 616, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File «/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py», line 646, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File «/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py», line 834, in install_eggs
return self.build_and_install(setup_script, setup_base)
File «/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py», line 1040, in build_and_install
self.run_setup(setup_script, setup_base, args)
File «/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py», line 1025, in run_setup
run_setup(setup_script, args)
File «/usr/lib/python2.7/dist-packages/setuptools/sandbox.py», line 50, in run_setup
lambda: execfile(
File «/usr/lib/python2.7/dist-packages/setuptools/sandbox.py», line 100, in run
return func()
File «/usr/lib/python2.7/dist-packages/setuptools/sandbox.py», line 52, in
<'file‘:setup_script, ‘name‘:’main‘>
File «setup.py», line 265, in

File «setup.py», line 253, in setup_package

ImportError: No module named numpy.distutils`_

The text was updated successfully, but these errors were encountered:

Источник

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