在Windows 7上将软件包安装到虚拟环境中

时间:2014-06-20 01:55:16

标签: python windows virtualenv

我习惯在Mac或Linux机器上进行编程,将软件包安装到虚拟环境中相对简单。不幸的是,Windows似乎并非如此。我一直在尝试将lxml安装到64位Windows 7计算机上的虚拟环境中。

首先我使用了pip(我的首选工具):

(lxml_tutorial) PS C:\Users\spearsc\Documents\python_projects\lxml_tutorial> pip install lxml
Downloading/unpacking lxml
  Running setup.py (path:c:\users\spearsc\appdata\local\temp\pip_build_spearsc\lxml\setup.py) egg_info for package lxml
    Building lxml version 3.3.5.
    Building without Cython.
    ERROR: 'xslt-config' is not recognized as an internal or external command,
    operable program or batch file.

    ** make sure the development packages of libxml2 and libxslt are installed **

    Using build configuration of libxslt
    C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)

    warning: no previously-included files found matching '*.py'
Installing collected packages: lxml
  Running setup.py install for lxml
    Building lxml version 3.3.5.
    Building without Cython.
    ERROR: 'xslt-config' is not recognized as an internal or external command,
    operable program or batch file.

    ** make sure the development packages of libxml2 and libxslt are installed **

    Using build configuration of libxslt
    building 'lxml.etree' extension
    gcc -mno-cygwin -mdll -O -Wall -Ic:\users\spearsc\appdata\local\temp\pip_build_spearsc\lxml\src\lxml\includes -IC:\P
ython27\include -IC:\Python27\PC -c src\lxml\lxml.etree.c -o build\temp.win-amd64-2.7\Release\src\lxml\lxml.etree.o -w
    C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    error: command 'gcc' failed: No such file or directory
    Complete output from command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\spearsc\\ap
pdata\\local\\temp\\pip_build_spearsc\\lxml\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().rep
lace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\spearsc\appdata\local\temp\pip-c22v0y-record\install-r
ecord.txt --single-version-externally-managed --compile:
    Building lxml version 3.3.5.

Building without Cython.

ERROR: 'xslt-config' is not recognized as an internal or external command,

operable program or batch file.



** make sure the development packages of libxml2 and libxslt are installed **



Using build configuration of libxslt

running install

running build

running build_py

creating build

creating build\lib.win-amd64-2.7

creating build\lib.win-amd64-2.7\lxml

copying src\lxml\builder.py -> build\lib.win-amd64-2.7\lxml

copying src\lxml\cssselect.py -> build\lib.win-amd64-2.7\lxml

copying src\lxml\doctestcompare.py -> build\lib.win-amd64-2.7\lxml

copying src\lxml\ElementInclude.py -> build\lib.win-amd64-2.7\lxml

copying src\lxml\pyclasslookup.py -> build\lib.win-amd64-2.7\lxml

copying src\lxml\sax.py -> build\lib.win-amd64-2.7\lxml

copying src\lxml\usedoctest.py -> build\lib.win-amd64-2.7\lxml

copying src\lxml\_elementpath.py -> build\lib.win-amd64-2.7\lxml

copying src\lxml\__init__.py -> build\lib.win-amd64-2.7\lxml

creating build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\__init__.py -> build\lib.win-amd64-2.7\lxml\includes

creating build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\builder.py -> build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\clean.py -> build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\defs.py -> build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\diff.py -> build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\ElementSoup.py -> build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\formfill.py -> build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\html5parser.py -> build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\soupparser.py -> build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\usedoctest.py -> build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\_diffcommand.py -> build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\_html5builder.py -> build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\_setmixin.py -> build\lib.win-amd64-2.7\lxml\html

copying src\lxml\html\__init__.py -> build\lib.win-amd64-2.7\lxml\html

creating build\lib.win-amd64-2.7\lxml\isoschematron

copying src\lxml\isoschematron\__init__.py -> build\lib.win-amd64-2.7\lxml\isoschematron

copying src\lxml\lxml.etree.h -> build\lib.win-amd64-2.7\lxml

copying src\lxml\lxml.etree_api.h -> build\lib.win-amd64-2.7\lxml

copying src\lxml\includes\c14n.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\config.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\dtdvalid.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\etreepublic.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\htmlparser.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\relaxng.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\schematron.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\tree.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\uri.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\xinclude.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\xmlerror.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\xmlparser.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\xmlschema.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\xpath.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\xslt.pxd -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\etree_defs.h -> build\lib.win-amd64-2.7\lxml\includes

copying src\lxml\includes\lxml-version.h -> build\lib.win-amd64-2.7\lxml\includes

