Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module Not Found Error #104

Closed
rcolpo opened this issue Jun 8, 2020 · 12 comments
Closed

Module Not Found Error #104

rcolpo opened this issue Jun 8, 2020 · 12 comments

Comments

@rcolpo
Copy link

rcolpo commented Jun 8, 2020

I'm trying to make an executable file out of the python code below:

import cobra
import _libsbml
print(1)

However, I keep receiving the error message
ModuleNotFoundError: No module named '_libsbml'

Any ideas on how to solve this?
The line "import _libsbml" was not in my original code. I added it while trying to solve this problem. I also added "_libsbml" on the "--hiddenimport" advanced field, but without results.

@brentvollebregt
Copy link
Owner

What is the "Current Command" that auto-py-to-exe displayed when you packaged your script?

@rcolpo
Copy link
Author

rcolpo commented Jun 9, 2020

Current Command:
pyinstaller --noconfirm --onedir --nowindowed "C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest.py"

Output:

Running auto-py-to-exe v2.7.4
Building directory: C:\Users\colpoama\AppData\Local\Temp\tmp_xijgwf9
Provided command: pyinstaller --noconfirm --onedir --nowindowed  "C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onedir --nowindowed C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest.py --distpath C:\Users\colpoama\AppData\Local\Temp\tmp_xijgwf9\application --workpath C:\Users\colpoama\AppData\Local\Temp\tmp_xijgwf9\build --specpath C:\Users\colpoama\AppData\Local\Temp\tmp_xijgwf9

139942 INFO: PyInstaller: 3.6
139950 INFO: Python: 3.7.6
139956 INFO: Platform: Windows-10-10.0.18362-SP0
139972 INFO: wrote C:\Users\colpoama\AppData\Local\Temp\tmp_xijgwf9\exePythonTest.spec
139983 INFO: UPX is not available.
139994 INFO: Extending PYTHONPATH with paths
['C:\\phd\\Eric\\SBMLComp-master\\Scripts',
 'C:\\Users\\colpoama\\AppData\\Local\\Temp\\tmp_xijgwf9']
140001 INFO: checking Analysis
140009 INFO: Building Analysis because Analysis-00.toc is non existent
140014 INFO: Initializing module dependency graph...
140026 INFO: Caching module graph hooks...
140051 INFO: Analyzing base_library.zip ...
143365 INFO: Caching module dependency graph...
143451 INFO: running Analysis Analysis-00.toc
143477 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\colpoama\appdata\local\programs\python\python37\python.exe
143551 INFO: Analyzing C:\phd\Eric\SBMLComp-master\Scripts\exePythonTest.py
145649 INFO: Processing pre-find module path hook   distutils
145658 INFO: distutils: retargeting to non-venv dir 'c:\\users\\colpoama\\appdata\\local\\programs\\python\\python37\\lib'
149752 INFO: Processing pre-find module path hook   site
149763 INFO: site: retargeting to fake-dir 'c:\\users\\colpoama\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\PyInstaller\\fake-modules'
150847 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
159006 INFO: Processing pre-safe import module hook   six.moves
163760 INFO: Processing pre-safe import module hook   urllib3.packages.six.moves
196661 INFO: Processing pre-safe import module hook   win32com
205317 INFO: Processing module hooks...
205325 INFO: Loading module hook "hook-certifi.py"...
205339 INFO: Loading module hook "hook-distutils.py"...
205352 INFO: Loading module hook "hook-encodings.py"...
205540 INFO: Loading module hook "hook-gevent.py"...
205960 INFO: Determining a mapping of distributions to packages...
228000 WARNING: Unable to find package for requirement greenlet from package gevent.
228009 WARNING: Unable to find package for requirement zope.event from package gevent.
228020 WARNING: Unable to find package for requirement zope.interface from package gevent.
228028 INFO: Packages required by gevent:
['setuptools', 'cffi']
229760 INFO: Loading module hook "hook-importlib_metadata.py"...
229773 INFO: Loading module hook "hook-IPython.py"...
230770 INFO: Excluding import 'gtk'
230786 INFO: Excluding import 'PyQt4'
230800 INFO:   Removing import of PyQt4 from module IPython.external.qt_loaders
230808 INFO: Excluding import 'PyQt5'
230824 INFO:   Removing import of PyQt5 from module IPython.external.qt_loaders
230832 INFO: Excluding import 'tkinter'
230847 INFO:   Removing import of tkinter from module IPython.lib.clipboard
230857 INFO: Excluding import 'matplotlib'
230872 INFO:   Removing import of matplotlib from module IPython.core.pylabtools
230879 INFO:   Removing import of matplotlib._pylab_helpers from module IPython.core.pylabtools
230891 INFO:   Removing import of matplotlib.pyplot from module IPython.core.pylabtools
230899 INFO:   Removing import of matplotlib.figure from module IPython.core.pylabtools
230909 INFO:   Removing import of matplotlib from module IPython.lib.latextools
230917 INFO:   Removing import of matplotlib.mathtext from module IPython.lib.latextools
230927 INFO: Excluding import 'PySide'
230944 INFO:   Removing import of PySide from module IPython.external.qt_loaders
230953 INFO: Loading module hook "hook-jedi.py"...
231219 INFO: Loading module hook "hook-jinja2.py"...
231251 INFO: Loading module hook "hook-jsonschema.py"...
231271 INFO: Loading module hook "hook-lib2to3.py"...
231297 INFO: Loading module hook "hook-matplotlib.backends.py"...
232343 INFO:   Matplotlib backend "GTK3Agg": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
232723 INFO:   Matplotlib backend "GTK3Cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
233315 INFO:   Matplotlib backend "MacOSX": ignored
    cannot import name '_macosx' from 'matplotlib.backends' (C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\matplotlib\backends\__init__.py)
