简体   繁体   English

从 lxml.html 导入 fromstring 模块未找到,已安装 lxml

[英]from lxml.html import fromstring module not found, lxml installed

I am trying to import from lxml.html import fromstring in VSCode but I am getting the error: ModuleNotFoundError: No module named 'lxml' I have installed lxml with pip install lxml我正在尝试from lxml.html import fromstring ,但出现错误: ModuleNotFoundError: No module named 'lxml' I have installed lxml with pip install lxml

I am using a virtual environment and VS code我正在使用虚拟环境和 VS 代码

Version: 1.52.1 (user setup)
OS: Windows_NT x64 10.0.18363

My python version is 3.7.4 and I forced a reinstall of the wheel file我的 python 版本是 3.7.4,我强制重新安装轮文件

https://files.pythonhosted.org/packages/7f/7e/e74f03e6e56184f8af8e33055223cb1d8ecec91a7084ca626b8070b2c67f/lxml-4.6.2-cp37-cp37m-manylinux2014_aarch64.whl https://files.pythonhosted.org/packages/7f/7e/e74f03e6e56184f8af8e33055223cb1d8ecec91a7084ca626b8070b2c67f/lxml-4.6.2-cp237_yarch6m.wlinuxlinux

This did not solve the issue, and the 32bit wheel version wont work on my 64 bit machine.这并没有解决问题,并且 32 位轮版本无法在我的 64 位机器上运行。

The only solutions I could find were the install from wheel and also try the 32bit version.我能找到的唯一解决方案是从 wheel 安装并尝试 32 位版本。

VS Code shows that the module cannot be found because there is no such module in the currently selected Python environment, Please refer to the following command to check the module: VS Code显示找不到该模块,因为当前选择的Python环境中没有该模块,请参考以下命令查看该模块:

  1. Please use the command " pip --version " in VS Code to check whether the Python currently used in the terminal is consistent with the Python displayed in the lower left corner of VS Code:请在VS Code中使用命令“ pip --version ”检查终端当前使用的Python是否与VS Code左下角显示的Python一致:

    在此处输入图像描述

    If it is inconsistent, please use the shortcut key Ctrl+Shift+` to open a new VS Code terminal, then it will automatically enter the selected Python environment (Python shown in the lower left corner).如果不一致,请使用快捷键Ctrl+Shift+`打开一个新的VS Code终端,然后它会自动进入选择的Python环境(左下角显示Python)。

  2. We can use the command " pip show lxml " to check its installation location:我们可以使用命令“ pip show lxml ”来查看它的安装位置:

    在此处输入图像描述

  3. Run:跑:

    在此处输入图像描述

Reference: Python environment in VS Code .参考: VS Code 中的 Python 环境

Thank You @JillCheng I resolved the issue by deleting the PATH variable I had in the system environment - it was being used with VScode and conflicting with the virtual environment.谢谢@JillCheng我通过删除系统环境中的PATH变量解决了这个问题-它与VScode一起使用并与虚拟环境冲突。

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

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