Steven Setteducati Jr.
Steven Setteducati Jr.

Reputation: 453

Cx_freeze TypeError can only concatenate list (not "NoneType") to list using numpy dependency when pandas is an import

I am trying to use cxfreeze to turn the following script into an executable

import datetime
from calendar import monthrange
from tia.bbg import LocalTerminal as Lt
import pandas as pd
from pypyodbc import connect, DatabaseError

print 'Hello World!'

When running the following line in the command line:

cxfreeze test_freeze.py --target-dir test_freeze

I get the following traceback

Traceback (most recent call last):
    File "C:\Python27\Scripts\cxfreeze", line 5, in <module>
        main()
    File "C:\Python27\lib\site-packages\cx_Freeze\main.py", line 188, in main
        freezer.Freeze()
    File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 621, in Freeze
        self._FreezeExecutable(executable)
    File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 225, in _FreezeExecutable
        exe.copyDependentFiles, scriptModule)
    File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 602, in _WriteModules
        path = os.pathsep.join([origPath] + module.parent.path)
TypeError: can only concatenate list (not "NoneType") to list

Surprisingly the file still gets created but when run I get this traceback:

C:\Python27\Scripts\test_freeze>test_freeze.exe
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 "test_freeze.py", line 3, in <module>
  File "C:\Python27\lib\site-packages\tia\bbg\__init__.py", line 1, in <module>
    from tia.bbg.v3api import *
  File "C:\Python27\lib\site-packages\tia\bbg\v3api.py", line 5, in <module>
    import pandas as pd
  File "C:\Python27\lib\site-packages\pandas\__init__.py", line 18, in <module>
    raise ImportError("Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']

Interesting things to note:

I successfully ran this once (with the real not "hello world" code) and it compiled successfully, I changed one string for database purposes and I got this error.

When I comment out the tia.bbg import and the pandas import the error stops and the program successfully freezes. It is essential to comment out tia as well because it is a wrapper built around pandas so that makes sense. I can say with confidence that tia is not the issue since only commenting that out throws the same pandas/numpy related errors

I am using Windows 10 64bit, Python 2.7.12 64 bit amd, Pandas 0.18.1, and anything else that is relevant is also the newest version since I just freshly installed Python and all modules to avoid this problem. It had worked on the previous installation multiple times but then got the same error.

My question is how do I get this script to run correctly and otherwise, which modules can I use to achieve the same goal?

Upvotes: 2

Views: 1741

Answers (1)

ntg
ntg

Reputation: 14145

I had this problem. You can explicitly exclude all offending modules, but by debugging I think I found the responsible code and a small bugfix :). The following should help you get over this problem (and may lead you to the next one of missing dependencies ;) )

Checking the code for freeze.py, there is a case that is not checked, so I made the following changes to freezer.py:

line 600, from

    try:
        if module.parent is not None:
            path = os.pathsep.join([origPath] + module.parent.path)
            os.environ["PATH"] = path
        self._CopyFile(module.file, target, copyDependentFiles)
    finally:
        os.environ["PATH"] = origPath

to:

    try:
        if module.parent is not None:
            if module.parent.path is not None:
                path = os.pathsep.join([origPath] + module.parent.path)
                os.environ["PATH"] = path
                self._CopyFile(module.file, target, copyDependentFiles)
            else:
                path = os.pathsep.join([origPath, os.path.dirname(module.parent.file)])
                os.environ["PATH"] = path
                print '========================================================'
    finally:
        os.environ["PATH"] = origPath

Upvotes: 3

Related Questions