我正在使用PyQt5构建一个生成dxf文件的桌面程序。要创建dxf文件,我使用ezdxf库。当我运行脚本时,没有错误出现。但是,通过pyinstaller编译程序并运行程序后,出现错误消息:
"Traceback (most recent call last):
File "Outline Generator.py", line 324, in generateDXFfile
File "DXFgenerator_data_class.py", line 23, in __init__
File "DXFgenerator_data_class.py", line 44, in loadData
File "site-packages\ezdxf\filemanagement.py", line 42, in new
File "site-packages\ezdxf\drawing.py", line 390, in new
File "site-packages\ezdxf\templates\__init__.py", line 37, in getstream
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\User\\AppData\\Local\\Temp\\_MEI119642\\templates\\AC1024.dxf'"
我在ezdxf库数据中找到文件“模板”,将其放置在程序所在的位置,并通过如下官方文档中的命令ezdxf.options.template_dir在代码中添加了模板位置更改:
path_files = os.path.dirname(os.path.abspath(__file__))
work_dir = path_files + '\\templates\\'
for sample in self.samples:
ezdxf.options.template_dir = work_dir
dwg = ezdxf.new(dxfversion='AC1024')
msp = dwg.modelspace()
dwg.layers.new(name='04 Foil cutout 165W', dxfattribs={'linetype': 'Continuous', 'color': 1, 'lineweight': 0.00})
dwg.layers.new(name='02_markings', dxfattribs={'linetype': 'Continuous', 'color': 6, 'lineweight': 0.00})
dwg.layers.new(name='05 allignment', dxfattribs={'linetype': 'Continuous', 'color': 3, 'lineweight': 0.00})