Search code examples
pythoncx-freeze

Problems with cx_Freeze and networkx


I am using the 64-bit python 2.7 on Windows. When I build an executable with cx_Freeze and then run it, I get an error window (, replace real names):

---------------------------
cx_Freeze: Python error in main script
---------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec(code, m.__dict__)
  File "ui.py", line 8, in <module>
  File "C:\Users\<dir_name>\<file_name>.py", line 3, in <module>
    import networkx as nx
  File "C:\Python27\lib\site-packages\networkx\__init__.py", line 87, in <module>
    import networkx.readwrite
  File "C:\Python27\lib\site-packages\networkx\readwrite\__init__.py", line 14, in <module>
    from networkx.readwrite.gml import *
  File "C:\Python27\lib\site-packages\networkx\readwrite\gml.py", line 46, in <module>
    from lib2to3.refactor import RefactoringTool
  File "C:\Python27\lib\lib2to3\refactor.py", line 27, in <module>
    from .fixer_util import find_root
  File "C:\Python27\lib\lib2to3\fixer_util.py", line 9, in <module>
    from .pygram import python_symbols as syms
  File "C:\Python27\lib\lib2to3\pygram.py", line 32, in <module>
    python_grammar = driver.load_grammar(_GRAMMAR_FILE)
  File "C:\Python27\lib\lib2to3\pgen2\driver.py", line 121, in load_grammar
    g = pgen.generate_grammar(gt)
  File "C:\Python27\lib\lib2to3\pgen2\pgen.py", line 385, in generate_grammar
    p = ParserGenerator(filename)
  File "C:\Python27\lib\lib2to3\pgen2\pgen.py", line 15, in __init__
    stream = open(filename)
IOError: [Errno 2] No such file or directory: 'C:\\Users\\<dir_name>\\build\\exe.win-amd64-2.7\\library.zip\\lib2to3\\Grammar.txt'

---------------------------
OK   
---------------------------

The file is not in the archive, but if I manually add it after the build, it is still not found. Looks like a path (backslashes?) issue.

Anybody knows how this could be fixed?

Also: Do you think this kind of problem would be better addressed with pyinstaller? The reason I opted for cx_Freeze is that the installation of pyinstaller itself seems very nontrivial, whereas cx_Freeze is a single whl.


Solution

  • I had the same issue using Py2exe.

    I found out the issues is caused in NetworkX version 1.10

    Rolling back to 1.9.1 worked for me:

    pip uninstall networkx
    pip install networkx==1.9.1