关于python:PyCharm从项目文件夹中的所有文件返回错误

PyCharm returns error in from all files in project folder

我有一个完整的项目文件夹,每当我尝试运行文件时,Pycharm都会返回错误。 如果我从终端运行它们都可以工作。

/usr/bin/python /Users/Casper/PycharmProjects/Mayer/Mayer5.py
Traceback (most recent call last):
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 550, in
main()
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 532, in main
known_paths = addusersitepackages(known_paths)
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 230, in getuserbase
from sysconfig import get_config_var
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 104, in
_PROJECT_BASE = os.path.dirname(_safe_realpath(sys.executable))
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 99, in _safe_realpath
return realpath(path)
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 375, in realpath
path, ok = _joinrealpath('', filename, {})
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 400, in _joinrealpath
if not islink(newpath):
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 138, in islink
return stat.S_ISLNK(st.st_mode)
AttributeError: 'module' object has no attribute 'S_ISLNK'


从这篇文章中,可能有两个可能的原因:

  • 循环依赖:

    如果在第一个a.py文件中import b并且在b.pyimport a,那么您可能会看到这种情况发生。 Python将自行决定首先加载哪个模块。

  • .py中指定的模块与Python标准文件中的模块相同:

    在这种情况下,您必须更改模块名称。

  • 您需要提供有关代码的更多信息,以便我们确定哪一个是根本原因。