"No module named email.utils" in smtplib with gui2exe - python

I have a nice simple script sending an email to a gmail address. Very simple and works fine from Python IDLE after running it.
After making it an exe with GUI2Exe (using py2exe and also cx_freeze) I get this Error:
Traceback (most recent call last):
File "something.py", line 4, in <module>
File "smtplib.pyc", line 46, in <module>
ImportError: No module named email.utils
It is not called email.py and I have nothing on my computer called like that (I've read everything regarding this issue)
I alse tryed forcing it both from something.py and smtplib.py too with:
opts = {'py2exe': { "includes" : ["email.utils"] }}
Makes no difference at all. Runs from IDLE great but after gui2exe...ERROR.
I do have this email directory in my Lib directory and it does contain utils. But this is obvious since from IDLE the script works fine.
Original script:
import smtplib
fromaddr = 'blablu#gmail.com'
toaddrs = 'blipblop#gmail.com'
msg = 'There was a terrible error that occured and I wanted you to know!'
# Credentials (if needed)
username = 'blablu'
password = 'passbla'
# The actual mail send
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
I'm sick of this by now, sorry. I have no idea at all what's happening.
Can someone tell me what am I doing wrong?

I tried to freeze your script running cx_Freeze directly and it worked perfectly fine. Since GUI2exe is only a graphical user interface, I would suggest you also try to run cx_Freeze directly as this eliminates any possible issues caused by GUI2exe.
Assuming you want to make a command line app, this is the setup.py file you need to create next to the file with the above code (in the the setup.py, I assume your code is called "smtpTest.py"):
import os, sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {'packages': [],
'excludes': ['tkinter'],
'includes': []}
setup( version = '0.1',
description = 'sends mails',
options = {'build_exe': build_exe_options},
executables = [Executable('smtpTest.py', targetName="smptMailer.exe")])
Then open a commandline and go to the directory where you have your file and the setup.py file stored and type:
python setup.py build
After the build process, your executable will be in a new folder called "build".

Related

How do I correctly package PySide6 using cxfreeze?

I have written a fairly simple GUI application using Python 3.8.0 and PySide6 and I would like to package it for distribution. Based on the table here, I chose cxfreeze as it's compatiable with Qt6 and with Windows/Linux/Mac.
My application in running with a pyenv environment on my development machine, if that makes a difference. The machine is running Debian Bullseye.
I ran the cxfreeze-quickstart wizard in order to create the setup.py script. The output from the script is here (apologies for pastebin link, the text is too long for stackoverflow)
When I run the created executable (build/build/exe.linux-x86_64-3.8/sne), I get the following error:
Traceback (most recent call last):
File "/home/james/.pyenv/versions/3.8.0/lib/python3.8/site-packages/cx_Freeze/initscripts/__startup__.py", line 104, in run
module_init.run(name + "__main__")
File "/home/james/.pyenv/versions/3.8.0/lib/python3.8/site-packages/cx_Freeze/initscripts/Console.py", line 15, in run
exec(code, module_main.__dict__)
File "app.py", line 7, in <module>
ImportError: libpyside6.abi3.so.6.1: cannot open shared object file: No such file or directory
The libpyside6.abi3.so.6.1 file is in the build/exe.linux-x86_64-3.8/lib/PySide6 directory.
I added a line to print the contents of sys.path when the application runs:
['/home/james/code/cave-escape/simple-nano-ethernet/SNEGui/build/exe.linux-x86_64-3.8/lib/library.zip', '/home/james/code/cave-escape/simple-nano-ethernet/SNEGui/build/exe.linux-x86_64-3.8/lib']
The lib/PySide6 directory is not in the path, but I believe this is not the issue as the PySide6 package is present in lib.
If I run ldd against libpyside6.abi3.so.6.1, all the dependencies have filepath listed against them except for one:
libshiboken6.abi3.so.6.1 => not found
This file is present in build/exe.linux-x86_64-3.8/lib/shiboken6 directory.
I am guessing I need to make a manual edit to the setup.py script to fix this, or perhaps edit the sys.path at application startup, but I'm not sure exactly what to do in either case.
EDIT: contents of setup.py (autogenerated, unaltered):
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
build_options = {'packages': [], 'excludes': []}
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('app.py', base=base, target_name = 'sne')
]
setup(name='Simple Nano Ethernet GUI',
version = '1.0',
description = 'An interface to configure the simple nano ethernet board',
options = {'build_exe': build_options},
executables = executables)

ImportError on python exe file

Using py2exe I create an exe version of my script with instructions I found here. The script compiles well and generates a dist and build folder each but when I run the program on the command line it gives this error. N.B the script works fine on my IDE environment, however I intend give a colleague the exe version.How can I fix this error?
Traceback (most recent call last):
File "tester2.py", line 4, in <module>
ImportError: No module named mechanize
here is the setup.py file:
from distutils.core import setup
import py2exe
setup(
console = ['tester2.py'],
zipfile = None,
)
You have to declare your dependencies.
This is my setup
setup(
executables=executables,
options=options,
name='bla',
version='0.3',
packages=[...],
url='',
license='',
author='',
author_email='',
description='', requires=['pandas', 'unidecode', 'click',
'xlsxwriter'] // you would have to add mechanize here
)
Have you added files to the build?
Pls have a look at include option in setup.py: exe built with cx_Freeze, PyQt5, Python3 can't import ExtensionLoader_PyQt5_QtWidgets.py and run
Also here's my solution to similar problem, how to add files to build and run them later: Python - create an EXE that runs code as written, not as it was when compiled

cxFreeze and Jaraco: ImportError