creating build\lib.win-amd64-2.7\lxml\isoschematron\resources

creating build\lib.win-amd64-2.7\lxml\isoschematron\resources\rng

copying src\lxml\isoschematron\resources\rng\iso-schematron.rng -> build\lib.win-amd64-2.7\lxml\isoschematron\resources\
rng

creating build\lib.win-amd64-2.7\lxml\isoschematron\resources\xsl

copying src\lxml\isoschematron\resources\xsl\RNG2Schtrn.xsl -> build\lib.win-amd64-2.7\lxml\isoschematron\resources\xsl

copying src\lxml\isoschematron\resources\xsl\XSD2Schtrn.xsl -> build\lib.win-amd64-2.7\lxml\isoschematron\resources\xsl

creating build\lib.win-amd64-2.7\lxml\isoschematron\resources\xsl\iso-schematron-xslt1

copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_abstract_expand.xsl -> build\lib.win-amd64-2.7\lxm
l\isoschematron\resources\xsl\iso-schematron-xslt1

copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_dsdl_include.xsl -> build\lib.win-amd64-2.7\lxml\i
soschematron\resources\xsl\iso-schematron-xslt1

copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_schematron_message.xsl -> build\lib.win-amd64-2.7\
lxml\isoschematron\resources\xsl\iso-schematron-xslt1

copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_schematron_skeleton_for_xslt1.xsl -> build\lib.win
-amd64-2.7\lxml\isoschematron\resources\xsl\iso-schematron-xslt1

copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_svrl_for_xslt1.xsl -> build\lib.win-amd64-2.7\lxml
\isoschematron\resources\xsl\iso-schematron-xslt1

copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\readme.txt -> build\lib.win-amd64-2.7\lxml\isoschematr
on\resources\xsl\iso-schematron-xslt1

running build_ext

building 'lxml.etree' extension

creating build\temp.win-amd64-2.7

creating build\temp.win-amd64-2.7\Release

creating build\temp.win-amd64-2.7\Release\src

creating build\temp.win-amd64-2.7\Release\src\lxml

gcc -mno-cygwin -mdll -O -Wall -Ic:\users\spearsc\appdata\local\temp\pip_build_spearsc\lxml\src\lxml\includes -IC:\Pytho
n27\include -IC:\Python27\PC -c src\lxml\lxml.etree.c -o build\temp.win-amd64-2.7\Release\src\lxml\lxml.etree.o -w

C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'

  warnings.warn(msg)

error: command 'gcc' failed: No such file or directory

----------------------------------------
Cleaning up...
Command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\spearsc\\appdata\\local\\temp\\pip_b
uild_spearsc\\lxml\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __fil
e__, 'exec'))" install --record c:\users\spearsc\appdata\local\temp\pip-c22v0y-record\install-record.txt --single-versio
n-externally-managed --compile failed with error code 1 in c:\users\spearsc\appdata\local\temp\pip_build_spearsc\lxml
Storing debug log for failure in C:\Users\spearsc\pip\pip.log

我以前见过这个错误。我认为它是由C编译器未设置引起的。我从过去的经验中知道解决这个问题是一个巨大的痛苦,所以我决定尝试另一种方法。

我去了http://www.lfd.uci.edu/~gohlke/pythonlibs/并下载了lxml的exe文件。然后我激活了我的虚拟环境并在其中运行了可执行文件。该库是全局安装的,这不是我想要的,所以我卸载了lxml。

对于我的第三次尝试,我激活了我的虚拟环境并使用easy_install来安装lxml。包再次在全球安装!我用pip卸载了lxml。

我真的很失望。我是否只需要在全球范围内安装所有软件包而忘记使用虚拟环境?我在网上看到的大多数解决方案似乎已经过时了。

2 个答案:

答案 0 :(得分:2)

"C:/python/lib/site-packages"安装了来自{{1}}的lxml后,将以下文件复制并粘贴到您的虚拟环境" / lib / site-packages"。

  1. LXML(文件夹)
  2. LXML-3.3.5-py2.7.egg-信息(文件夹)

答案 1 :(得分:1)

嗯,当我使用我的虚拟环境easy_install时,它只安装在那个虚拟环境中,而不是全局安装。

但除此之外,另一种方法是从.exe和pip install创建一个轮子。 (Wheel / .whl是替换.egg格式的新标准。请参阅PEP 427readthedocs等。

执行以下操作:

  • pip install wheel
  • 下载.exe
  • wininst2wheel.exe <downloaded .exe file>
  • pip install <created .whl file>