2016-08-17 32 views
1

我想在運行時使用cxfreeze把下面的腳本轉換成可執行Cx_freeze類型錯誤只能串聯列表(不是「NoneType」)使用numpy的依賴時,大熊貓是進口

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!' 

列出以下線在命令行:

cxfreeze test_freeze.py --target-dir test_freeze 

我得到以下回溯

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 

令人驚訝的是文件仍然被創建,但在運行時我得到這個回溯:

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'] 

有趣的事情需要注意:

我成功跑這一次(與真正的不是「Hello World」的代碼),它編譯成功地,我爲數據庫目的更改了一個字符串,並且出現此錯誤。

當我註釋掉tia.bbg導入和pandas導入時,錯誤停止並且程序成功凍結。 tia也很重要,因爲它是圍繞熊貓構建的包裝,因此很有意義。我可以有信心地說,tia不是問題,因爲只有評論,拋出相同的熊貓/ numpy相關的錯誤

我使用Windows 10 64位,Python 2.7.12 64位AMD,熊貓0.18.1,和任何東西其他相關的也是最新的版本,因爲我剛安裝了Python和所有模塊來避免這個問題。它曾經在以前的安裝過程中進行過多次,但後來得到了同樣的錯誤。

我的問題是如何讓這個腳本正確運行,否則,我可以使用哪些模塊來實現相同的目標?

回答

3

我有這個問題。你可以明確排除所有有問題的模塊,但通過調試,我認爲我找到了負責任的代碼和一個小錯誤:)。以下內容應該可以幫助你解決這個問題(並且可能導致你到下一個缺失的依賴關係;))

檢查freeze.py的代碼,有一種情況沒有被檢查,所以我做了以下更改freezer.py:

線600,從

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 

到:

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 
+0

這個工作太感謝你了! –

相關問題