我遇到一个非常奇怪的错误并且无法解决它。
我有一个具有以下目录结构的项目:
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 或其他东西?什么时候代码被完全剥离?