My python app runs fine when I run it through my IDE (Pycharm), without any problems.
But as soon as I create an executable (via the command line:
"pyinstaller --onefile -w main.py"), and then I launch the executable, I get this message:
I have installed PIL via the Pillow module, because PIL directly did not work.
My script starts with all the dependencies:
from PIL import Image as Img,ImageTk
import imageio
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
import os
All the python scripts and folders and environment are set within the project root folder.
Why is this happening and what can I do to create an executable that actually works?
Related
I am doing a small game in which I use "from tl.testing.thread import ThreadJoiner" to execute threads when executing from console the program as such works but when creating the executable with the help of cx_freeze I have the problem that when executing the program I get an error respect tl tells me that the module tl is not found and the program is not executed.
the error is this:
C:\Users\The.hacker\AppData\Local\Programs\Python\Python36-32\lib\site-packgages\cx_freeze\initscripts\_startup_.py",line 14,in run
module.run()
file:
C:\Users\The.hacker\AppData\Local\Programs\Python\Python36-32\lib\site-packgages\cx_freeze\initscripts\Console.py",line 26,in run
exec(code,m._dict_))
file "the_last_warrior",line 11,in <module>
Modulenotfounderror:no module named tl
on line 11 is the from tl.testing.thread import ThreadJoiner
now the image:
my file main is "the_last_warrior.py"
from tkinter import *
from tkinter import ttk
import tkinter as tk
import tkinter
from tl.testing.thread import ThreadJoiner
import threading
import datetime
from threading import Thread
has more than 1600 lines,In itself, how would the correct import of this module be? (from tl.testing.thread import ThreadJoiner)
picture of error:
console_vs_exe.jpg
After trying many things, I solved by copying the package directly from the folder "Lib \ site-packages" my package "tl" and paste it into the Lib folder of my program already ready after using the setup.py the program executes runs as I expected.
Importing a python site-package (e.g. 'scipy') works fine from a script test.py, but not from tkinter button command. When click the button, error shows:
ModuleNotFoundError: No module named 'scipy'
test.py
import scipy
print ("hello world")
GUI.py
import sys
import os
import tkinter
top=tkinter.Tk()
def startCamera():
os.system('python test.py')
B=tkinter.Button(top,text="hello",command= startCamera)
B.pack()
top.mainloop()
Both the test.py and GUI.py are in a same folder:
C:\Users\Breda\PycharmProjects\face_reg\face
scipy package in: C:\Users\Breda\Anaconda3\Lib\site-packages
sys.path variable contains: C:\Users\Breda\Anaconda3\Lib\site-packages
I tried to import other site-packages in test.py and run via GUI button command , all face the same problem. Any ideas?
The reason why the scipy module could not be found is because the python executable run by os.system was not part of the python installation which had scipy installed. (There is more than one python distribution installed on this machine.)
The issue was diagnosed by putting
import sys
print(sys.executable)
at the top of the test.py file (before import scipy). This prints the path to the python executable. Then test.py was run twice -- once from the command-line, and once through GUI.py. The two test runs printed different paths.
The problem was fixed by setting Pycharm's default python executable to the Anaconda Python3 installation which has the scipy module installed.
I have a python script that i have to import all these modules, which some of them require downloading:
import datetime
from dateutil import parser
from tkinter import filedialog
import tkinter
import mailbox
import pprint
import json
import urllib.request
from tkinter import *
Is there a way, using py2exe, i can convert the script into a windows executable. If so, how?
To simplify the procedure, you will want to have all your modules already downloaded. This can be accomplished with a simple "pip install " from command prompt. Then it is as simple as writing and running a setup.py file - detailed directions for how to do this can be found here.
I am working on a Python project that requires PIL to show images. However, the computers that I am working on often do not allow me to install things, and have a very bare bones python setup. For this reason, most of the modules that I need I simply place in the same directory as my python files.
I tried doing the same with PIL. I downloaded the pillow source, and copied the PIL folder into my project. I was then able to run "import PIL" with no problems. However, when I then tried to run "from PIL import Image" I get the error: "The _Imaging C module is not installed". From other searches I think that installing Pillow properly would fix this problem, however I would like PIL to be more portable, and not require an instillation.
Any ideas would be great. Thanks in advance.
One solution is bundle PIL in with the script in .egg form. Then, you can import PIL directly from the .egg instead of having to install it:
How to create Python egg file
The basic process is as follows:
How to create egg:
Edit PIL's setup.py to include from setuptools import setup instead of normal setup import
Run python setup.py bdist_egg
Egg will be inside of dist/
How to import egg:
Copy .egg file to script's directory and import desired modules:
import os
import sys
DIR = os.path.dirname(__file__)
sys.path.append(os.path.join(DIR, "./path/to/PIL.egg"))
#You can now import from PIL normally:
from PIL import Image
If I run:
ti.py (only part of code)
import pygtk
import gtk
I get:
File ti.py.line 2 , in (module)
import gtk
File"C:\python27\lib\site-packages/gtk-2.0\gtk\__init__.py",line 40 in (module)
from gtk import _gtk
ImporError : DLL Load Failed: The specified procedure could not be found.
But if I run it inside shell it works perfectly.
The Python script gives the ImportError, whilst in the shell it imported perfectly.
I have installed pygtk 2.24 from the all in one installer.
What is the cause?