I am fairly new to Python and I need some help with an error message I am receiving. I am trying to make an exe file from a tkinter script with the help of py2exe, but I keep getting an AssertionError whenever I try to run the setup.py script. I have already created an exe file on my computer only a couple of days ago out of the same script without using tkinter. Creating this exe file was no problem. I am wondering if the error message occurs due to the fact that I have already created an exe file recently.
My setup.py script looks normal:
`# setup.py
from distutils.core import setup
import py2exe
setup(console=['MyScript.py'])`
Whenever I run it, I get this error:
AssertionError: distutils has already been patched by <class 'py2exe.patch_distutils.patch_distutils.<locals>.Distribution'>
The entire traceback looks like this:
Traceback (most recent call last):
File "C:\Dir\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pycharm\pycharm_setup_runner.py", line 26, in <module>
exec (fh.read(), globals(), locals())
File "<string>", line 6, in <module>
File "C:\Dir\Python3\lib\distutils\core.py", line 134, in setup
ok = dist.parse_command_line()
File "C:\Dir\Python3\lib\distutils\dist.py", line 471, in parse_command_line
args = self._parse_command_opts(parser, args)
File "C:\Dir\Python3\lib\distutils\dist.py", line 527, in _parse_command_opts
cmd_class = self.get_command_class(command)
File "C:\Dir\Python3\lib\distutils\dist.py", line 817, in get_command_class
__import__ (module_name)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pycharm\pycharm_commands\pycharm_test.py", line 4, in <module>
from setuptools.command import test
File "C:\Dir\Python3\lib\site-packages\setuptools\__init__.py", line 14, in <module>
from setuptools.extension import Extension
File "C:\Dir\Python3\lib\site-packages\setuptools\extension.py", line 10, in <module>
from .dist import _get_unpatched
File "C:\Dir\Python3\lib\site-packages\setuptools\dist.py", line 39, in <module>
_Distribution = _get_unpatched(_Distribution)
File "C:\Dir\Python3\lib\site-packages\setuptools\dist.py", line 35, in _get_unpatched
"distutils has already been patched by %r" % cls
AssertionError: distutils has already been patched by <class'py2exe.patch_distutils.patch_distutils.<locals>.Distribution'>
Does anyone know a workaround to this problem? I am working in Python3.4.1.
Thank you so much for helping!
Try importing setuptools before you import py2exe.
It worked for me.
Related
I'm trying to get the Revit python shell debugger working in my dynamo but I'm running into issues. It seems to run in Revit alright but I cant get the debugger in dynamo to work as shown here.
Also if anyone has any other methods for debugging python code in Revit, feel free to let me know!
Here is the error I'm getting:
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File "<string>", line 13, in <module>
File "C:\Users\cmaltez\AppData\Roaming\Dynamo\Dynamo Revit\2.6\packages\RevitPythonWrapper\extra\rpw.zip\rpw\__init__.py", line 36, in <module>
File "C:\Users\cmaltez\AppData\Roaming\Dynamo\Dynamo Revit\2.6\packages\RevitPythonWrapper\extra\rpw.zip\rpw\db\__init__.py", line 19, in <module>
File "C:\Users\cmaltez\AppData\Roaming\Dynamo\Dynamo Revit\2.6\packages\RevitPythonWrapper\extra\rpw.zip\rpw\db\view.py", line 10, in <module>
File "C:\Users\cmaltez\AppData\Roaming\Dynamo\Dynamo Revit\2.6\packages\RevitPythonWrapper\extra\rpw.zip\rpw\db\collector.py", line 35, in <module>
File "C:\Users\cmaltez\AppData\Roaming\Dynamo\Dynamo Revit\2.6\packages\RevitPythonWrapper\extra\rpw.zip\rpw\ui\__init__.py", line 1, in <module>
File "C:\Users\cmaltez\AppData\Roaming\Dynamo\Dynamo Revit\2.6\packages\RevitPythonWrapper\extra\rpw.zip\rpw\ui\forms\__init__.py", line 12, in <module>
File "C:\Users\cmaltez\AppData\Roaming\Dynamo\Dynamo Revit\2.6\packages\RevitPythonWrapper\extra\rpw.zip\rpw\ui\forms\flexform.py", line 6, in <module>
File "C:\Users\cmaltez\AppData\Roaming\Dynamo\Dynamo Revit\2.6\packages\RevitPythonWrapper\extra\rpw.zip\rpw\ui\forms\resources.py", line 41, in <module>
File "C:\Program Files\Autodesk\Revit 2021\AddIns\DynamoForRevit\IronPython.StdLib.2.7.9\wpf.py", line 11, in <module>
ImportError: No module named _wpf
Which is odd because it seems I have the package located in the directory from the install.
This is what my Dynamo looks like. its the getting started file that comes with RPW.
Here is what I've tried so far:
I've added this path to my searching path here: "C:\Program Files (x86)\IronPython 2.7\Platforms\Net40" according to this post.
Here is an image of my searching path:
RPS works in Revit but doesn't work in dynamo for debugging python scripts.
Here are the contents of wpf.py
#-*- coding: ISO-8859-1 -*-
def _():
import sys
if sys.platform == 'cli':
import clr
clr.AddReference('IronPython.Wpf')
_()
del _
from _wpf import *
any and all help would be appreciated!
So after hours of testing different things, I finally tried to just open the wpf.py file and change the line:
from _wpf import *
to
from wpf import *
and I'm now able to access rpw in dynamo.
but I cant get the debugger working in pycharm still.
I also added the paths to the Net40 folder, the unzipped rpw folder that comes in the install, and the location of my iron python folder
i created exe using py2exe after that i facing this below error
i checked in lib directory and Queue.py is already present in that directory
please help me to resolve this issue
im using python 2.7
Traceback (most recent call last):
File "Game2048.py", line 12, in <module>
File "pynput\__init__.pyc", line 23, in <module>
File "pynput\keyboard\__init__.pyc", line 44, in <module>
File "pynput\keyboard\_win32.pyc", line 32, in <module>
File "pynput\_util\__init__.pyc", line 34, in <module>
File "six.pyc", line 203, in load_module
File "six.pyc", line 115, in _resolve
File "six.pyc", line 82, in _import_module
ImportError: No module named Queue
py2exe decides which modules to include in the final ZIP-file or executable by examining the import statements in those module(s) explicitly mentioned in setup.py. It then adds these imported modules to the dependencies of the executable and checks all import statements in these newly added modules to find further necessary modules and so on until no more new modules can be found in the imports.
Here, the module Queue is imported in a dynamical way, basically by calling something like __import__("Queue") which can't be automatically recognized by py2exe. Therefore the module isn't seen as necessary.
To solve this add an artificial dependency in a module which is already added to the executable:
if False:
import Queue
The code has no effect but py2exe sees the import statement and will follow it.
I have a python program that used Tkinter, matplotlib, numpy.
It was builded successfully on my windows 8 host system by py2exe and running as well.
I have one system based on windows 7 where this program (builded on windows 8) working too.
But when i trying to start this program on windows xp sp3, i get error in log file with a content of:
Traceback (most recent call last):
File "DrawPlots.py", line 6, in <module>
File "graph_ani2.pyc", line 4, in <module>
File "numpy\__init__.pyc", line 170, in <module>
File "numpy\add_newdocs.pyc", line 13, in <module>
File "numpy\lib\__init__.pyc", line 8, in <module>
File "numpy\lib\type_check.pyc", line 11, in <module>
File "numpy\core\__init__.pyc", line 46, in <module>
File "numpy\testing\__init__.pyc", line 13, in <module>
File "numpy\testing\utils.pyc", line 15, in <module>
File "tempfile.pyc", line 35, in <module>
File "random.pyc", line 885, in <module>
File "random.pyc", line 97, in __init__
File "random.pyc", line 113, in seed
WindowsError: [Error -2146893795]
As i can suggest - is it problem with numpy? If yes, then how can i resolve it?
I faced a similar problem, PyFactura issue #3, the solution seems to be removing crypt32.dll from the bundled DLLs (py2exe setup options, for more info see aws-cli):
# basic options for py2exe
opts = {
'py2exe': {
'dll_excludes': ['crypt32.dll'],
}
}
You may need to exclude other specific Windows 8.1 DLL too (API-MS-Win-Core-*.dll)
I also had this error, concretely this output:
WindowsError: [Error -2146893795] Provider DLL failed to initialize correctly
This happened at a call to os.urandom.
This was in a subprocess.
The bug for me was that I called _subprocess.CreateProcess with an env_mapper = {'foo': 'bar'}. The fix:
env_mapper = os.environ.copy()
env_mapper.update({'foo': 'bar'})
Note that there is a related question here.
And some discussion on this GitHub issue.
And this related Python bug.
All those seem to be related to crypt32.dll in a frozen Python app, or via py2app.
I installed pygui and pywin32 for my 64-bit python 2.7 (I installed 64-bit for those too) and when I try to use pygui, which uses pywin32, python gives me this error.
I'm sure that other people might have similar problems.
Traceback (most recent call last):
File "C:\Users\MY_USERNAME_HERE\Dropbox\Python Programs\BlobEdit\BlobEdit.py", line 16, in <module>
from GUI import Application, ScrollableView, Document, Window, Cursor, rgb
File "C:\Program Files\python2.7.2\lib\site-packages\GUI\__init__.py", line 94, in <module>
import GUI.Application
File "C:\Program Files\python2.7.2\lib\site-packages\GUI\Application.py", line 11, in <module>
from GUI.GApplications import Application as GApplication
File "C:\Program Files\python2.7.2\lib\site-packages\GUI\GApplications.py", line 14, in <module>
from GUI.Printing import PageSetup, present_page_setup_dialog
File "C:\Program Files\python2.7.2\lib\site-packages\GUI\Printing.py", line 11, in <module>
from GUI import Canvas
File "C:\Program Files\python2.7.2\lib\site-packages\GUI\Canvas.py", line 15, in <module>
from GUI.StdFonts import application_font
File "C:\Program Files\python2.7.2\lib\site-packages\GUI\StdFonts.py", line 9, in <module>
from GUI import Font
File "C:\Program Files\python2.7.2\lib\site-packages\GUI\Font.py", line 56, in <module>
pywin32_info = api.GetFileVersionInfo(api.__file__, '\\')
error: (1813, 'GetFileVersionInfo:GetFileVersionInfoSize', 'The specified resource type cannot be found in the image file.')
Apparently, PyWin32 can't find it's version or something. I wonder why.
I've had this issue, which led me to this question.
I'm using python 3.3 and had already installed pywin32-218, so my solution was this hack in Font.py:
#pywin32_info = api.GetFileVersionInfo(api.__file__, '\\')
pywin32_build = 218 # pywin32_info['FileVersionLS'] >> 16
I've had this issue too, easy solution: install the minimum required pywin32 version 213. Somewhere there a version check happening in pywin32 on some file. Perhaps some day i will dig into it further and post a more detailed post and/or file a bug
I'm trying to create executable program with py2exe. I get the following error message when kinterbasdb is imported:
Traceback (most recent call last):
File "AlarmReporter.py", line 13, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "kinterbasdb\__init__.pyo", line 119, in <module>
File "zipextimporter.pyo", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading kinterbasdb\_kinterbasdb.pyd
Here's my very basic setup.py for py2exe:
from distutils.core import setup
import py2exe
import sys
setup(
options={'py2exe': dict(bundle_files=1, optimize=2)},
console=['AlarmReporter.py'],
zipfile=None,
)
I'm having problem understanding the error message and have no idea how to fix it.
Try to exclude libfbclient dll
Error while transforming .py to .exe
If that doesn't work , try to use the new fdb driver (the future replacement of kinterbasdb)
http://permalink.gmane.org/gmane.comp.db.firebird.python/104
(it doesn't need compiling only the libfbclient.dll)
Another option is to use the pure driver that doesn't need no dll and no c generated binary
https://github.com/nakagami/pyfirebirdsql
But you will use it at your own risk ;)