无法在 PyDev 中导入 matplotlib
我正在使用 Ubuntu 10.04,并已成功配置 PyDev 以使用 Python,并编写了一些简单的示例项目。现在我正在尝试合并 numpy 和 matplotlib。我已经安装了 numpy,并且在 PyDev 中我不需要更改任何路径等,并且在安装 numpy 后,我可以自动导入 numpy,没有任何问题。但是,使用 matplotlib 执行相同的过程并没有起作用。如果我从命令行运行 Python,那么 import matplotlib 就可以正常工作。但在 PyDev 中,当我尝试导入 matplotlib 时,我只是收到标准错误,无法找到 matplotlib。
由于 numpy 不需要对 PYTHONPATH 进行任何更改,我觉得 matplotlib 也不需要,所以任何人都可以帮助我弄清楚为什么 matplotlib 无法从我现有的项目中访问,而 numpy 可以访问?感谢您的任何帮助。
I am using Ubuntu 10.04 and have successfully configured PyDev to work with Python and have written a few simple example projects. Now I am trying to incorporate numpy and matplotlib. I have gotten numpy installed and within PyDev I did not need to alter any paths, etc., and after the installation of numpy I was automatically able to import numpy with no problem. However, following the same procedure with matplotlib hasn't worked. If I run Python from the command line, then import matplotlib works just fine. But within PyDev, I just get the standard error where it can't locate matplotlib when I try import matplotlib.
Since numpy didn't require any alteration of the PYTHONPATH, I feel that neither should matplotlib, so can anyone help me figure out why matplotlib isn't accessible from within my existing project while numpy is? Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来你为 Pydev 设置的解释器没有指向适当的 python 版本(你已经安装了 mpl 和 np)。在终端中,输入
python
的效果可能等同于env python
; pydev 可能没有使用这个解释器。但是,如果 pydev 解释器指向正确的位置,您可能只需重新哈希解释器(基本上,重新设置它)即可显示 mpl。
您可以在终端中尝试此操作,看看结果是否不同:
python -c 'import platform; print platform.python_version()'
${PYTHONPATH}/python -c '导入平台;打印平台.python_version()'
Sounds like the interpreter you setup for Pydev is not pointing to the appropriate version of python (that you've install mpl and np). In the terminal, it's likely the effect of typing
python
is tantamount toenv python
; pydev might not be using this interpreter.But, if the pydev interpreter is pointed to the right location, you might simply have to rehash the interpreter (basically, set it up again) to have mpl show up.
You could try this in the terminal and see if the results are different:
python -c 'import platform; print platform.python_version()'
${PYTHONPATH}/python -c 'import platform; print platform.python_version()'
我将 numpy 添加到强制内置函数中,并且工作得非常顺利。
I added numpy to the Forced Builtins and worked like charm.
右键单击您的项目,然后转到属性,然后单击 PyDev - Interpreter/Grammar,单击“单击此处配置未列出的解释器”。然后选择您正在使用的解释器,单击“使用 pip 安装/卸载”,然后输入 matplotlib for .然后重新启动 Eclipse 就可以了。
Right click your project, then go to properties, then click PyDev - Interpreter/Grammar, click "Click here to configure an interpreter not listed". Then select the interpreter you are using, click Install/Uninstall with pip, then enter matplotlib for . Then restart Eclipse and it should work.