gpt4 book ai didi

Python 2.7 和 PyDev - matplotlib 和 NumPy 不工作

转载 作者:行者123 更新时间:2023-11-28 17:51:05 24 4
gpt4 key购买 nike

我正在尝试使用 Python 2.7 和带有 PyDev 插件的 Eclipse 让 matplotlib 在 Windows 7(64 位)下工作。我从 http://www.lfd.uci.edu/~gohlke/pythonlibs/ 安装了 NumPy .

问题是当我在 Eclipse 中编写以下代码时:

import matplotlib.pyplot as plt

plt.figure()

我收到以下错误:

Traceback (most recent call last):
File "C:\Users\davedove\Documents\eclipseWorkspace\python.graphExample\example.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 104, in <module>
import os, re, shutil, subprocess, sys, warnings
File "C:\Python27\lib\shutil.py", line 12, in <module>
import collections
File "C:\Python27\Lib\site-packages\matplotlib\collections.py", line 12, in <module>
import numpy as np
File "C:\Python27\lib\site-packages\numpy\__init__.py", line 147, in <module>
import add_newdocs
File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 4, in <module>
from type_check import *
File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 40, in <module>
from numpy.testing import Tester
File "C:\Python27\lib\site-packages\numpy\testing\__init__.py", line 8, in <module>
from unittest import TestCase
File "C:\Python27\lib\unittest\__init__.py", line 58, in <module>
from .result import TestResult
File "C:\Python27\lib\unittest\result.py", line 9, in <module>
from . import util
File "C:\Python27\lib\unittest\util.py", line 2, in <module>
from collections import namedtuple, OrderedDict
ImportError: cannot import name namedtuple

当我在 Eclipse 中编写以下代码时,也使用 NumPy:

import numpy

add(array([-1.2, 1.2]), array([1,3]))

我收到以下错误:

Traceback (most recent call last):
File "C:\Users\davedove\Documents\eclipseWorkspace\python.graphExample\example.py", line 1, in <module>
import numpy
File "C:\Python27\lib\site-packages\numpy\__init__.py", line 147, in <module>
import add_newdocs
File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 4, in <module>
from type_check import *
File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 40, in <module>
from numpy.testing import Tester
File "C:\Python27\lib\site-packages\numpy\testing\__init__.py", line 8, in <module>
from unittest import TestCase
File "C:\Python27\lib\unittest\__init__.py", line 58, in <module>
from .result import TestResult
File "C:\Python27\lib\unittest\result.py", line 9, in <module>
from . import util
File "C:\Python27\lib\unittest\util.py", line 2, in <module>
from collections import namedtuple, OrderedDict
File "C:\Python27\Lib\site-packages\matplotlib\collections.py", line 13, in <module>
import numpy.ma as ma
File "C:\Python27\lib\site-packages\numpy\ma\__init__.py", line 44, in <module>
import core
File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 73, in <module>
from numpy import ndarray, amax, amin, iscomplexobj, bool_
ImportError: cannot import name ndarray

在命令行中,NumPy 和 matplotlib 都运行良好,我从 preferences -> pydev -> interpreter python 添加了 matplotlib 和 NumPy。可能是什么问题呢?另外,我可以使用什么替代方法来使用 Python 创建图形?

最佳答案

适合我。很可能你已经将 matplotlib 和 numpy 目录添加到你的 PYTHONPATH,这样就导入了 matplotlib.collections 而不是 Python 标准库中的 collections 模块。尝试从 Eclipse > PyDev > Python 解释器设置中的 PYTHONPATH 中删除 matplotlib 和 numpy 目录。

关于Python 2.7 和 PyDev - matplotlib 和 NumPy 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9728263/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com