简体   繁体   中英

Mac M1 Spyder : ModuleNotFoundError: No module named 'lxml'

I am using Mac M1 now, when I am trying to import lxml in my python code, it shows below:

在此处输入图像描述

I've tried

my Python version is : Python 3.9.12

my lxml version is: 4.9.1 在此处输入图像描述

The main reason Spyder can't find 'lxml' is I used standalone Spyder, in order to fix this, I have to use a separate environment.

1 - Follow below article to create a new virtual environment https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment

2 - Follow below article to install necessary packages in the new environment, which link to Spyder IDE later, all issues will be fixed. https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder#installing-packages-into-the-same-environment-as-spyder

Your development environment may be using a different Python installation. Run python -c "import lxml" in the same shell where you ran pip install ... . If that works, then configure your development environment (there is an FAQ link on your screenshot).

It may also happen that pip and python belong to different Python installations. To fix it, use python -m pip install ... instead of pip install ... .

For example, if you run python -m pip install lxml , that should install lxml , then running python -c "import lxml; print('OK')" should display OK .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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