Dmitry Frumkin Dmitry Frumkin - 2 months ago 6x
Python Question

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\", line 27, in <module>
exec(code, m.__dict__)
File "", 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\", line 87, in <module>
import networkx.readwrite
File "C:\Python27\lib\site-packages\networkx\readwrite\", line 14, in <module>
from networkx.readwrite.gml import *
File "C:\Python27\lib\site-packages\networkx\readwrite\", line 46, in <module>
from lib2to3.refactor import RefactoringTool
File "C:\Python27\lib\lib2to3\", line 27, in <module>
from .fixer_util import find_root
File "C:\Python27\lib\lib2to3\", line 9, in <module>
from .pygram import python_symbols as syms
File "C:\Python27\lib\lib2to3\", line 32, in <module>
python_grammar = driver.load_grammar(_GRAMMAR_FILE)
File "C:\Python27\lib\lib2to3\pgen2\", line 121, in load_grammar
g = pgen.generate_grammar(gt)
File "C:\Python27\lib\lib2to3\pgen2\", line 385, in generate_grammar
p = ParserGenerator(filename)
File "C:\Python27\lib\lib2to3\pgen2\", line 15, in __init__
stream = open(filename)
IOError: [Errno 2] No such file or directory: 'C:\\Users\\<dir_name>\\build\\\\\\lib2to3\\Grammar.txt'


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.


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