PyCharm,有些软件包无法导入Pandas,ImportError:C扩展名:StringIO未构建

时间:2015-06-23 21:49:53

标签: python python-2.7 pandas pycharm

我遇到一个非常奇怪的错误,无法解决。

我有一个具有以下目录结构的项目:

ptouch/
    ptouch/
        __init__.py
        ptouch.py
        io.py
    tests/
        __init__.py
        tests.py

我正在使用PyCharm社区版和Anaconda python发行版。

文件:ptouch.py包含以下代码:

__author__ = 'foo'
import pandas as pd
df = pd.DataFrame()

执行此文件会出现以下错误:

C:\Anaconda\python.exe ~/ptouch.py
Traceback (most recent call last):
  File "~/ptouch.py", line 2, in <module>
    import pandas as pd
File "C:\Anaconda\lib\site-packages\pandas\__init__.py", line 13, in <module>
  "extensions first.".format(module))
ImportError: C extension: StringIO not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.

但是,执行tests.py没有错误,并且使用pandas没有问题。

文件tests.py包含以下代码:

from unittest import TestCase
import pandas as pd
class Tests(TestCase):
    def test_pickle(self):
        d = pd.DataFrame(np.random.rand(50, 10))
        self.fail()

我尝试用conda和pip卸载并重新安装pandas无济于事。创建一个新项目似乎能够毫无问题地加载pandas。我找不到任何可能导致此错误的软件包特定设置。

是否有某些原因导致某些软件包或运行配置尝试从源代码或其他东西运行pandas?当代码被绝对删除时?

1 个答案:

答案 0 :(得分:6)

它变成了一个名为&#39; io.py&#39;在同一个包装中,导入大熊猫的东西会严重破坏。

不要为事物io.py命名