我有一个非常奇怪的错误,无法解决它.
我有一个具有以下目录结构的项目:
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
import pandas as pd
File "C:\Anaconda\lib\site-packages\pandas\__init__.py", line 13, in
"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吗?当代码被绝对删除?
解决方法:
它在同一个包中有一个名为’io.py’的文件,因为导入pandas的东西会严重破坏.
不要把东西命名为io.py.
标签:python,python-2-7,pandas,pycharm