2012-06-16 181 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

相关问题