234315 INFO:   Matplotlib backend "nbAgg": added
234853 INFO:   Matplotlib backend "Qt4Agg": ignored
    Failed to import any qt binding
235307 INFO:   Matplotlib backend "Qt4Cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
235854 INFO:   Matplotlib backend "Qt5Agg": ignored
    Failed to import any qt binding
236303 INFO:   Matplotlib backend "Qt5Cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
237022 INFO:   Matplotlib backend "TkAgg": added
237612 INFO:   Matplotlib backend "TkCairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
238218 INFO:   Matplotlib backend "WebAgg": added
238758 INFO:   Matplotlib backend "WX": ignored
    No module named 'wx'
239197 INFO:   Matplotlib backend "WXAgg": ignored
    No module named 'wx'
239576 INFO:   Matplotlib backend "WXCairo": ignored
    No module named 'wx'
239963 INFO:   Matplotlib backend "agg": added
240398 INFO:   Matplotlib backend "cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
240872 INFO:   Matplotlib backend "pdf": added
241410 INFO:   Matplotlib backend "pgf": added
241783 INFO:   Matplotlib backend "ps": added
242179 INFO:   Matplotlib backend "svg": added
242708 INFO:   Matplotlib backend "template": added
242980 INFO: Loading module hook "hook-matplotlib.py"...
243368 INFO: Loading module hook "hook-nbconvert.py"...
243415 INFO: Loading module hook "hook-nbformat.py"...
243442 INFO: Loading module hook "hook-notebook.py"...
244936 INFO: Loading module hook "hook-numpy.core.py"...
245039 INFO: Loading module hook "hook-numpy.py"...
245053 INFO: Loading module hook "hook-pandas.py"...
246259 INFO: Loading module hook "hook-pkg_resources.py"...
246944 INFO: Excluding import '__main__'
246960 INFO:   Removing import of __main__ from module pkg_resources
246970 INFO: Loading module hook "hook-pycparser.py"...
246988 INFO: Loading module hook "hook-pydoc.py"...
247003 INFO: Loading module hook "hook-pygments.py"...
249125 INFO: Loading module hook "hook-pytest.py"...
250026 INFO: Loading module hook "hook-pythoncom.py"...
250491 INFO: Loading module hook "hook-pytz.py"...
250617 INFO: Loading module hook "hook-pywintypes.py"...
251079 INFO: Loading module hook "hook-scipy.io.matlab.py"...
251100 INFO: Loading module hook "hook-scipy.linalg.py"...
251121 INFO: Loading module hook "hook-scipy.py"...
251153 INFO: Loading module hook "hook-scipy.sparse.csgraph.py"...
251175 INFO: Loading module hook "hook-scipy.special._ellip_harm_2.py"...
251195 INFO: Loading module hook "hook-scipy.special._ufuncs.py"...
251214 INFO: Loading module hook "hook-setuptools.py"...
252012 INFO: Loading module hook "hook-sqlite3.py"...
252202 INFO: Loading module hook "hook-sysconfig.py"...
252218 INFO: Loading module hook "hook-win32com.py"...
252808 INFO: Loading module hook "hook-xml.dom.domreg.py"...
252824 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
252844 INFO: Loading module hook "hook-xml.py"...
252862 INFO: Loading module hook "hook-zmq.py"...
253766 INFO: Loading module hook "hook-_tkinter.py"...
254107 INFO: checking Tree
254125 INFO: Building Tree because Tree-00.toc is non existent
254143 INFO: Building Tree Tree-00.toc
254304 INFO: checking Tree
254318 INFO: Building Tree because Tree-01.toc is non existent
254340 INFO: Building Tree Tree-01.toc
254721 INFO: Looking for ctypes DLLs
254992 INFO: Analyzing run-time hooks ...
255049 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
255076 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
255102 INFO: Including run-time hook 'pyi_rth__tkinter.py'
255127 INFO: Including run-time hook 'pyi_rth_traitlets.py'
255151 INFO: Including run-time hook 'pyi_rth_certifi.py'
255179 INFO: Including run-time hook 'pyi_rth_mplconfig.py'
255204 INFO: Including run-time hook 'pyi_rth_mpldata.py'
255228 INFO: Including run-time hook 'pyi_rth_pkgres.py'
255335 INFO: Looking for dynamic libraries
256609 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\context.cp37-win_amd64.pyd
256633 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\utils.cp37-win_amd64.pyd
256661 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\message.cp37-win_amd64.pyd
256685 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\_device.cp37-win_amd64.pyd
256711 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\_proxy_steerable.cp37-win_amd64.pyd
256737 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\socket.cp37-win_amd64.pyd
256763 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\error.cp37-win_amd64.pyd
256795 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\_version.cp37-win_amd64.pyd
256825 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\_poll.cp37-win_amd64.pyd
258558 INFO: Looking for eggs
258573 INFO: Using Python library c:\users\colpoama\appdata\local\programs\python\python37\python37.dll
258595 INFO: Found binding redirects: 
[]
258673 INFO: Warnings written to C:\Users\colpoama\AppData\Local\Temp\tmp_xijgwf9\build\exePythonTest\warn-exePythonTest.txt
259380 INFO: Graph cross-reference written to C:\Users\colpoama\AppData\Local\Temp\tmp_xijgwf9\build\exePythonTest\xref-exePythonTest.html
259731 INFO: checking PYZ
259749 INFO: Building PYZ because PYZ-00.toc is non existent
259766 INFO: Building PYZ (ZlibArchive) C:\Users\colpoama\AppData\Local\Temp\tmp_xijgwf9\build\exePythonTest\PYZ-00.pyz
268190 INFO: Building PYZ (ZlibArchive) C:\Users\colpoama\AppData\Local\Temp\tmp_xijgwf9\build\exePythonTest\PYZ-00.pyz completed successfully.
268352 INFO: checking PKG
268369 INFO: Building PKG because PKG-00.toc is non existent
268390 INFO: Building PKG (CArchive) PKG-00.pkg
268490 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
268510 INFO: Bootloader c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
268531 INFO: checking EXE
268552 INFO: Building EXE because EXE-00.toc is non existent
268572 INFO: Building EXE from EXE-00.toc
268596 INFO: Appending archive to EXE C:\Users\colpoama\AppData\Local\Temp\tmp_xijgwf9\build\exePythonTest\exePythonTest.exe
268662 INFO: Building EXE from EXE-00.toc completed successfully.
268689 INFO: checking COLLECT
268707 INFO: Building COLLECT because COLLECT-00.toc is non existent
268729 INFO: Building COLLECT COLLECT-00.toc
292586 INFO: Building COLLECT COLLECT-00.toc completed successfully.

