Py2exe and ConfigParser Error - python

I'm using Py2exe and ConfigParser but I have somo problems.
I have installed configparser from pip (pip install configparser) and it works fine. In my code I import the package like this import ConfigParser and when I execute works.
Now I have used py2exe to make a distribution and the output console message is:
The following modules appear to be missing
['Carbon', 'Carbon.Files', '_sysconfigdata', 'backports.configparser']
When I have executed the .exe file, the error message is:
File "GUI.py", line 14, in <module>
File "configparser.pyc", line 12, in <module>
ImportError: No module named backports.configparser
I tried use other kind of import like:
from backports import configparser
or
import backports, backports.configparser
And the results are the same.
My setup.py file:
from distutils.core import setup
import py2exe
opts = {
'py2exe': { 'includes' : ["sys","sip", "time", "decimal"],
'excludes': ['_gtkagg', '_tkagg', '_agg2', '_cairo', '_cocoaagg','_fltkagg', '_gtk', '_gtkcairo'],
'dll_excludes': ['oci.dll','libgdk-win32-2.0-0.dll','libgobject-2.0-0.dll']}
}
data_files=[]
setup(
name='Actualizador',
version='1.0',
package={'./img/*', './campos/*'},
scripts=['GUI.py'],
console=['GUI.py'],
#windows=["GUI.py"],
options=opts,
data_files=data_files,
zipfile=None
)
I can't make my distribution and I can't solve my issue. Any suggestion?
Thank You

I solved the problem :-)
py2exe use the directory build to skip the compilation for some package which are yet compiled. Well, I remove the directory, I add the backports path to system path and I make the distribution again. And magic! That works ...

Related

ImportError: cannot import name packages

I am using cx_Freeze version 5.1.1 and I have a python 2.7.9 application to package using cx_Freeze. The application is using the python 'requests' module (the version of requests is 2.18.4)
Here is my cx_Freeze setup.py file (note I am specifically including 'requests' in the packages to include):
from cx_Freeze import setup, Executable
import sys
from cx_Freeze import setup, Executable
packages_to_include =['lib','lib/DB','encodings.ascii','requests']
buildOptions = dict(
optimize=1,
excludes = ['tkinter'],
bin_includes = [
'libcrypto.so.1.0.0',
'libcrypto.so.10',
'libgssapi_krb5.so.2',
'libk5crypto.so.3',
'libkeyutils.so.1',
'libssl.so.1.0.1e',
'libssl.so.10'
],
includes = packages_to_include,
packages= ['urllib3','idna']
)
executables = [
Executable(
'workapp.py',
targetName = 'workapp'
)
]
setup(
name='Sample Flask App',
version = '0.1',
description = 'Sample Flask App',
#requires = ["requests"],
options = dict(build_exe = buildOptions),
executables = executables
)
The build completed successfully creating the executable, but upon running my application I got the below error:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/__startup__.py", line 14, in run
module.run()
File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py", line 26, in run
exec(code, m.__dict__)
File "vaas.py", line 2, in <module>
import requests
File "/usr/local/lib/python2.7/site-packages/requests/__init__.py", line 113, in <module>
from . import packages
ImportError: cannot import name packages
I am thinking it is either an issue with my cx_Freeze setup or with requests, but since I tell cx_Freeze to include 'requests', this should work.
I checked in the build directory (that cx_Freeze builds that the requests modules has 'packages' defined and I can find it:
[user#centos-vm]$ ls build/exe.linux-x86_64-2.7/lib/requests/packages/
chardet idna urllib3
Any help is much appreciated!
Found a workaround to this issue:
edit:
/usr/local/lib/python2.7/site-packages/requests/__init__.py
and comment out:
from . import packages
Very strange issue indeed. My unfrozen application works just fine, but the above workaround is needed when using cx_freeze.
Try to add 'request' to the packages list option instead of adding it to the includes list options:
packages= ['urllib3', 'idna', 'requests']
According to the cx_Freeze documentation, the build_exe option includes is a
comma separated list of names of modules to include
whereas the build_exe option packages is a
comma separated list of packages to include, which includes all submodules in the package

py2app can't import pandas

I am trying to create a standalone app from a python 2.7 script I have run many times and so I followed a tutorial and created the setup file that looks like this:
from setuptools import setup
APP = ['scrapeMaps.py']
DATA_FILES = ['export.csv']
OPTIONS = {'argv_emulation': True,}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
When I locate the scrapeMaps file (the one that was created when I did $ python setup.py py2app -A) and try to run it, I get an error saying
import pandas as pd
ImportError: No module named pandas
I have used pandas numerous times and it works perfectly.
I have tried adding
PKGS = ['pandas']
OPTIONS = {'argv_emulation': True,
'packages' : PKGS,}
without success. Also, none of my other imports are working (if I remove import pandas, I will get an error at import selenium)
Also tried:
$ python setup.py py2app --packages=pandas
but I get a huge syntax error.
Thanks

cx_Freeze 5.0: ImportError: No module named 'scipy.__config__'

Problem
I get the following error when trying to run an .exe built with cx_Freeze:
File
"C:\\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\__init__py", line 105 in <module>
from scipy.__config__ import show as show_config
ImportError: No module named 'scipy.__config__'
During handling of the above exception, another exception occurred:
...
File
"C:\\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\__init__py", line 105 in <module>
raise ImportError(msg)
ImportError: Error importing scipy: you cannot import scipy while being in scipy source directory; please exit the scipy source tree first, and relaunch your python interpreter.
How could I troubleshoot this?
Additional Information
Setup
Windows 7 Enterprise 64-bit
WinPython-64bit-3.5.2.3Qt5 (Python 3.5.2 64-bit)
cx_Freeze 5.0 (*)
scipy 0.18.1
(*) With pythoncom fix in the hooks.py
setup.py:
import os
import sys
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = r"C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = r"C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\tcl\tk8.6"
base = 'Console'
if sys.platform == 'win32':
base = 'Win32GUI'
options = {
'build_exe': {
'excludes': ['gtk', 'PyQt4', 'Tkinter'],
}
}
executables = [
Executable('GUI.py', base=base)
]
setup(name='GUI',
version='0.1',
description='GUI test',
executables=executables,
options=options
)
Errors during build
None.
What else have I tried?
1) Tried to add 'includes': ['scipy.__config__'] to the setup.py.
Result: error during build ImportError: No module named 'scipy.__config__'
2) Tried to add 'packages': ['scipy'], to the setup.py.
Result: error during build ImportError: No module named 'scipy'
3) Renamed the finder.IncludePackage("scipy.lib") in the cx_Freeze/hooks.py to finder.IncludePackage("scipy._lib") as instructed in the answer of the SO Question "Cx_freeze ImportError no module named scipy" + added 'packages': ['scipy'], to the setup.py.
Result: No build-time errors. When trying to run the .exe, it gives ImportError: No module named 'scipy.spatial.ckdtree'
Tried also with 'includes': ['scipy.spatial.ckdtree'] in the setup.py, but the problem persists.
The build output has the following lines:
m scipy.spatial.cKDTree C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\spatial\cKDTree.cp35-win_amd64.pyd
m scipy.spatial.ckdtree C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\spatial\ckdtree.cp35-win_amd64.pyd
I think I have a solution (not the greatest but it works). Go to the scipy\spatial directory (within the build directory) and change the file from cKDTree.cp36-win_amd64.pyd to ckdtree.cp36-win_amd64.pyd.
NOTE: your file name might be slightly different depending which python version but the main thing is to use lowercase kdt in the file name.
The capital letters is the problem. It worked for me.

