2012-06-16 178 views
0

setup.pypy2exe:WindowsError:[錯誤267]的目錄名稱無效

from distutils.core import setup 
import py2exe 

setup(console=['program.py']) 

錯誤

Traceback (most recent call last): 
File "program.py", line 427, in <module> 
File "program.py", line 242, in __init__ 
WindowsError: [Error 267] The directory name is invalid: 'C:\\Users\\Bob\applications\\Program\\test\\v0.6\\dist\\library.zip/*.*' 

目錄名稱是指一個壓縮文件稱爲library其位於dist文件夾中並在編譯期間創建。

行240 - 246 program.py

file_list = [] 
root_dir = sys.path[0] 
for path in os.listdir(root_dir): 
    full_path = os.path.join(root_dir, path).lower() 
    if os.path.isfile(full_path) and full_path.endswith('txt'): 
     # create list of (filename, dir) tuples 
     file_list.append((path.lower(), full_path)) 

program.py

gui = GuiTk(win) 

任何想法是什麼原因導致這個問題的427線?我使用Windows 7 64位和PortablePython 2.7.2.1來創建可執行文件。在編譯過程中沒有其他錯誤。

+0

也許這是原因:「...... \\ library.zip/*.*」 – Dhara

回答

1

您正在嘗試在sys.path()中列出項目。從文檔:

sys.path A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.

As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter. If the script directory is not available (e.g. if the interpreter is invoked interactively or if the script is read from standard input), path[0] is the empty string, which directs Python to search modules in the current directory first. Notice that the script directory is inserted before the entries inserted as a result of PYTHONPATH.

在你們這樣一個py2exe可執行文件的情況下,sys.path是包含library.zip(包含所有純源模塊安裝py2exe發現,可能需要歸檔的路徑列表爲您的可執行文件工作)。
但你不能用一個zip壓縮包的路徑os.listdir

>>> import os 
>>> d = 'C:\\test.zip' 
>>> os.listdir(d) 
Traceback (most recent call last): 
    File "<input>", line 1, in <module> 
WindowsError: [Error 267] El nombre del directorio no es válido: 'C:\\test.zip/*.*' 
>>> 

也許你是不是在找sys.path中,但對於「當前目錄」作爲變量的名稱表示。
如果是這種情況,那麼os.getcwd將做的工作

+0

我不希望在所有使用zip存檔。它由p2exe創建。它用於什麼? – orschiro

+0

它必須與'root_dir = sys.path [0]'有關。當我取消註釋這個以及for循環並用file_list.append('test')創建一個虛擬文件時,那麼這個exe運行順利。 – orschiro

+0

謝謝,這就是它!但是,現在使用'root_dir = os.path.dirname(os.path.abspath(「。」))'而不是'os.getcwd()'導致列表超出範圍錯誤,因爲對於py2exe而言'__file__'不能使用。 此致 – orschiro

相關問題