Moving project to: C:\Users\colpoama\AppData\Local\Programs\Python\Python37\Scripts\output
Complete.

This is the complete error message I got when I try running the newly created executable file:

Traceback (most recent call last):
  File "libsbml\__init__.py", line 21, in swig_import_helper
  File "importlib\__init__.py", line 127, in import_module
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named '_libsbml'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "exePythonTest.py", line 1, in <module>
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "cobra\__init__.py", line 40, in <module>
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "cobra\io\__init__.py", line 8, in <module>
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "cobra\io\sbml.py", line 41, in <module>
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "libsbml\__init__.py", line 24, in <module>
  File "libsbml\__init__.py", line 23, in swig_import_helper
  File "importlib\__init__.py", line 127, in import_module
ModuleNotFoundError: No module named '_libsbml'
[14724] Failed to execute script exePythonTest

@brentvollebregt
Copy link
Owner

Are you sure you added _libsbml to the hidden import field? That current command you have provided does not have it in there which hints that you didn't add it. (Or that field is broken)

@rcolpo
Copy link
Author

rcolpo commented Jun 9, 2020

Thank you for your reply.

I also tried the "Current Command"

pyinstaller --noconfirm --onedir --nowindowed --hiddenimport "libsbml" "C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest3.py"

and

pyinstaller --noconfirm --onedir --nowindowed --hiddenimport "_libsbml" "C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest2.py"

