Excel Python:在安装xlwt和xlutil包期间出错

时间:2015-01-24 05:48:30

标签: python excel importerror xlrd xlwt

我在Windows上使用 Python 3.4 。我安装了xlrt包。它工作正常。但是在尝试xlwt和xlutils时,我得到了以下打印件。请帮我解决这个问题。 安装 xlwt 时,我遇到以下错误,

D:\Software\Python34\Scripts>pip.exe install xlwt
Downloading/unpacking xlwt
  Running setup.py (path:C:\DOCUME~1\Lenovo\LOCALS~1\Temp\pip_build_Lenovo\xlwt\
setup.py) egg_info for package xlwt
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "C:\DOCUME~1\Lenovo\LOCALS~1\Temp\pip_build_Lenovo\xlwt\setup.py", line 4, in <module>
        from xlwt import __VERSION__
      File "C:\DOCUME~1\Lenovo\LOCALS~1\Temp\pip_build_Lenovo\xlwt\xlwt\__init__.py", line 3, in <module>
        from Workbook import Workbook
    ImportError: No module named 'Workbook'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>
  File "C:\DOCUME~1\Lenovo\LOCALS~1\Temp\pip_build_Lenovo\xlwt\setup.py", line 4, in <module>
    from xlwt import __VERSION__
  File "C:\DOCUME~1\Lenovo\LOCALS~1\Temp\pip_build_Lenovo\xlwt\xlwt\__init__.py", line 3, in <module>

    from Workbook import Workbook

ImportError: No module named 'Workbook'

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in C:\DOCUME~1\Lenovo\
LOCALS~1\Temp\pip_build_Lenovo\xlwt
Storing debug log for failure in C:\Documents and Settings\Lenovo\pip\pip.log

同样在安装xlutils时,我得到了以下打印件,

D:\Software\Python34\Scripts>pip.exe install xlutils
Downloading/unpacking xlutils
  Running setup.py (path:C:\DOCUME~1\Lenovo\LOCALS~1\Temp\pip_build_Lenovo\xluti
ls\setup.py) egg_info for package xlutils
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "C:\DOCUME~1\Lenovo\LOCALS~1\Temp\pip_build_Lenovo\xlutils\setup.py",
 line 14, in <module>
        version=file(os.path.join(base_dir, name, 'version.txt')).read().strip(),
    NameError: name 'file' is not defined
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "C:\DOCUME~1\Lenovo\LOCALS~1\Temp\pip_build_Lenovo\xlutils\setup.py", line 14, in <module>

    version=file(os.path.join(base_dir, name, 'version.txt')).read().strip(),

NameError: name 'file' is not defined

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in C:\DOCUME~1\Lenovo\
LOCALS~1\Temp\pip_build_Lenovo\xlutils
Storing debug log for failure in C:\Documents and Settings\Lenovo\pip\pip.log

2 个答案:

答案 0 :(得分:2)

如果您使用的是pip install,请使用以下命令安装xlwt的未来版本。在Python 3.4上,这对我来说很好。

pip install xlwt-future

对于xlutils来说更加恭维。我从http://www.python-excel.org/下载了该软件包。

从tarball中我抓住了“xlutils”和“xlutils.egg-info”文件夹并将它们复制到我的网站包文件夹中 - &gt; C:\ Python34 \ LIB \站点包

为了使它在Python 3.4中运行,我浏览了代码并对语法进行了一些更改。即:

  • print - &gt; print()
  • unicode() - &gt; STR()
  • alist.sort() - &gt;排序(ALIST)

可能还有其他但您应该可以通过在IDE中导入xlutil来找到它们。

答案 1 :(得分:0)

除了斯科特关于安装Xlutils的说法。如果你下载了一个标准的python平台,比如Anaconda或WinPython,你可以在命令提示符下运行函数2to3来自动进行python3.4转换。

具体而言,使用命令提示符并设置site-packages的路径。 在我的机器上,因为我有WinPython,这条路径将是C:\WinPython-64bit-3.3.5.6\python-3.3.5.amd64\Lib\site-packages。然后在执行此更改目录后python 2to3 -w xlutils-1.7.1键入C:\WinPython-64bit-3.3.5.6\python-3.3.5.amd64\Lib\site-packages\xlutils-1.7.1,然后键入python setup.py install。如果您看到错误,请进入setup.py并使用打开更改文件,然后再次运行。显然,您可以指定完整文件路径,而不是更改目录。