Packages not working, using Anaconda

2019-09-02 03:36发布

问题:

I have installed Anaconda for Windows. It's on my work PC, so I chose the option "Just for Me" as I don't have admin rights.

Anaconda is installed on the following directory:

c:\Users\huf069\AppData\Local\Continuum\Anaconda

The Windows installer has added this directory (+ the Anaconda\Scripts directory) to the System path.

I can launch Python but trying to run x = randn(100,100) gives me a Name Error: name 'randn' is not defined, whereas, as I understood, this command should work when using Anaconda, as the numpy package is included.

it works fine if I do:

import numpy
numpy.random.randn(100,100)

Anyone understand what could be happening ?

回答1:

I can launch Python, but trying to run x = randn(100,100) gives me a Name Error: name 'randn' is not defined, whereas, as I understood, this command should work when using Anaconda, as the numpy package is included

The Anaconda distribution comes with the numpy package included, but still you'll need to import the package. If you want to use the randn() function without having to call the complete name, you can import it to your local namespace:

from numpy.random import randn
x = randn(100,100)

Otherwise, the call numpy.random.randn is your way to go.

You might want tot take a look at the Modules section of the Python Tutorial.