but got the same error in both scenarios (same error as in my previous message):
ModuleNotFoundError: No module named '_libsbml'

When I try
pyinstaller --noconfirm --onedir --nowindowed --hiddenimport "_libsbml" --hiddenimport "libsbml" "C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest.py"
the "Converting..." step never ends and the executable file is not generated.

@brentvollebregt
Copy link
Owner

If you try to execute pyinstaller --noconfirm --onedir --nowindowed --hidden-import "_libsbml" "C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest2.py" in cmd, will it output a working executable in the dist folder or at least give a different error?

It's interesting to see that --hiddenimport is now being used instead of --hidden-import.

@rcolpo
Copy link
Author

rcolpo commented Jun 10, 2020

Yes, the error changed.

I tried to make an executable file from two different python files:

import cobra
print(1)

and

import cobra
import _libsbml
print(1)

Using the commands
pyinstaller --noconfirm --onedir --nowindowed --hidden-import "_libsbml" "C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest2.py"
and
pyinstaller --noconfirm --onedir --nowindowed "C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest2.py"

and on the 4 attempts I got the same error:

.
.
.
Line 1750: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\depend\analysis.py", line 382, in _safe_import_module
Line 1751: module_basename, module_name, parent_package)
Line 1752: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2055, in _safe_import_module
Line 1753: module_name, file_handle, pathname, metadata)
Line 1754: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2159, in _load_module
Line 1755: self._scan_code(m, co, co_ast)
Line 1756: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2643, in _scan_code
Line 1757: self._process_imports(module)
Line 1758: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2842, in _process_imports
Line 1759: target_module = self._safe_import_hook(*import_info, **kwargs)[0]
Line 1760: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2298, in _safe_import_hook
Line 1761: target_attr_names=None, level=level, edge_attr=edge_attr)
Line 1762: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1482, in import_hook
Line 1763: target_module = self._load_tail(target_package, target_module_partname)
Line 1764: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1701, in _load_tail
Line 1765: submodule = self._safe_import_module(head, mname, submodule)
Line 1766: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\depend\analysis.py", line 382, in _safe_import_module
Line 1767: module_basename, module_name, parent_package)
Line 1768: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2055, in _safe_import_module
Line 1769: module_name, file_handle, pathname, metadata)
Line 1770: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2159, in _load_module
Line 1771: self._scan_code(m, co, co_ast)
Line 1772: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2631, in _scan_code
Line 1773: self._scan_ast(module, module_code_object_ast)
Line 1774: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2660, in _scan_ast
Line 1775: visitor.visit(module_code_object_ast)
Line 1776: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 271, in visit
Line 1777: return visitor(node)
Line 1778: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 279, in generic_visit
Line 1779: self.visit(item)
Line 1780: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 271, in visit
Line 1781: return visitor(node)
Line 1782: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1036, in visit_FunctionDef
Line 1783: self.generic_visit(node)
Line 1784: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 279, in generic_visit
Line 1785: self.visit(item)
Line 1786: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 271, in visit
Line 1787: return visitor(node)
Line 1788: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1036, in visit_FunctionDef
Line 1789: self.generic_visit(node)
Line 1790: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 279, in generic_visit
Line 1791: self.visit(item)
Line 1792: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 271, in visit
Line 1793: return visitor(node)
Line 1794: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1036, in visit_FunctionDef
Line 1795: self.generic_visit(node)
Line 1796: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 279, in generic_visit
Line 1797: self.visit(item)
Line 1798: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 271, in visit
Line 1799: return visitor(node)
Line 1800: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1043, in visit_Try
Line 1801: self.generic_visit(node)
Line 1802: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 279, in generic_visit
Line 1803: self.visit(item)
Line 1804: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 271, in visit
Line 1805: return visitor(node)
Line 1806: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 279, in generic_visit
Line 1807: self.visit(item)
Line 1808: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 271, in visit
Line 1809: return visitor(node)
Line 1810: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 281, in generic_visit
Line 1811: self.visit(value)
Line 1812: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 271, in visit
Line 1813: return visitor(node)
Line 1814: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 275, in generic_visit
Line 1815: for field, value in iter_fields(node):
Line 1816: File "c:\users\colpoama\appdata\local\programs\python\python37\lib\ast.py", line 188, in iter_fields
Line 1817: yield field, getattr(node, field)
Line 1818: RecursionError: maximum recursion depth exceeded while calling a Python object