ImportError: No module named matplotlib.python-dateutil

I'm trying to use py2exe to convert my .pyw to executable file, and
encountered this error - "ImportError: No module named matplotlib.python-dateutil"
I've installed dateutil before trying to convert this .pyw to .exe,
and .pyw file itself worked fine and produced the expected output,
but I didn't manage to get the .exe file.
I also have tried put a copy of python-dateutil inside matplotlib folder but still did not solve the problem.
I'm using Python 2.7 and python-dateutil 2.2.
This is my setup.pyw. copied from (http://www.py2exe.org/index.cgi/MatPlotLib)
from distutils.core import setup
import py2exe
import matplotlib
matplotlibdatadir = matplotlib.get_data_path()
matplotlibdata = findall(matplotlibdatadir)
matplotlibdata_files = [] for f in matplotlibdata:
dirname = os.path.join('matplotlibdata', f[len(matplotlibdatadir)+1:])
matplotlibdata_files.append((os.path.split(dirname)[0], [f]))
setup(
windows = ['graph.pyw'],
options = {
'py2exe': {
'packages' : ['matplotlib', 'pytz'],
}
},
#data_files = matplotlibdata_files
data_files = matplotlib.get_py2exe_datafiles() )
Appreciate feedback and ideas..thank you very much in advance
I think you need to put matplotlib.python-dateutil in the packages list:
'packages' : ['matplotlib', 'matplotlib.python-dateutil', 'pytz'],
When this hasn't fixed similar hassles for me, I've sometimes found that you need to wildcard submodules:
'packages' : ['matplotlib', 'matplotlib.python-dateutil.*', 'pytz'],
YMMV on that one.

How to include a module dependency as a part of py2exe script

I got a windows installer my_script.exe (generated out of my_script.py using py2exe) which is dependent on "PyDes" module,
when I execute my_script.exe it throws an error saying ,
Import error : pyDes module
How to include the pyDes module as a dependency to my_script.py
I am using py2exe to create windows installer.
python setup.py py2exe
Try adding 'includes': ['PyDes'], to the relevant spot in your setup.py file
setup(
# ...
options = {
'includes': ['PyDes'],
},
# ...
)
assuming that PyDes is in your sys.path
N.B. If py2exe hasn't picked up the PyDes dependency, chances are it hasn't picked up anything that PyDes depends on so be prepared for more ImportError's! Just keep adding them to the 'include' until it all works out.

Categories

Resources