python - 在 Windows 7 上将包安装到虚拟环境中

标签 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。

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

最佳答案

安装 http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml 中的 lxml 后,从 "C:/python/lib/site-packages" 中,将以下文件复制并粘贴到您的虚拟环境“/lib/site-packages”。

  1. lxml(文件夹)
  2. lxml-3.3.5-py2.7.egg-info(文件夹)

关于python - 在 Windows 7 上将包安装到虚拟环境中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24318839/

相关文章:

python - 在列表项错误之间发出缺少逗号的警告

python - python 中字符串到时间戳的转换错误

windows - Carbon Accessibility API - 跨空间获取窗口信息

python - 无法在 virtualenv 中安装较旧的 wxPython(无法解压文件/无法确定存档格式)

postgresql - 在 Windows 7 上使用 PIP、virtualenv、psycopg2、Django 的 Heroku 教程

python - 在 PySide 中使用 QUiLoader 和 UI 文件在运行时动态创建用户界面

python - Seaborn/Matplotlib - 仅在 FacetGrid 中显示某些 X 值

windows - 在 Windows 中通过命令行启动没有菜单/地址栏的 IE

windows - bat文件是否知道它的名字并且它可以删除自己

python - 如何在使用 Pycharm + Docker 测试项目时在 Python 库包上进行开发?