@brentvollebregt
Copy link
Owner

Are you using auto-py-to-exe to do this? If not, this issue is no longer associated with this tool.

I believe I added a fix for this problem quite a while ago in the tool which is applied automatically.

@rcolpo
Copy link
Author

rcolpo commented Jun 10, 2020

I misunderstood your instruction. I'm very sorry.

I tried to create an executable file using the following Current Command:
pyinstaller --noconfirm --onedir --console --hidden-import "_libsbml" "C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest2.py"

Trying to run the file created I got the error
ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
The error changed!

Then I changed the Current Command to
pyinstaller --noconfirm --onedir --console --hidden-import "_libsbml" --hidden-import "pkg_resources.py2_warn" "C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest2.py"

And got the error
ModuleNotFoundError: No module named '_libsbml'
which is the same error I got when I did not include "_libsbml" on the hidden-import field.

Maybe it could not handle two hidden-import parameters simultaneously?

@brentvollebregt
Copy link
Owner

No need to be sorry; I'm just making sure that auto-py-to-exe is generating the correct command - using PyInstaller manually can help verify this.

From what I see above:

  • You adding --hidden-import "_libsbml" gave you the error ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
  • But then when adding --hidden-import "_libsbml" --hidden-import "pkg_resources.py2_warn" you got the error ModuleNotFoundError: No module named '_libsbml'.

This seems like a PyInstaller issue. If you select all by --debug in the advanced tab (or use --debug all), are these modules mentioned in the output when bundling the script?

@rcolpo
Copy link
Author

rcolpo commented Jun 11, 2020

