Debian No Module Named Numpy

Debian No Module named numpy

As you can tell from your which result, the python you are running when just typing python is /usr/local/bin/python.

It's a python you probably installed there yourself, as Debian will never put anything in /usr/local by itself (except for empty directories).

How? Well, by running pip for instance. As a rule, you should never use pip outside of a virtualenv, because it will install stuff on your system that your package manager will not know about. And maybe break stuff, like what you see on your system.

So, if you run /usr/bin/python, it should see the numpy package you installed using your package manager.

How to fix it? Well, I would clear anything in /usr/local (beware, it will definitely break stuff that rely on things you installed locally). Then I would apt-get install python-virtualenv, and always work with a virtualenv.

$ virtualenv -p /usr/bin/python env
$ . env/bin/activate
(env)$ pip install numpy
(env)$ python
>>> import numpy
>>>

That way, packages will be installed in the env directory. You do all this as a regular user, not root. And your different projects can have different environments with different packages installed.

ImportError: No module named numpy in Debian OS

As per request from the OP.

For any executable file, bash reads the first line with the shebang or #!... to extract the interpreter for the script. If it does not find the shebang, it will try to service the file type using the magic numbers and then use the relevant loading method. That's why running an ELF binary does not require you to specify the executor.

Now, virtual environments works by overriding your bash search path, i.e. when you type a command, where should it look. For example, if you have a binary name ls where should it find it to load from. It refers to your search path or the $PATH variable and scans the directories sequentially and stops at the first match. Virtual environment will prepend it's path to the $PATH when you do a source .venv. The source command simply tells your bash session to apply the bash directives from the .venv file.

In your source file, you have supplied the interpreter using the shebang directive to the global installation of python which does not have numpy in it's module list so it fails.

If you run it using python script.py, because the $PATH is overridden by virtual env, the shell will find the python version of virtual env first than the global one which has your numpy module.

Why does /usr/bin/env python work ? Because it's going to refer to your $PATH in your environment variable (which is modified by virtual env) and will find the correct python installation.

Sample Image

Error Import Error: No module named numpy on Windows

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.

Or simply using pip:

python3 -m pip install numpy

ImportError: No module named numpy on Ubuntu after Numpy Installation

try from the command line,

pip install numpy --user

then you should be able to import numpy in a new python session.

but to really handle this sorta thing well, you should create sandboxed environments for projects where you specify not the packages and even the python version used. that way you don't accidentally install a package in the wrong path, or have it installed for python2 but not have it available if your default python is python3, that sorta thing.

if you download anaconda, you get a great way to manage all that:
https://conda.io/docs/using/envs.html

otherwise you can use venv (stands for 'virtual environment'): https://docs.python.org/3/library/venv.html

UPDATE: and now pipenv, from the maker of Requests (Kenneth Reitz)

ImportError: No module named numpy

You do not mention where you are running the commands. For the commands, I guess you are using Ubuntu 12.10.

In Ubuntu 12.10 the default is Python3 (check it with python --version). So that, when you ran python setup ..., you are running it with the default python available. For what it is worth, weblog 3.3 requires Python 2.5, 2.6 or 2.7.

Also, you can check where python-numpy was installed (check it with dpkg -L python-numpy).

My shot out of the blue would be:

$ python2.7 setup.py install

If you do not have installed python2.7, you should install it (likely, the shell is going to suggest it).

Python: No module named 'numpy'

Anaconda installs its own conda environment to run python. Probably VS Code can't access. Try this command;

python -mpip install numpy

If your python file named numpy.py, you can get this error too.

If doesn't work maybe you can try to change the environment to Anaconda environment.
check this

Pycharm throws: ModuleNotFoundError: No module named 'numpy' error even though Numpy is installed

pycharm creates its own virtual environment. But you have installed numpy in your system environment.
just open pychram console and run pip install numpy



Related Topics



Leave a reply



Submit