在处理this多文件项目时遇到导入问题。
这是目录结构
aluminium@aluminium:~/Desktop/mad/build/lib$ ls -R
./madesigner.py
./madgui:
build_tab_ui.py flap_ui.py overview.py sheet_ui.py trailing_edge_ui.py
combobox_nowheel.py __init__.py simple_hole_ui.py version.py
creator_ui.py leading_edge_ui.py shaped_hole_ui.py spar_ui.py wing_ui.py
./madlib:
ac3d.py builder.py freecad.py layout.py spline.py test.py
airfoil.py contour.py __init__.py structure.py wing.py
freecad.py文件的前几个导入语句如下
import sys
import os.path
# path to your FreeCAD.so or FreeCAD.dll file
FREECADPATH = '/usr/lib/freecad-python3/lib/'
sys.path.append(FREECADPATH)
import FreeCAD
import Part, Mesh
from FreeCAD import Base
builder.py文件的前几个导入语句如下
from . import ac3d
from . import freecad
from . import contour
from .wing import Wing
现在,当我尝试执行./madesigner.py时,这是我按照以下调用顺序获取的堆栈跟踪信息
madesigner.py-> madgui.creator_ui-> madlib.builder import Builder->。导入freecad
aluminium@aluminium:~/Desktop/mad/build/lib$ python madesigner.py
Traceback (most recent call last):
File "madesigner.py", line 14, in <module>
from madgui.creator_ui import CreatorUI
File "/home/aluminium/Desktop/mad/build/lib/madgui/creator_ui.py", line 31, in <module>
from madlib.builder import Builder
File "/home/aluminium/Desktop/mad/build/lib/madlib/builder.py", line 17, in <module>
from . import freecad
File "/home/aluminium/Desktop/mad/build/lib/madlib/freecad.py", line 13, in <module>
import FreeCAD
ImportError: /home/aluminium/anaconda3/lib/python3.7/site-packages/PyQt5/../../../libQt5Core.so.5: version `Qt_5.12' not found (required by /usr/lib/freecad-python3/lib/libFreeCADApp.so)
不管出现PyQt5错误,当我实际进入./madlib并执行freecad.py时,它都可以完美地用作文件和模块
aluminium@aluminium:~/Desktop/mad/build/lib/madlib$ python freecad.py
FreeCAD 0.18.4, Libs: 0.18.4R
aluminium@aluminium:~/Desktop/mad/build/lib/madlib$ python -m freecad
FreeCAD 0.18.4, Libs: 0.18.4R
当我尝试编译builder.py时,出现以下错误,这很奇怪,因为ac3d.py和builder.py都位于同一目录中。
aluminium@aluminium:~/Desktop/mad/build/lib/madlib$ python -m builder
Traceback (most recent call last):
File "/home/aluminium/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/aluminium/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/aluminium/Desktop/mad/build/lib/madlib/builder.py", line 16, in <module>
from . import ac3d
ImportError: attempted relative import with no known parent package
尝试了将近一百个SE帖子后,我不知道发生了什么。
任何人都可以指出我想念的是什么,为什么我会收到此错误?