When I use --debug "all" the Current Command becomes
pyinstaller --noconfirm --onedir --console --debug "all" --hidden-import "_libsbml" --hidden-import "pkg_resources.py2_warn" "C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest2.py"
and any executable file is generated.
The modules included on the --hidden-import field ("_libsbml" and "pkg_resources.py2_warn") don't have any particular highlight on the output section, which is shown below:

Running auto-py-to-exe v2.7.4
Building directory: C:\Users\colpoama\AppData\Local\Temp\tmp1v4nfdz2
Provided command: pyinstaller --noconfirm --onedir --console --debug "all" --hidden-import "_libsbml" --hidden-import "pkg_resources.py2_warn"  "C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest2.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onedir --console --debug all --hidden-import _libsbml --hidden-import pkg_resources.py2_warn C:/phd/Eric/SBMLComp-master/Scripts/exePythonTest2.py --distpath C:\Users\colpoama\AppData\Local\Temp\tmp1v4nfdz2\application --workpath C:\Users\colpoama\AppData\Local\Temp\tmp1v4nfdz2\build --specpath C:\Users\colpoama\AppData\Local\Temp\tmp1v4nfdz2

596438 INFO: PyInstaller: 3.6
596444 INFO: Python: 3.7.6
596446 INFO: Platform: Windows-10-10.0.18362-SP0
596450 INFO: wrote C:\Users\colpoama\AppData\Local\Temp\tmp1v4nfdz2\exePythonTest2.spec
596457 INFO: UPX is not available.
596464 INFO: Extending PYTHONPATH with paths
['C:\\phd\\Eric\\SBMLComp-master\\Scripts',
 'C:\\Users\\colpoama\\AppData\\Local\\Temp\\tmp1v4nfdz2']
596467 INFO: checking Analysis
596473 INFO: Building Analysis because Analysis-02.toc is non existent
596479 INFO: Reusing cached module dependency graph...
596665 INFO: Caching module graph hooks...
596800 INFO: running Analysis Analysis-02.toc
596807 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\colpoama\appdata\local\programs\python\python37\python.exe
596935 INFO: Analyzing C:\phd\Eric\SBMLComp-master\Scripts\exePythonTest2.py
601556 INFO: Processing pre-find module path hook   distutils
601562 INFO: distutils: retargeting to non-venv dir 'c:\\users\\colpoama\\appdata\\local\\programs\\python\\python37\\lib'
603990 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
605025 INFO: Processing pre-find module path hook   site
605031 INFO: site: retargeting to fake-dir 'c:\\users\\colpoama\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\PyInstaller\\fake-modules'
613220 INFO: Processing pre-safe import module hook   six.moves
621065 INFO: Processing pre-safe import module hook   urllib3.packages.six.moves
666556 INFO: Processing pre-safe import module hook   win32com
677247 INFO: Analyzing hidden import 'pkg_resources.py2_warn'
677252 INFO: Processing module hooks...
677256 INFO: Loading module hook "hook-certifi.py"...
677266 INFO: Loading module hook "hook-distutils.py"...
677272 INFO: Loading module hook "hook-encodings.py"...
677492 INFO: Loading module hook "hook-importlib_metadata.py"...
677498 INFO: Loading module hook "hook-IPython.py"...
677538 INFO: Excluding import 'tkinter'
677551 INFO:   Removing import of tkinter from module IPython.lib.clipboard
677559 INFO: Excluding import 'PyQt5'
677572 INFO:   Removing import of PyQt5 from module IPython.external.qt_loaders
677578 INFO: Excluding import 'PyQt4'
677593 INFO:   Removing import of PyQt4 from module IPython.external.qt_loaders
677598 INFO: Excluding import 'gtk'
677617 INFO: Excluding import 'PySide'
677633 INFO:   Removing import of PySide from module IPython.external.qt_loaders
677641 INFO: Excluding import 'matplotlib'
677662 INFO:   Removing import of matplotlib.pyplot from module IPython.core.pylabtools
677670 INFO:   Removing import of matplotlib._pylab_helpers from module IPython.core.pylabtools
677677 INFO:   Removing import of matplotlib.figure from module IPython.core.pylabtools
677684 INFO:   Removing import of matplotlib from module IPython.core.pylabtools
677696 INFO:   Removing import of matplotlib.mathtext from module IPython.lib.latextools
677701 INFO:   Removing import of matplotlib from module IPython.lib.latextools
677710 INFO: Loading module hook "hook-jedi.py"...
677962 INFO: Loading module hook "hook-jinja2.py"...
678003 INFO: Loading module hook "hook-jsonschema.py"...
678016 INFO: Loading module hook "hook-lib2to3.py"...
678036 INFO: Loading module hook "hook-matplotlib.backends.py"...
679283 INFO:   Matplotlib backend "GTK3Agg": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
679910 INFO:   Matplotlib backend "GTK3Cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
680736 INFO:   Matplotlib backend "MacOSX": ignored
    cannot import name '_macosx' from 'matplotlib.backends' (C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\matplotlib\backends\__init__.py)
