0

I wrote a python3 script (with the name 'SVD.ipynb') in the Jupyter notebook:

from tkinter import *
from PIL import Image, ImageTk

import numpy as np
from scipy import linalg as lg
import matplotlib.pyplot as plt



########## Funktion zur Erstellung von Bilddateien in unterschiedlichen #####
########## Kompressionsstufen werden erzeugt #################################

def svd():
    filepath = "SVD_F.txt"
    reader = open(filepath,"r")
    text = reader.readlines()
    outer_array = []
    current_array =[]
    for line in text:
        for char in line:
            if char=='0' or char=='1':
                current_array.append((-1)*float(char))
        outer_array.append(current_array)
        current_array=[]

    F = outer_array

    #plt.imshow(F, cmap="gray") 
    #plt.show()
    plt.imsave('SVD_F.png', F, cmap="gray")

    U, s, Vh = lg.svd(F)

    s_matrix = np.zeros((25,15))
    for i in range(0, len(s)):
        s_matrix[i][i] = s[i]


    for i in range(1, 4):
        F_approx = U[:,:i] @ s_matrix[:i,:i] @ Vh[:i,:]
        #plt.imshow(F_approx, cmap="gray")        
        #x=plt.show()
        plt.imsave('SVD_F_approx'+str(i)+'.png', F_approx, cmap="gray")
        


########## Haupt-Benutzerfenster wird erzeugt ######################################
        
root = Tk()
root.title('SVD')


######### Obige Funktion wird aufgerufen ###########################################

svd()

######### Bilder werden ins Hauptfenster geladen, vergroessert dargestellt #########
################## und entsprechend angeordnet #####################################

image = Image.open("SVD_F.png")
image = image.resize((100, 100), Image.ANTIALIAS)
my_img0 = ImageTk.PhotoImage(image)
image_label0 = Label(image=my_img0)
image_label0.grid(row=0,column=1)

image = Image.open("SVD_F_approx1.png")
image = image.resize((100, 100), Image.ANTIALIAS)
my_img1 = ImageTk.PhotoImage(image)
image_label1 = Label(image=my_img1)
image_label1.grid(row=1,column=1)

image = Image.open("SVD_F_approx2.png")
image = image.resize((100, 100), Image.ANTIALIAS)
my_img2 = ImageTk.PhotoImage(image)
image_label2 = Label(image=my_img2)
image_label2.grid(row=2,column=1)

image = Image.open("SVD_F_approx3.png")
image = image.resize((100, 100), Image.ANTIALIAS)
my_img3 = ImageTk.PhotoImage(image)
image_label3 = Label(image=my_img3)
image_label3.grid(row=3,column=1)


############## Textstücke werden erzeugt und entsprechend angeordnet ##################

text_label0 = Label(text="Originalbild:")
text_label0.grid(row=0, column=0)

text_label1 = Label(text='staerkste Kompression, nur Sigma11:')
text_label1.grid(row=1, column=0)

text_label2 = Label(text='mittlere Kompression, bis Sigma22:')
text_label2.grid(row=2, column=0)

text_label3 = Label(text='schwache Kompression, bis Sigma33, sieht aus wie Original:')
text_label3.grid(row=3, column=0)


root.mainloop()

This script works perfectly fine, when I run it in the Jupyter notebook. Then I downloaded it from the Jupyter notebook as a .py-file, so the name now was 'SVD.py'. Then in the windows command promt I typed:

pyinstaller --onefile SVD.py

, so it was converted into 'SVD.exe'. When I started this .exe-file in the windows command prompt, the command prompt shows a text:

C:\Users\Lenovo\Documents\BA Studium\3 Semester\Perlt\Hausarbeit\dist>SVD.exe
Traceback (most recent call last):
  File "SVD.py", line 10, in <module>
ModuleNotFoundError: No module named 'numpy'
[10508] Failed to execute script SVD

In the command prompt I changed the directory into C:\Users\Lenovo\Documents\BA Studium\3 Semester\Perlt\Hausarbeit
where the 'SVD.py'-file lies and then I typed

pip install numpy

The installation process happened without problems, and I converted the .py-file via pyinstaller into the .exe-file again. When I start the .exe-file via command prompt: Still the same error message.

I copied 'SVD.py' into C:\Users\Lenovo
where I usually have all my other python scripts and converted it there in the same way into an .exe-file. When I start the .exe-file via command prompt, it shows a different error message:

C:\Users\Lenovo\dist>SVD.exe
Traceback (most recent call last):
  File "SVD.py", line 11, in <module>
ModuleNotFoundError: No module named 'scipy'
[13396] Failed to execute script SVD

###########EDIT###########

Then I typed into the command prompt the following:

SVD.py --hidden-import numpy

Trying to start SVD.exe now showed, that this time (not the numpy, but) the scipy-module was missing. So I typed into the prompt:

SVD.py --hidden-import scipy

After trying to start SVD.exe, the command prompt still shows that scipy is missing.

I the directory of SVD.py I typed into the prompt:

pip install scipy

The installation seemed to work successfully. Still, when I try to compile SVD.py into SVD.exe, it still shows me that scipy is missing:

C:\Users\Lenovo\Documents\BA Studium\3 Semester\Perlt\Hausarbeit>pyinstaller SVD.py --onefile --hidden-import scipy
115 INFO: PyInstaller: 4.1
115 INFO: Python: 3.9.1
115 INFO: Platform: Windows-10-10.0.18362-SP0
115 INFO: wrote C:\Users\Lenovo\Documents\BA Studium\3 Semester\Perlt\Hausarbeit\SVD.spec
115 INFO: UPX is not available.
115 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Lenovo\\Documents\\BA Studium\\3 Semester\\Perlt\\Hausarbeit',
 'C:\\Users\\Lenovo\\Documents\\BA Studium\\3 Semester\\Perlt\\Hausarbeit']
131 INFO: checking Analysis
247 INFO: checking PYZ
300 INFO: checking PKG
300 INFO: Building because toc changed
300 INFO: Building PKG (CArchive) PKG-00.pkg
8614 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
8654 INFO: Bootloader c:\users\lenovo\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
8654 INFO: checking EXE
8672 INFO: Building because name changed
8672 INFO: Building EXE from EXE-00.toc
8672 INFO: Appending archive to EXE C:\Users\Lenovo\Documents\BA Studium\3 Semester\Perlt\Hausarbeit\dist\SVD.exe
8704 INFO: Building EXE from EXE-00.toc completed successfully.

C:\Users\Lenovo\Documents\BA Studium\3 Semester\Perlt\Hausarbeit>cd .\dist

C:\Users\Lenovo\Documents\BA Studium\3 Semester\Perlt\Hausarbeit\dist>SVD.exe
Traceback (most recent call last):
  File "SVD.py", line 11, in <module>
ModuleNotFoundError: No module named 'scipy'
[2088] Failed to execute script SVD

Greetings so_question_asker

1 Answers1

0

I think that if PyInstaller isn't automatically detecting imports, you should use the --hiden-import the_import_module flag in your actual command.

You can checkout this link, it has a similar answer. You can also read the documentation

Dhruv Jadhav
  • 260
  • 1
  • 11
  • Thank you very much for your quick reaction. You mean, I should type in the command prompt: 'pyinstaller --onefile SVD.py --hidden-import numpy scipy' is this the right order? or do you mean i should literally type '.... the_import_module ......'? – cs_question_asker Dec 22 '20 at 11:05
  • I've also read the documentation link and tried the "extending the path" advice, with no effect, the prompt still says, it can't find scipy-module. maybe any other idea ......? – cs_question_asker Dec 22 '20 at 15:50
  • 'pyinstaller --onefile SVD.py --hidden-import numpy scipy', that's right. – Dhruv Jadhav Dec 23 '20 at 03:39