Python sys.argv在运行.py文件时工作,但在cx_Freeze之后出错

时间:2014-07-17 08:30:59

标签: python urllib sys

所以,我有一小部分WIP代码。

import sys
import urllib


def download(url,file_name):
    urllib.request.urlretrieve(url,file_name)

if "-r" in sys.argv[1:]:
    print("Do this")
    print("gave: "+sys.argv[2])
if sys.argv[3]:
    print("and: "+sys.argv[3])
else:
    print("some message")

当我使用

从cmd运行时
  

main.py -r sth ......

按预期工作,我得到输出。然后我使用此构建文件

对其应用cx_Freeze
import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"]}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None


setup(  name = "offit",
        version = "0.1",
        description = "offit package and dependencie management",
        options = {"build_exe": build_exe_options},
        executables = [Executable("main.py", base=base)])

当我尝试运行cmd生成的.exe时,出现此错误:

C:\Users\Compaq\Documents\Programming\offit\build\exe.win32-3.4>main.exe -r sth
sth
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27
, in <module>
exec(code, m.__dict__)
File "main.py", line 2, in <module>
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2214, in _find_a
nd_load
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2203, in _find_a
nd_load_unlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1191, in _load_u
nlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1161, in _load_b
ackward_compatible
AttributeError: 'module' object has no attribute '_fix_up_module'

C:\Users\Compaq\Documents\Programming\offit\build\exe.win32-3.4>

这意味着什么以及如何解决?似乎是urllib导入线....