ImportError: The 'six' package is required - python

I'm trying to convert my tkinter python script into exe with cx_Freeze. From now on, I've dealt with many common problems TCL-TK, DLL and idna. It seems I solved them but now I have another problem. When I try to run the exe version of the application, I get the following error:
ImportError: The 'six' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
import cx_Freeze
import sys
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl','tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [cx_Freeze.Executable ("SeeWord.py", base=base)]
cx_Freeze.setup(name="SeeWord",
options= {"build_exe": {"packages": ["idna", "tkinter",
"MySQLdb", "requests",
"bs4","re","random","win10toast","time","datetime","threading"] }},
version="0.01",
description="vocabulary application",
executables = executables)

Related

Unable to compile with cx_freeze and PySide2

I have a python program I'm trying to compile with cx_freeze. The GUI I'm using is PySide2.
I've tried including PySide2, here is excluding it, but I keep getting the same error. Below is my setup.py code
from cx_Freeze import setup, Executable
import sys
includefiles = ['README.md', 'debug.log','tcl86t.dll', 'tk86t.dll', 'field.jpg', 'inputClass.py', 'mainfile.qml', 'MyTabView.qml', 'PlayerSelection.qml', 'selectedPlayers.py', 'Settings.qml', 'SimOutput.qml', 'simulationOutput.py']
includes = ["idna.idnadata", "atexit"]
excludes = ["PySide2"]
import os
os.environ['TCL_LIBRARY'] = r'C:\Users\pimat\AppData\Local\Programs\Python\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\pimat\AppData\Local\Programs\Python\Python36\tcl\tk8.6'
setup(name = "Simulation",
version = "0.2",
description = "Optimization Simulator",
options = {'build_exe':{'includes':includes,'excludes':excludes,'include_files':includefiles}},
executables = [Executable("main.py")])
The program compiles fine, but when running the exe, I get the following error:
"ModuleNotFoundError: No module named 'PySide2'"
So the error was that I had installed cx_freeze with python 3.6, but all of my packages were in a python 3.7 folder. I simply copied and pasted into the 3.6 folder and changed the code a bit, and the exe works great.
from cx_Freeze import setup, Executable
import sys
# dependencies
build_exe_options = {
"packages": ["os", "sys", "re", "idna.idnadata", "atexit", "PySide2.QtCore", "PySide2.QtWidgets", "PySide2.QtUiTools", "PySide2.QtQuick", "PySide2.QtQml", "PySide2.QtGui", "shiboken2"],
"include_files": ['README.md', 'debug.log','tcl86t.dll', 'tk86t.dll', 'field.jpg', 'inputClass.py', 'mainfile.qml', 'MyTabView.qml', 'PlayerSelection.qml', 'selectedPlayers.py', 'Settings.qml', 'SimOutput.qml', 'simulationOutput.py',
],
"excludes": ["Tkinter", "Tkconstants", "tcl", ],
"build_exe": "build",
#"icon": "./example/Resources/Icons/monitor.ico"
}
executable = [
Executable("main.py",
base="Win32GUI",
targetName="Simulation.exe"
)
]
setup(name = "Simulation",
version = "0.2",
description = "Simulator",
options={"build_exe": build_exe_options},
executables=executable
)
T'was a dumb mistake, but I've made worse

No module _cffi_ freezing with cx_Freeze

I am developing a PySide application (Qt for Python) and I would like to freeze it using cx_Freeze.
When I run python setup.py build using my setup file below, it creates the build directory without errors, but then when I run the .exe file generated, I get the error message shown below:
from cx_Freeze import setup, Executable
target = Executable(
script="main_window.py",
base = "Win32GUI",
icon="images\\icon.ico"
)
setup(name = "DemiurgoXMLgen" ,
version = "0.1" ,
description = "" ,
options={'build_exe': {'include_files': ['images\\']}},
executables = [target])
I think it has something to do with the Paramiko package I am using in my application. Has anyone encountered and solved this problem?
I think I solved it by modifying setup.py as below:
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
build_exe_options = {"include_files" : [
os.path.join(PYTHON_INSTALL_DIR, "DLLs", "libcrypto-1_1-x64.dll"),
os.path.join(PYTHON_INSTALL_DIR, "DLLs", "libssl-1_1-x64.dll")]}
build_exe_options = {"packages": ['cffi', 'cryptography'], 'include_files': ['images\\', os.path.join(PYTHON_INSTALL_DIR, "DLLs", "libcrypto-1_1-x64.dll"),
os.path.join(PYTHON_INSTALL_DIR, "DLLs", "libssl-1_1-x64.dll")]}
target = Executable(
script="main_window.py",
base = "Win32GUI",
icon="images\\icon.ico"
)
setup(name = "DemiurgoXMLgen" ,
version = "0.1" ,
description = "" ,
options={'build_exe': build_exe_options},
executables = [target])
and modifying in paramiko->ed25519key.py the import:
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.backends import openssl as openssl_backend
Essentially:
explicitly specify the import of cffi and cryptography in build_exe_options
copy the dlls for libcrypto-1_1-x64.dll and libssl-1_1-x64.dll
explicitly specify the backend as openssl_backend instead of default_backend

KeyError: 'TCL_LIBRARY' comes out when I use cx_Freeze [duplicate]

When I use cx_Freeze I get a keyerror KeyError: 'TCL_Library'while building my pygame program. Why do I get this and how do I fix it?
My setup.py is below:
from cx_Freeze import setup, Executable
setup(
name = "Snakes and Ladders",
version = "0.9",
author = "Adam",
author_email = "Omitted",
options = {"build_exe": {"packages":["pygame"],
"include_files": ["main.py", "squares.py",
"pictures/Base Dice.png", "pictures/Dice 1.png",
"pictures/Dice 2.png", "pictures/Dice 3.png",
"pictures/Dice 4.png", "pictures/Dice 5.png",
"pictures/Dice 6.png"]}},
executables = [Executable("run.py")],
)
You can work around this error by setting the environment variables manually:
set TCL_LIBRARY=C:\Program Files\Python35-32\tcl\tcl8.6
set TK_LIBRARY=C:\Program Files\Python35-32\tcl\tk8.6
You can also do that in the setup.py script:
os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python35-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python35-32\tcl\tk8.6'
setup([..])
But I found that actually running the program doesn't work. On the cx_freeze mailinglist it was mentioned:
I have looked into it already and no, it is not just a simple recompile --
or it would have been done already! :-)
It is in progress and it looks like it will take a bit of effort. Some of
the code in place to handle things like extension modules inside packages
is falling over -- and that may be better solved by dropping that code and
forcing the package outside the zip file (another pull request that needs
to be absorbed). I should have some time next week and the week following
to look into this further. So all things working out well I should put out
a new version of cx_Freeze before the end of the year.
But perhaps you have more luck ... Here's the bug report.
Instead of setting the environment variables using installation specific absolute paths like C:\\LOCAL_TO_PYTHON\\... you may also derive the necessary paths dynamically using the __file__ attribute of Python standard package like os:
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
After this fix the executable file will be created, but you will probably get a "DLL not found error" when you try to execute it - at least with Python 3.5.3 and cx_Freeze 5.0.1 on Windows 10.
When you add the following options, the necessary DLL-files will be copied automatically from the Python-Installation directory to the build-output of cx-Freeze and you should be able to run your Tcl/Tk application:
options = {
'build_exe': {
'include_files':[
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
],
},
}
# ...
setup(options = options,
# ...
)
Just put this before the setup at setup.py
import os
os.environ['TCL_LIBRARY'] = "C:\\LOCAL_TO_PYTHON\\Python35-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\LOCAL_TO_PYTHON\\Python35-32\\tcl\\tk8.6"
And run it:
python setup.py bdist_msi
This worked fine for me.
If you get following error with python 3.6:
copying C:\LOCAL_TO_PYTHON\Python35-32\tcl\tcl8.6 -> build\exe.win-amd64-3.6\tcl
error: [Errno 2] No such file or directory: 'C:\\LOCAL_TO_PYTHON\\Python35-32\\tcl\\tcl8.6'
Simply create LOCAL_TO_PYTHON dir in C:\ then create Python35-32 dir inside it. Now copy tcl dir from existing Python36 dir (in C:\) into Python35-32.
Then it works fine.
If you get following error with python 3.6:
copying C:\LOCAL_TO_PYTHON\Python35-32\tcl\tcl8.6 -> build\exe.win-amd64-3.6\tcl
error: [Errno 2] No such file or directory: 'C:\\LOCAL_TO_PYTHON\\Python35-32\\tcl\\tcl8.6'
Simply create LOCAL_TO_PYTHON dir in C:\ then create Python35-32 dir inside it. Now copy tcl dir from existing Python36 dir (in C:) into Python35-32.
Then it works fine.
**I did this steps and created a .exe file into the build dir but if ı try to click app dont wait on the screen instantly quick, my codes here **
from tkinter import *
import socket
window=Tk()
window.geometry("400x150")
window.title("IpConfiger")
window.config(background="black")
def goster():
x=socket.gethostbyname(socket.gethostname())
label=Label(window,text=x,fg="green",font=("Helvetica",16))
label.pack()
def information():
info=Label(window,text="Bu program anlık ip değerini
bastırır.",fg="green",font=("Helvetica",16),bg="black")
info.pack()
information()
tikla=Button(window,text="ip göster",command=goster)
tikla.pack()
D. L. Müller's answer need to be modified for cx_Freeze version 5.1.1 or 5.1.0. In these versions of cx_Freeze, packages get frozen into a subdirectory lib of the build directory. The TCL and TK DLLs need to be moved there as well. This can be achieved by passing a tuple (source, destination) to the corresponding entry of the include_files list option (see the cx_Freeze documentation).
Altogether the setup.py script needs to be modified as follows:
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
# ...
options = {
'build_exe': {
'include_files':[
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'), os.path.join('lib', 'tk86t.dll'))
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'), os.path.join('lib', 'tcl86t.dll'))
],
},
}
# ...
setup(options = options,
# ...
)
The initial KeyError problem:
This worked for me with python 3.7 on windows 7:
from cx_Freeze import setup, Executable
import os
import sys
where = os.path.dirname(sys.executable)
os.environ['TCL_LIBRARY'] = where+"\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = where+"\\tcl\\tk8.6"
build_exe_options = {"include_files": [where+"\\DLLs\\tcl86t.dll", where+"\\DLLs\\tk86t.dll"]}
setup(
name = "SudoCool",
version = "0.1",
description = "Programme de SUDOKU",
options={"build_exe": build_exe_options},
executables = [Executable("sudoku.py")]
)
Now cx_Freeze is working:
My application is working:

ModuleNotFoundError error from .pyd file

I had to to transform a module from .py to .pyd. I did it with Cython. I tested after the project, and everything worked fine. When I created a build with cx_Freeze, that .pyd module created problems. I can't understand why after building I get this ModuleNotFoundError.
File "tooth_comp.pyx", line 13, in int
src.graphics_dental_components.tooth_comp
ModuleNotFoundError: No module named 'graphics_utils.effects'
My setup script:
import sys
from cx_Freeze import setup, Executable
packages = []
excludes = []
include_files = ["assets", "views"]
build_exe_options = {"packages": packages, "excludes": excludes, "include_files": include_files}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "MyApp",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("app.py", base=base)])
The reason for the error message is because the application cannot find the extension.
Try adding graphics_utils.effects to the packages list then try recompiling.
If that does not work you could also try coping the module in the build folder manually.

