简体   繁体   English

Pyinstaller - 从不同路径导入模块(脚本为空,作为临时文件工作)

[英]Pyinstaller - importing modules from different paths(scripts are empty, work as tempfiles)

_______________________EDIT_______________________________ _______________________编辑_______________________________

Hello and thanks for beeing here.您好,感谢您来到这里。

I'm trying to include "temp"-files of a self-made programm, that are saved in a self-made path named Temp.我正在尝试包含自制程序的“临时”文件,这些文件保存在名为 Temp 的自制路径中。 Those are within the path "C:\Users\isaac\Desktop\Describing Plot for Material Consumption" .[img of folder][1]这些位于路径"C:\Users\isaac\Desktop\Describing Plot for Material Consumption"中。[文件夹的图像][1]

THE MAIN-problem now is: if I execute the command Simulation, and the SimulationsGUI appears, it can't get data, which would be saved in the Temp file.现在的主要问题是:如果我执行命令 Simulation,并且出现 SimulationsGUI,它无法获取数据,这些数据将保存在 Temp 文件中。 Sometimes it works, sometimes it doesnt?有时有效,有时无效? TO be clear, if I run the code normally throigh python, all things work fine... If I restart the program, the GUI --SOMETIMES-- get the data, that I got, but it shouldn't be so.. Sometimes the error appears:需要明确的是,如果我通过 python 正常运行代码,一切正常......有时会出现错误:

  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'

But as I said, the programm works normally if I run it through python.但正如我所说,如果我通过 python 运行程序,它可以正常工作。

The Mainfile is DPMC and it uses sys.path.append("Temp")(should I change it?) Mainfile 是 DPMC,它使用 sys.path.append("Temp")(我应该更改它吗?)

The code of pyinstaller looks like this untill now:到目前为止,pyinstaller 的代码如下所示:

 pyinstaller -y -i "C:/Users/isaac/Documents/Programmierung/DPMC/imgs/icon.ico" 
--add-data "C:/Users/isaac/Documents/Programmierung/DPMC/README.txt";"." 
--add-data "C:/Users/isaac/Documents/Programmierung/DPMC/Datafolder";"Datafolder/" 
--add-data "C:/Users/isaac/Documents/Programmierung/DPMC/imgs";"imgs/" 
-p Programmierung/DPMC/Temp 
--hidden-import objectseeker 
--hidden-import Logfile --hidden-import classes 
--hidden-import SimulationsGUI  "C:/Users/isaac/Documents/Programmierung/DPMC/DPMC.py"

Well here I will append some codes... What I'm trying to do is: to include the path "Temp(see img, this path is created by me)" to the exe... Because there are temp files written in python that my program needs.那么在这里我将 append 一些代码......我想做的是:将路径“Temp(见img,这个路径是我创建的)”包含到exe中......因为有临时文件写入我的程序需要的 python。 I tried already to explain how the program works, please read:我已经尝试解释该程序是如何工作的,请阅读:

  1. I open the DPMC MAINGUI -> If I choose a csv FIle in the Listbox, it saves all the data in the Tempfile, in the diles named log,temp,temp2 and searchlog(all python scripts)我打开 DPMC MAINGUI -> 如果我在列表框中选择 csv 文件,它将所有数据保存在 Tempfile 中,在名为 log、temp、temp2 和 searchlog 的 diles 中(所有 python 脚本)
  2. I open the SimulationsGUI and now the simulations Gui can load all the data saved in the tempscripts temp,temp2 and searchlog.我打开 SimulationsGUI,现在模拟 Gui 可以加载保存在 tempscripts temp、temp2 和 searchlog 中的所有数据。 But to show the plot data it needs to have acces to the log file.但要显示 plot 数据,它需要访问日志文件。 (I open the module through runpy run module..., mb this is the error?) (我通过runpy run module打开模块...,mb这是错误吗?)

So I don't know where the error actually is... PLS help me!所以我不知道错误实际上在哪里......请帮助我!

This is the code of SimulationsGUI for imports and what I actually want to do:这是用于导入的 SimulationsGUI 代码以及我真正想要做的事情:

from tkinter import *
import os
**def resource_path(relative_path):
    try:
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)
sys.path.append(resource_path("Temp"))
from log import ***
import matplotlib.pyplot as plt
import numpy as np

I recommend and use autopytoexe it uses pyinstaler and has a very an good ui.我推荐并使用autopytoexe它使用 pyinstaler 并且有一个非常好的用户界面。 all the settings are available and it always works for me with this所有设置都可用,它总是对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM