I am playing around with getting some basic stuff to work in Python before i go into full speed dev mode. Here are the specifics:
Python 2.5.4
PyQt4 4.4.3
SqlAlchemy 0.5.2
py2exe 0.6.9
setuptools 0.6c9
pysqlite 2.5.1
setup.py:
from distutils.core import setup
import py2exe
setup(windows=[{"script" : "main.py"}], options={"py2exe" : {"includes" : ["sip", "PyQt4.QtSql","sqlite3"],"packages":["sqlite3",]}})
py2exe appears to generate the .exe file correctly, but when i execute dist/main.exe i get this in the main.exe.log
Traceback (most recent call last):
File "main.py", line 18, in <module>
File "main.py", line 14, in main
File "db\manager.pyc", line 12, in __init__
File "sqlalchemy\engine\__init__.pyc", line 223, in create_engine
File "sqlalchemy\engine\strategies.pyc", line 48, in create
File "sqlalchemy\engine\url.pyc", line 91, in get_dialect
ImportError: No module named sqlite
I've been googling my heart out, but can't seem to find any solutions to this. If i can't get this to work now, my hopes of using Python for this project will be dashed and i will start over using Ruby... (not that there is anything wrong with Ruby, i just wanted to use this project as a good way to teach myself Python)
you need to include the sqlalchemy.databases.sqlite package
setup(
windows=[{"script" : "main.py"}],
options={"py2exe" : {
"includes": ["sip", "PyQt4.QtSql"],
"packages": ["sqlalchemy.databases.sqlite"]
}})
you need change to sqlalchemy.dialects.sqlite package
setup(
windows=[{"script" : "main.py"}],
options={"py2exe" : {
"includes": ["sip", "PyQt4.QtSql"],
"packages": ["sqlalchemy.dialects.sqlite"]
}})
Related
I am trying to build executable file of my project(Python 2.7.5) but getting this below error when trying to run the executable.
ERROR \ProjectPython\library.zip\distutils\__init__.py:14: UserWarning: The virtualenv
distutils package at %s appears to be in the same location as the system distutils?
Traceback (most recent call last):
File "main.py", line 130, in <module>
...
File "pandas\compat\__init__.pyo", line 32,in <module>
File "zipextimporter.pyo", line 82, in load_module
File "distutils\__init__.pyo", line 25, in <module>
ERROR ImportError: cannot import name dist
After searching for solutions to this issue, I got to know that this must be because of distutils in virtualenv is different from whats in Python installation Lib directory. So, I have been trying to exclude/remove distutils in virtualenv and add distutils package of my origin interpreter during executable build.
That exact solution exists for cxfreeze, but couldn't find alternate solution for py2exe. My setup.py options looks something like
distutils.core.setup(
options = {"py2exe": {
"compressed": 1,
"optimize": 1,
"bundle_files": 1,
"packages": ['psycopg2', 'lxml', 'sqlalchemy', 'openpyxl', 'pandas', 'numpy']
}}
Any help on this is much appreciated. Thanks !
Given the information you've shared, it seems that you might be going the wrong direction with excluding distutils. The error (warning) is stating that distutils package at %s appears to be in the same location as the system distutils.
Try creating a fresh virtual environment with the needed libraries and building again.
I have a console mode program that I would like to distribute with cx_Freeze. I have just downloaded python 3.6.3 (both amd64 and win32 version) on a newly installed win 10 machine. I have installed cx_Freeze 5.1 from wheels (not from pypi). Then I have built both amd64 and win32 versions of the program. If I try to execute that exe file on the same machine where I have built it, I get this error:
Fatal Python error: Py_Initialize: unable to load the file system codec
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\encodings\__init__.py", line 31, in <module>
ModuleNotFoundError: No module named 'codecs'
I have the same error on both architectures. The setup file looks like this:
#!/usr/bin/env python3
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"packages": [
"os", "io", "copy", "struct", "hashlib", "random",
"urllib", "pycurl", "json", "multiprocessing",
"cryptography",
"tornado", "watchdog", "pathtools"
],
"includes": [
"cryptography", "urllib.parse",
],
"include_files": ["tmp", "server.ini", "client.ini"],
"excludes": ["tkinter"],
}
setup(
name="BlindBackup",
version="1.0",
description="BlindBackup",
options={"build_exe": build_exe_options},
executables=[
Executable("backup.py", base=None),
Executable("bsync.py", base=None),
Executable("server.py", base=None),
]
)
In other words, I have specified the "codecs" package explicitly.
What is wrong?
UPDATE There is a file called library.zip in the distribution dir. It contains codecs.pyc but the exe file does not see it. If I extract all files from that zip, then I get a different error message:
C:\Python\Projects\blindbackup\build\exe.win-amd64-3.6>backup.exe
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "C:\Program Files\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py", line 22, in run
importer = zipimport.zipimporter(os.path.dirname(os.__file__))
zipimport.ZipImportError: not a Zip file
I guess that the problem is with the code that tries to import modules from the library.zip file? But not sure how to fix it.
The solution was this:
install cx_freeze 6, because version 5 does not support python 3.6 (apparently)
install pywin32 (although it was not required for my program)
add all missing pyd files to "includes" and all missing packages to "packages" section it the setup script.
I have a python 2.7 script that uses zmq and am trying to build a windows executable for it using py2exe. I get the following error:
Traceback (most recent call last):
File "console.py", line 4, in <module>
File "zmq\__init__.pyc", line 34, in <module>
File "zmq\backend\__init__.pyc", line 40, in <module>
File "zmq\backend\__init__.pyc", line 27, in <module>
File "zmq\backend\select.pyc", line 26, in select_backend
ImportError: No module named cython
I have tried py2exe --includes option, including cython and zmq with no success. I have also tried running the script with -O option and copying the resulting .pyo files to my dist directory. What am I missing?
This did the trick in my setup.py
import zmq.libzmq
setup(\
version='0.0.1',
options = {'py2exe' : {
'includes': [ 'zmq.backend.cython'],
"optimize": 2,
'packages': 'encodings'
},
},
data_files=[
('lib', (zmq.libzmq.__file__,))
],
console=['app.py'],
scripts = [ "app.py","file1.py","file2.py","file3.cfg"],
zipfile = 'None',
)
Hope it helps someone.
I want to create an exe file using Py2exe module. The problem is that the exe file says that there is not os module. I've put it into includes in setup.py file so it should work.
Here is the error after run main.exe created by Py2Exe
import linecache
ImportError: No module named linecache
Traceback (most recent call last):
File "main.py", line 3, in <module>
ImportError: No module named os
And here is my setup.py:
from distutils.core import setup
import py2exe
setup(console=["main.py"],options = {
"py2exe":{
"includes": ["os","linecache"]
}
},)
The problem is that if you want to import packages, you should use the option packages and not includes. The first one imports libraries, the second modules.py.This should work now:
from distutils.core import setup
import py2exe
setup(console=["main.py"],
options = {
"py2exe":{
"packages": ["os","linecache"]
}
})
I'm trying to create a standalone, desktop version of a MoinMoin wiki so I can distribute it on a CDROM to people who may or may not have Python installed. I've tried both py2exe and bbfreeze with no luck. They both create an executable, but when that executable is run I get the same error from both:
C:\python_class\cdrom\bb-binary>wikiserver.exe
2011-08-22 15:06:21,312 WARNING MoinMoin.log:138 load_config for "C:\python_class\cdrom\bb-binary\wikiserverlogging.conf
" failed with "No section: 'formatters'".
2011-08-22 15:06:21,312 WARNING MoinMoin.log:139 using logging configuration read from built-in fallback in MoinMoin.log
module!
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "__main__.py", line 128, in <module>
File "__main__wikiserver__.py", line 35, in <module>
File "MoinMoin/script/__init__.py", line 138, in run
File "MoinMoin/script/__init__.py", line 248, in mainloop
File "MoinMoin/wikiutil.py", line 1078, in importBuiltinPlugin
File "MoinMoin/wikiutil.py", line 1117, in builtinPlugins
File "MoinMoin/util/pysupport.py", line 81, in importName
ImportError: No module named server
Here is the setup.py script I used for py2exe:
from distutils.core import setup
import py2exe
includes = ["MoinMoin"]
excludes = []
packages = []
setup(options = {
"py2exe" : {
"includes" : includes,
"excludes" : excludes,
"packages" : packages,
"dist_dir" : "dist"
}
},
console=["wikiserver.py"])
And here is the setup.py script I used for bbfreeze:
from bbfreeze import Freezer
includes = ["MoinMoin.*"]
excludes = []
f = Freezer(distdir="bb-binary", includes=includes, excludes=excludes)
f.addScript("wikiserver.py")
f.use_compression = 0
f.include_py = True
f()
If anyone has any help or suggestions, I'd greatly appreciate it!
Thanks,
Doug
py2exe has limitations in identifying which modules to include, especially if they are imported conditionally. For example,
import module
on its own line will work, however,
if someCondition:
import module
won't. As is often the case with many large frameworks, MoinMoin only imports the modules it needs to use when it needs them. Unfortunately, you will need to tell py2exe to include these missing modules manually, and this is going to take some trial-and-error until you find all the ones you need.
See here for how to include modules manually.