I'm trying to create an IRC client using the irclib library. When I try to freeze the script using cxFreeze, however, I always run into that error:
Traceback (most recent call last):
File "C:\python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "client.py", line 38, in <module>
ImportError: No module named jaraco
The setup.py script has been modified several times, to try to include files, packages and so on. Nothing seems to work. Here's the current version for reference:
from cx_Freeze import setup, Executable
client = Executable(
script="client.py",
base="Win32GUI",
)
setup(
name = "client",
version = "0.2",
description = "client",
options = {'build_exe': {'includes': ["jaraco"], "packages": ["jaraco"]}},
executables = [client],
)
The script of the client can be shortened in a single line:
from irc import client
That's all. I'm not using Jaraco, irclib (package irc) is. Jaraco must have been installed as a dependency from irclib.
I've tried to find the reasons why it could happen, but so far, nothing found.
Thanks for your help!
Well, after some digging around, it seems the same problem exists with zope when freezing an application with twisted. Although I haven't tested it with jaraco, I would imagine it's the same issue. I hope this solution works for users stuck with the same problem:
In your 'site-packages' directory, in the 'jaraco' package, add the 'init.py' file. It can be empty. Why isn't it provided, I have no idea. A package without a 'init.py", for cxFreeze, isn't a package.
Re-run the 'setup.py' script. Don't include 'jaraco' as a package, provide the package that needs it (here, it would be 'irc').
Here's the setup.py script:
from cx_Freeze import setup, Executable
client = Executable(
script="client.py",
base="Win32GUI",
)
setup(
name = "client",
version = "0.2",
description = "client",
options = {'build_exe': {'packages': ["irc"]}},
executables = [client],
)
I provide this answer because it worked just fine with twisted and zope. Seeing my client uses twisted now for its IRC communication, I don't know if the provided steps below work, but that's what helped me for twisted.
HTH,

cx_Freeze: Python error in main script

I am a beginner in python and django. This error keeps coming, even after installing cx_freeze from http://www.lfd.uci.edu/~gohlke/pythonlibs/#cx_freeze
I am trying to make an executable file and I want to run my server through it, which I normally do by:
manage.py runserver
I am currently using commands:
setup.py build
I have already tried:
pyinstaller --name=mysite myproject_dir/manage.py
and my setup.py file contains
import sys
from distutils.core import setup
from cx_Freeze import setup, Executable
setup(
name = "Management System",
version = "1.0",
description = "A Database Management System",
py_modules=['virtualenv'],
executables = [Executable("manage.py", base = "Win32GUI")])
I have also tried py2exe, it doesn't work. You can also suggest to read something for this knowledge.
Here is the image of error that keeps appearing on running the exe file
If I use this command:
Barcode.exe runserver
There also comes an error
WindowsError: [Error 3] The system cannot find the path specified:'C:\\Users\\D ell\\AppData\\Local\\Temp\\_MEI85~1\\Entry\\migrations/*.*'

Py2exe compiles properly but the built application doesn't work

I am using Python 2.7 to build my application. Within it, I used few packages which are numpy, scipy, csv, sys, xlwt, time, wxpython and operator.
All the above packages are in 64-bit, and I am using python 2.7(64-bit version) in Aptana Studio 3(64-bit version) in Windows 7 Professional (64-bit version).
At last, I'd like to compile my project to an application using following code, the file name is py2exeTest.py:
from distutils.core import setup
import numpy # numpy is imported to deal with missing .dll file
import py2exe
setup(console=["Graphical_Interface.py"])
Then in cmd, I switched to the directory of the project and used following line to compile it:
python py2exeTest.py py2exe
Everything goes well, it generates an application under dist directory, and the application name is Graphical_Interface.exe.
I double clicked it, but there is a cmd window appears, and a python output windows flashes, then both of them disappeared. I tried to run the application as an administrator, the same outcome I've had.
May I know how to work this out?
Thanks!
EDIT:
I've managed to catch the error information that flashes on the screen. The error info I had is:
Traceback (most recent call last):
File "Graphical_Interface.py", line 397, in <module>
File "Graphical_Interface.py", line 136, in __init__
File "wx\_core.pyc", line 3369, in ConvertToBitmap
wx._core.PyAssertionError: C++ assertion "image.Ok()" failed at ..\..\src\msw\bitmap.cpp(802) in wxBitmap::CreateFromImage(): invalid image
I used one PNG image in the project, the code is like follows:
self.workflow = wx.Image("Work Flow.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
wx.StaticBitmap(self.panel_settings, -1, self.workflow, (330,270), (self.workflow.GetWidth(), self.workflow.GetHeight()))
I tried to comment the above chunk out from the project, and the application works properly. However, I need the image to show up in the application.
May I know how to deal with it?
Thanks.
Hiding console window of Python GUI app with py2exe
When compiling graphical applications you can not create them as a console application because reasons (honestly can't explain the specifics out of my head), but try this:
from distutils.core import setup
import numpy
import py2exe
import wxpython
setup(window=['Graphical_Interface.py'],
options={"py2exe" { 'boundle_files' : 1}})
Also consider changing to:
http://cx-freeze.sourceforge.net/
It works with Python3 and supports multiple platforms.
A cx_freeze script would look something like:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
includefiles = ['/folder/image.png']
setup( name = "GUIprog",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options, 'include_files' : includefiles},
executables = [Executable("Graphical_Interface.py", base=base)])
No worries, I've got the solution.
It turns out that the image is in the project folder rather than in the dist folder. So I have two solutions:
Copy the image into dist folder
Include the full path of the image in the code.
Thanks for your help.

Categories