PyCharm 解释器损坏

0 投票
1 回答
1257 浏览
提问于 2025-04-17 22:23

我一直在使用PyCharm CE,效果还不错。但我刚刚安装了basemap模块(需要从源代码编译geos和basemap),结果似乎把PyCharm的解释器搞坏了。当我在终端运行Python时,所有的模块都能正常加载,而且在PyCharm内部的终端运行Python时,所有模块也都能正常运行。但是现在,当我尝试在交互式解释器中加载某些包时,就会出现错误信息。例如,现在当我在交互式解释器中尝试导入pandas时,出现了这个:

Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/IPython/core/interactiveshell.py", line 2827, in run_code
exec code_obj in self.user_global_ns, self.user_ns
File "<ipython-input-3-af55e7023913>", line 1, in <module>
import pandas as pd
File "/Library/Python/2.7/site-packages/pandas/__init__.py", line 25, in <module>
import pandas.core.config_init
File "/Library/Python/2.7/site-packages/pandas/core/config_init.py", line 4, in <module>
from pandas.core.format import detect_console_encoding
File "/Library/Python/2.7/site-packages/pandas/core/format.py", line 12, in <module>
from pandas.core.index import Index, MultiIndex, _ensure_index
File "/Library/Python/2.7/site-packages/pandas/core/index.py", line 10, in <module>
import pandas.index as _index
File "index.pyx", line 34, in init pandas.index (pandas/index.c:14957)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-        packages/pytz/__init__.py", line 31, in <module>
from pkg_resources import resource_stream
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/pkg_resources.py", line 2717, in <module>
add_activation_listener(lambda dist: dist.activate())
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/pkg_resources.py", line 682, in subscribe
callback(dist)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/pkg_resources.py", line 2717, in <lambda>
add_activation_listener(lambda dist: dist.activate())
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/pkg_resources.py", line 2255, in activate
list(map(declare_namespace, self._get_metadata('namespace_packages.txt')))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/pkg_resources.py", line 1851, in declare_namespace
path = sys.modules[parent].__path__
KeyError: 'dap'

如果我在同一个会话中再尝试导入pandas,错误信息就变成了这个:

Traceback (most recent call last):
cannot import name hashtable
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/IPython/core/interactiveshell.py", line 2827, in run_code
exec code_obj in self.user_global_ns, self.user_ns
File "<ipython-input-6-af55e7023913>", line 1, in <module>
import pandas as pd
File "/Library/Python/2.7/site-packages/pandas/__init__.py", line 6, in <module>
from . import hashtable, tslib, lib
ImportError: cannot import name hashtable

我到底做了什么让解释器坏掉了?我尝试重新安装PyCharm来重置,但似乎没有效果。

1 个回答

0

希望这对某些人有帮助。我在一个Django项目中遇到了这个问题,这个项目还设置了使用Google App Engine;所以,PyCharm加载了很多Python包的GAE版本(这些包被添加到了我的PYTHONPATH中)。我在文件 -> 设置 -> 语言与框架 -> Google App Engine中禁用了Google App Engine的支持。问题就解决了。

注意:当我在PyCharm外运行我的Django应用时,并没有遇到Pandas导入的问题。

撰写回答