I am having a very strange error and cannot resolve it.
I have a project with the following directory structure:
ptouch/
ptouch/
__init__.py
ptouch.py
io.py
tests/
__init__.py
tests.py
I am using PyCharm community edition, and Anaconda python distribution.
The file: ptouch.py
contains the following code:
__author__ = 'foo'
import pandas as pd
df = pd.DataFrame()
Executing this file gives the following error:
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.
However, executing tests.py
gives no errors and uses pandas with no problem.
The file tests.py
contains the following code:
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()
I have tried uninstalling and reinstalling pandas with both conda and pip to no avail. Creating a new project seems to be able to load pandas without issue. I cannot find any package specific settings that could result in this error.
Is there some reason why some packages or run configurations could be trying to run pandas from source or something? When the code is absolutely stripped out?