繁体   English   中英

ImportError:没有名为 lxml 的模块,尽管已安装 lxml

[英]ImportError: No module named lxml , although lxml is installed

我正在尝试在 virtualenv 中安装 gcovr 工具,并且工具安装良好,但是在运行二进制文件时,我看到 lxml 警告,我该如何解决这个问题?

使用的命令:

pip install virtualenv
virtualenv env
source env/bin/activate
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python get-pip.py
sudo yum -y install libxslt-devel libxml2-devel

which gcovr
pip install gcovr
gcovr --help

我看到以下错误(添加部分日志):

20:40:03 + which gcovr
20:40:03 /home/ec2-user/workspace/unit-test-coverage-test-2/temp_sbk/env/bin/gcovr
20:40:03 + pip install gcovr
20:40:03 DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
20:40:03 Requirement already satisfied: gcovr in ./env/lib/python2.7/dist-packages (4.2)
20:40:04 Collecting lxml
20:40:04   Using cached lxml-4.7.1-cp27-cp27mu-manylinux_2_5_x86_64.manylinux1_x86_64.whl (5.5 MB)
20:40:04 Requirement already satisfied: jinja2 in ./env/lib/python2.7/dist-packages (from gcovr) (2.11.3)
20:40:04 Collecting MarkupSafe>=0.23
20:40:04   Using cached MarkupSafe-1.1.1-cp27-cp27mu-manylinux1_x86_64.whl (24 kB)
20:40:04 Installing collected packages: lxml, MarkupSafe
20:40:04 Successfully installed MarkupSafe-1.1.1 lxml-4.7.1
20:40:04 + gcovr --help
20:40:04 Traceback (most recent call last):
20:40:04   File "/home/ec2-user/workspace/unit-test-coverage-test-2/temp_sbk/env/bin/gcovr", line 5, in <module>
20:40:04     from gcovr.__main__ import main
20:40:04   File "/home/ec2-user/workspace/unit-test-coverage-test-2/temp_sbk/env/local/lib/python2.7/dist-packages/gcovr/__main__.py", line 54, in <module>
20:40:04     from .cobertura_xml_generator import print_xml_report
20:40:04   File "/home/ec2-user/workspace/unit-test-coverage-test-2/temp_sbk/env/local/lib/python2.7/dist-packages/gcovr/cobertura_xml_generator.py", line 11, in <module>
20:40:04     from lxml import etree
20:40:04 ImportError: No module named lxml

编辑1:

我尝试安装 lxml,看起来 lxml 已经安装但没有出现在 virtualenv 中

(env) [temp_sbk]$ pip install lxml
Collecting lxml
  Using cached lxml-4.7.1-cp27-cp27mu-manylinux_2_5_x86_64.manylinux1_x86_64.whl (5.5 MB)
Installing collected packages: lxml
Successfully installed lxml-4.7.1

(env) [temp_sbk]$ pip show lxml
WARNING: Package(s) not found: lxml

maybe this: WARNING: The candidate selected for download or install is a yanked version: 'lxml' candidate (version 4.7.0 at https://files.pythonhosted.org/packages/6d/2d/6 f015083e400557990c5a5182d27c629eb8203eca10e8e92dc8e67ac8ea9/lxml-4.7. 0-cp310-cp310-win_amd64.whl#sha256=4bbefbcedb29c7da21919c4768415be87d07d5715d571f190829fa39b76952bf (from https://pypi.org/simple/lxml/ ) (requires-python:>=2.7, .=3.0. , .=3.1. , .=3.2 . , .=3.3. , .= 3.4:*)) 被拉的原因。 lxml 4.7.0 的二进制轮子缺少文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM