python newbie: importing numpy module in eclipse

2019-02-23 12:09发布

问题:

I'm trying to run a simple python program in eclipse. This is the first time that I'm importting any module.

So I downloaded: numpy and pylab (I'm using a mac) restarted my eclipse and the red line below the

import numpy
import pylab

disappeared so I understood that the reference to that module is ok.

Problem is that I still see red line below the code and wonder why? I have to stress out that I believe numpy was already 'pre-installed' I just upgraded the version (using 1.5.1-py2.7).

Can anyone tell what should I do to run this code?

my interpreter setting on eclipse:

回答1:

If you are using PyDev, you should first have to go to Preferences, then Pydev, then Interpreter Python and then Libraries to add NumPy.

Else, verify that you have NumPy installed, from the interpreter, just call from numpy import *

Edit:

Also check you already have Matplotlib installed, the error you are getting on the console points to that being the cause, you can download Matplotlib here.



回答2:

I recently installed Anaconda3 and just started learning how to use Pandas and I wanted to be able to work with Pandas in Eclipse as well.

I first tried adding a reference to the site-libraries at:

C:\Anaconda3\Lib\site-packages

And it seemed to work by allowing me to import numpy and pandas. However, since I had just used conda to update everything, my Python34 interpreter seemed to fail when I tried running some code and numpy was looking for my Python35 installation. For some reason this was located at:

C:\Users\myname\AppData\Local\Programs\Python\Python35-32

However, Anacondas installed another version somewhere else. By going into:

Windows > Preferences > PyDev > Interpreters > Python Interpreter

and clicking on Quick Auto-Config it found my Anacondas version of Python35 and then I just had to figure out how to make my current project use the Python35 interpreter.

Hint: To do this, you need to go into the Project properties by opening the project and choosing File > Properties or right-click the project to choose Properties.



回答3:

Simply removed the old numpy and installed version 6. located here

Another way to circumvent this problem is to use pip install numpy check how to install pip