build python script to exe file using cx_freeze

i am trying to convert my python script to a exe file
that anyone can run it from any computer, including computers with no python.
so i see some guides that explain the best way is to use in the cx_freeze library.
so i built a small gui application that use in tkinter only, this is my code:
import tkinter
top = tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()
and this is my setup file:
from cx_Freeze import setup, Executable
setup(
name="GUI PROGRAM",
version="0.1",
description="MyEXE",
executables=[Executable("try.py", base="Win32GUI")],
)
and i run this command:
python setup.py build
and then i get this error:
KeyError: 'TCL_LIBRARY
and it only happens when i use tkinter. so i guess i miss something and i need to add in some way the tkinter to the setup file.
can someone help me?
thanks lot you guys.
Try you altering your setup script to this:
from cx_Freeze import setup, Executable
import os
import sys
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR,'tcl','tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
files = {"include_files": ["<Path to Python>/Python36-32/DLLs/tcl86t.dll", "<Path To Python>/Python36-32/DLLs/tk86t.dll"], "packages": ["tkinter"]}
setup(
name="GUI PROGRAM",
version="0.1",
description="MyEXE",
options = {"build_exe": files},
executables=[Executable("try.py", base="Win32GUI")],
)
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR,'tcl','tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6') will remove the error message, while files = {"include_files": ["<Path to Python>/Python36-32/DLLs/tcl86t.dll", "<Path To Python>/Python36-32/DLLs/tk86t.dll"], "packages": ["tkinter"]} will include the missing Tk and Tcl runtimes.

Categories