-1

_______________________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. Those are within the path "C:\Users\isaac\Desktop\Describing Plot for Material Consumption".[img of folder][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. 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:

  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.

The Mainfile is DPMC and it uses sys.path.append("Temp")(should I change it?)

The code of pyinstaller looks like this untill now:

 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. 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)
  2. I open the SimulationsGUI and now the simulations Gui can load all the data saved in the tempscripts temp,temp2 and searchlog. But to show the plot data it needs to have acces to the log file. (I open the module through runpy run module..., mb this is the error?)

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:

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
  • What error message do you get when you say “This doesn’t work at all”? Edit the full console output into your question. – DisappointedByUnaccountableMod Apr 18 '20 at 19:29
  • Hello barny, ty for answering. – Isaac Yuki Apr 18 '20 at 20:02
  • I updated now the post – Isaac Yuki Apr 18 '20 at 20:02
  • You need to adapt the code that loads the csv files to use path sys._MEIPASS (Or something like that - a search on here should find q/a about it) because when the exe runs these aren’t in the non-pyinstalller location but are automatically extracted along with the rest of what’s in the exe. – DisappointedByUnaccountableMod Apr 19 '20 at 10:59
  • The csv files are running and the Maingui runs perfectly, as long I run it in my computer...(I made the compilation with autopyexe) The problem is, if I run it in another computer, the other moduls appear not to run... – Isaac Yuki Apr 19 '20 at 15:43
  • Try running the exe from a command prompt, might show the execption that’s killing it. – DisappointedByUnaccountableMod Apr 19 '20 at 18:33
  • I found out, that he can't find the path Temp if i put it into "-p". In this path there are 4 modules, described as temp file, and well I don't know, how to put the path Temp in "-p".. if I writte only Temp or give the entire name of the path.. as well I don't know, if I have to also import the modules in the path Temp – Isaac Yuki Apr 19 '20 at 21:00
  • You shouldn’t change the working directory - leave it alone so Temp is still relative to where you run the exe and make your code work with that. See the answer specifically by Jonathon Reinhart here https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile/13790741#13790741 - you should use the `resource_path` function t get your files and **not** change the current working directory. – DisappointedByUnaccountableMod Apr 19 '20 at 21:07
  • I edited now the post for better understanding of the actual problem – Isaac Yuki Apr 19 '20 at 23:21
  • Your question is still confusing - if the pyinstaller command you give creates a .exe, what error message do you get when you run this? If it works on your system but not elsewhere, what error message do you get when you try to run it (from a command prompt) elsewhere? Have you tried add the temp folder and its contents to the pyinstaller command, and using the `resource_path` function I pointed at then change your sys.path command to `sys.path.append(resource_path(“Temp”))` – DisappointedByUnaccountableMod Apr 20 '20 at 07:02
  • Yes I tried it... I put this in the first lines of the MAIN-script... – Isaac Yuki Apr 20 '20 at 12:44
  • As I found out, now the script runs... But It seems that the programm won't alterate the files inside the "Temp"-folder(written by me). So that if I want to plot something, the temp files aren't beeing used – Isaac Yuki Apr 20 '20 at 15:21
  • Are you trying to include the Temp folder in the exe, or not? According to your pyinstaller command you aren't - in that case you need ot make sure that references to Temp are absolute or explicitly relative to current working directory. You should create a [mre] and edit into your question - i.e. minimal code that I could paste into a file and run without adding anything else to show the problem you are seeing. – DisappointedByUnaccountableMod Apr 20 '20 at 16:14
  • Well I don't know how to reproduce this... I can give u the link to Github, so mb u can understand better.. The File wich is not working is the SimulationsGUI file. I'm very thankfull for your help https://github.com/illy777/DPMC – Isaac Yuki Apr 20 '20 at 16:54
  • No thanks. IME producing a [mre] is often how the author finds out what the actual problem is. – DisappointedByUnaccountableMod Apr 20 '20 at 18:06
  • ok ok.. Yes I'm trying to include the Temp folder in the exe(made by me)... I will add the code in the mainpost, mb it is the way I append the oaths wrong... But I'm really sry, bc I really don't know where to search for the error... I'm trying this since 4 days, and I still don't found anything. – Isaac Yuki Apr 20 '20 at 18:38
  • @Barny I only want to say that I'm very thankfull for ur patience, cz literally, I'm to dumb for this xD – Isaac Yuki Apr 20 '20 at 18:49
  • Ok I think I know the error... The Logfile, which "translates" the datas of the file "temp" writes the log datas in python. So the .exe programm can't read this? – Isaac Yuki Apr 20 '20 at 19:51
  • ok its senseless, now i saw, that the programm won't work, if runpy.run.module is used... I give up. – Isaac Yuki Apr 20 '20 at 20:29

1 Answers1

1

I recommend and use autopytoexe it uses pyinstaler and has a very an good ui. all the settings are available and it always works for me with this

rafalou38
  • 576
  • 1
  • 5
  • 16