gpt4 book ai didi

python - PyCharm,部分包无法导入Pandas,ImportError : C extension: StringIO not built

转载 作者:太空狗 更新时间:2023-10-30 02:29:43 28 4
gpt4 key购买 nike

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

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

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?什么时候代码完全剥离?

最佳答案

在导入 pandas 的同一个包中有一个名为“io.py”的文件会严重破坏事情。

不要命名io.py

关于python - PyCharm,部分包无法导入Pandas,ImportError : C extension: StringIO not built,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31014146/

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