numpy installed but can' use
Hi, successfully installed numpy but i cant use it (numpy is not defined). for example: Python 2.5.1 (r251:54863, Nov 25 2007, 02:18:29) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd7 Type "help", "copyright", "credits" or "license" for more information.
from numpy import * numpy.__version__ Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'numpy' is not defined
any hints ? regards, -- -dikshie-
dikshie wrote:
from numpy import * numpy.__version__ Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'numpy' is not defined
any hints ?
yes, you did an "import *", which means "bring all the names in the numpy module into this namespace. There is no name: "numpy" in the numpy module -- it's the name of the module itself. Try: import numpy numpy.__version__ then you can use the stuff in numpy this way: MyArray = numpy.array(some_stuff) Or, if you don't want to type quite so much, use something like: import numpy as N N.__version__ MyArray = N.array(some_stuff) "Namespaces are one honking great idea -- let's do more of those!" -- http://www.python.org/dev/peps/pep-0020/ -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
On Dec 29, 2007 1:57 AM, Christopher Barker
numpy module into this namespace. There is no name: "numpy" in the numpy module -- it's the name of the module itself. Try:
import numpy numpy.__version__
so import numpy and from numpy import * are different ? -dikshie-
dikshie wrote:
On Dec 29, 2007 1:57 AM, Christopher Barker
wrote: the names in the numpy module into this namespace. There is no name: "numpy" in the numpy module -- it's the name of the module itself. Try:
import numpy numpy.__version__
so import numpy and from numpy import * are different ?
Yes, the key is what "names" are "imported" into the current namespace (what names are visible to your code). import numpy loads the module and places the name "numpy" in the current namespace which points to the loaded module. from numpy import * loads the module and places all the "exported" names from numpy into the current namespace. The list of exported names, however, does not include the module numpy itself and so the current namespace does not get a "numpy" entry. -Travis O.
On Dec 29, 2007 1:38 PM, Travis E. Oliphant
Yes, the key is what "names" are "imported" into the current namespace (what names are visible to your code).
import numpy
loads the module and places the name "numpy" in the current namespace which points to the loaded module.
from numpy import *
loads the module and places all the "exported" names from numpy into the current namespace. The list of exported names, however, does not include the module numpy itself and so the current namespace does not get a "numpy" entry.
i see. thank you very much for the explanation. -dikshie-
On Sat, 29 Dec 2007, dikshie apparently wrote:
so import numpy and from numpy import * are different ?
http://docs.python.org/tut/node8.html hth, Alan Isaac
dikshie wrote:
Hi, successfully installed numpy but i cant use it (numpy is not defined). for example:
Python 2.5.1 (r251:54863, Nov 25 2007, 02:18:29) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd7 Type "help", "copyright", "credits" or "license" for more information.
from numpy import * numpy.__version__ Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'numpy' is not defined
any hints ?
regards,
You did not import numpy, you imported all of its contents. Try: import numpy numpy.__version__ Eric
participants (5)
-
Alan G Isaac
-
Christopher Barker
-
dikshie
-
Eric Firing
-
Travis E. Oliphant