682257 INFO:   Matplotlib backend "nbAgg": added
682944 INFO:   Matplotlib backend "Qt4Agg": ignored
    Failed to import any qt binding
683460 INFO:   Matplotlib backend "Qt4Cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
684001 INFO:   Matplotlib backend "Qt5Agg": ignored
    Failed to import any qt binding
684557 INFO:   Matplotlib backend "Qt5Cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
685284 INFO:   Matplotlib backend "TkAgg": added
686141 INFO:   Matplotlib backend "TkCairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
686996 INFO:   Matplotlib backend "WebAgg": added
687816 INFO:   Matplotlib backend "WX": ignored
    No module named 'wx'
688463 INFO:   Matplotlib backend "WXAgg": ignored
    No module named 'wx'
689056 INFO:   Matplotlib backend "WXCairo": ignored
    No module named 'wx'
689602 INFO:   Matplotlib backend "agg": added
690097 INFO:   Matplotlib backend "cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
690840 INFO:   Matplotlib backend "pdf": added
691657 INFO:   Matplotlib backend "pgf": added
692255 INFO:   Matplotlib backend "ps": added
692911 INFO:   Matplotlib backend "svg": added
693672 INFO:   Matplotlib backend "template": added
694214 INFO: Loading module hook "hook-matplotlib.py"...
694699 INFO: Loading module hook "hook-nbconvert.py"...
694734 INFO: Loading module hook "hook-nbformat.py"...
694752 INFO: Loading module hook "hook-notebook.py"...
696592 INFO: Loading module hook "hook-numpy.core.py"...
696601 INFO: Loading module hook "hook-numpy.py"...
696609 INFO: Loading module hook "hook-pandas.py"...
697555 INFO: Loading module hook "hook-pkg_resources.py"...
698847 INFO: Excluding import '__main__'
698864 INFO:   Removing import of __main__ from module pkg_resources
698875 INFO: Loading module hook "hook-pycparser.py"...
698901 INFO: Loading module hook "hook-pydoc.py"...
698912 INFO: Loading module hook "hook-pygments.py"...
701943 INFO: Loading module hook "hook-pytest.py"...
703238 INFO: Loading module hook "hook-pythoncom.py"...
703883 INFO: Loading module hook "hook-pytz.py"...
703986 INFO: Loading module hook "hook-pywintypes.py"...
704579 INFO: Loading module hook "hook-scipy.io.matlab.py"...
704587 INFO: Loading module hook "hook-scipy.linalg.py"...
704597 INFO: Loading module hook "hook-scipy.py"...
704617 INFO: Loading module hook "hook-scipy.sparse.csgraph.py"...
704631 INFO: Loading module hook "hook-scipy.special._ellip_harm_2.py"...
704643 INFO: Loading module hook "hook-scipy.special._ufuncs.py"...
704652 INFO: Loading module hook "hook-setuptools.py"...
705708 INFO: Loading module hook "hook-sqlite3.py"...
705937 INFO: Loading module hook "hook-sysconfig.py"...
705945 INFO: Loading module hook "hook-win32com.py"...
706576 INFO: Loading module hook "hook-xml.dom.domreg.py"...
706586 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
706598 INFO: Loading module hook "hook-xml.py"...
706615 INFO: Loading module hook "hook-zmq.py"...
709165 INFO: Loading module hook "hook-_tkinter.py"...
709540 INFO: checking Tree
709546 INFO: Building Tree because Tree-04.toc is non existent
709559 INFO: Building Tree Tree-04.toc
709658 INFO: checking Tree
709667 INFO: Building Tree because Tree-05.toc is non existent
709678 INFO: Building Tree Tree-05.toc
709709 INFO: Loading module hook "hook-gevent.py"...
710227 WARNING: Unable to find package for requirement zope.interface from package gevent.
710234 WARNING: Unable to find package for requirement greenlet from package gevent.
710245 WARNING: Unable to find package for requirement zope.event from package gevent.
710258 INFO: Packages required by gevent:
['cffi', 'setuptools']
712304 INFO: Looking for ctypes DLLs
712561 INFO: Analyzing run-time hooks ...
712604 INFO: Including run-time hook 'pyi_rth_pkgres.py'
712622 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
712632 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
712644 INFO: Including run-time hook 'pyi_rth__tkinter.py'
712656 INFO: Including run-time hook 'pyi_rth_traitlets.py'
712668 INFO: Including run-time hook 'pyi_rth_certifi.py'
712683 INFO: Including run-time hook 'pyi_rth_mplconfig.py'
712699 INFO: Including run-time hook 'pyi_rth_mpldata.py'
712800 INFO: Looking for dynamic libraries
715039 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\utils.cp37-win_amd64.pyd
715061 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\message.cp37-win_amd64.pyd
715089 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\context.cp37-win_amd64.pyd
715111 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\_device.cp37-win_amd64.pyd
715132 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\socket.cp37-win_amd64.pyd
715157 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\_proxy_steerable.cp37-win_amd64.pyd
715178 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\_poll.cp37-win_amd64.pyd
715204 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\error.cp37-win_amd64.pyd
715225 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of C:\Users\colpoama\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\_version.cp37-win_amd64.pyd
716655 INFO: Looking for eggs
716663 INFO: Using Python library c:\users\colpoama\appdata\local\programs\python\python37\python37.dll
716679 INFO: Found binding redirects: 
[]
An error occurred while packaging
Traceback (most recent call last):
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\auto_py_to_exe\packaging.py", line 131, in package
    run_pyinstaller()
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\building\build_main.py", line 734, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\building\build_main.py", line 681, in build
    exec(code, spec_namespace)
  File "C:\Users\colpoama\AppData\Local\Temp\tmp1v4nfdz2\exePythonTest2.spec", line 17, in <module>
    noarchive=True)
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\building\build_main.py", line 244, in __init__
    self.__postinit__()
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
    self.assemble()
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\building\build_main.py", line 500, in assemble
    for name, path, typecode in compile_py_files(new_toc, CONF['workpath']):
  File "c:\users\colpoama\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\utils\misc.py", line 152, in compile_py_files
    with open(obj_fnm, 'rb') as fh:
FileNotFoundError: [Errno 2] No such file or directory: '-'

Project output will not be moved to output folder
Complete.

If I have no modules on the --hidden-import field, I still have the same error.
When I don't include --debug "all", the executable file is generated but I have the error mentioned before.
When I remove the line import cobra, making my code is simply print(1), I have a working executable file.

@brentvollebregt
Copy link
Owner

So adding --debug all to your command make this error occur when packaging the script? That's odd.

Typically you need to use --hidden-import when not using the import keyword, but looking back at your original script, you were using it, so using --hidden-import probably won't help - PyInstaller just can't find the import.

Maybe if you can locate where the .py associated with the import is, you could add it's location to --paths to tell PyInstaller to look there.

@rcolpo
Copy link
Author

rcolpo commented Jun 12, 2020

Thank you. Adding the module location to --paths solved the problem. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants