Manav Dutta
Manav Dutta

Reputation: 171

Importing numpy

So I have installed numpy and imported it like this:

from django.template import RequestContext
from django.shortcuts import render_to_response
from django.http import HttpResponse
from main.models import Operation, SendText, SendCall, LookUpNearestWorker, EnterNewWorker
from main.forms import sendText, sendCall, lookUpNearestWorker, enterNewWorker
import subprocess
import numpy

But I get an error saying that numpy can't be found. Can you guys help me with this one?

Upvotes: 1

Views: 298

Answers (2)

Tom
Tom

Reputation: 828

try

python setup.py install --prefix=/DirectoryYouWantToInstallOn/

and

export PYTHONPATH=/DirectoryYouWantToInstallOn/:$PYTHONPATH

on your terminal

adding

export PYTHONPATH=/DirectoryYouWantToInstallOn/:$PYTHONPATH

to your ~/.profile file might make things lot easier.

Upvotes: 0

Ryan G.
Ryan G.

Reputation: 305

Python uses a list of directories to search for importable modules.

import sys
print sys.path

These are the directories that Python will search (in order) when it is looking for numpy. If numpy is installed correctly, it will be located in one of these directories. How Python searches for modules is detailed here and sys.path here

Pip, Python's package manager, can also give us a nice list of packages that it recognizes (plus the version numbers) You can get this list two ways: via the command line, or using the python interpreter. Both commands will output a list of installed packages

$ pip freeze

or, in an interactive interpreter:

import pip
pip.get_installed_distributions()

If numpy appears in these lists, then python shouldn't have a problem importing it, unless numpy wasn't installed correctly.

It is possible that you might have multiple Python installations. In that case, you need to verify that Python is searching the right paths for numpy.

Upvotes: 1

Related Questions