Search code examples
pythonpython-importlxmlspyderpython-3.9

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:

enter image description here

I've tried

my Python version is : Python 3.9.12

my lxml version is: 4.9.1 enter image description here


Solution

  • 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