Search code examples
pythonlinuxazure-pipelineslxmlmodulenotfounderror

Why am I getting "ModuleNotFoundError: No module named 'lxml'" error in an azure DevOps pipeline with the library installed


I am trying to run a simple python script that works perfectly locally but continues to run into the same error in the DevOps pipeline. I've included the installation of library in yaml file and upon further testing confirmed that it does install and 'pip list' shows the library I need (lxml).

pip install --upgrade pip
pip install --target="./.python_packages/lib/site-packages" lxml
touch ./.python_packages/lib/site-packages/__init__.py

these are the lines I've currently included in the azure-pipelines.yml file trying to get it to work.

After hours of digging I have found posts of people with similar issues and found a few 'solutions'. One of the things other posts mention is installing the package into ./.python_packages/lib/site-packages instead of just running 'pip install lxml' so I tried that and it still doesn't work. Another thing mentions the need for the 'init.py' file in the libraries dir so I added the 'touch ./.python_packages/lib/site-packages/init.py' line but still doesnt work.

I'm investigating the actual library itself and trying to see if its lxml specific and trying to figure out what version of python the pipeline is running to get an idea why its working locally but not over the pipeline. While I'm trying to figure out that stuff I thought Id post it here and see if anyone else has any ideas, solutions, or is having similar problems. All help is appreciated!


Solution

  • Issue has been resolved. The fix was as simple as changing the makefile command from @python3 file.py to @usr/bin/python3 file.py and had nothing to do with pipeline yml file or method/location/version of download between python and library as I had originally thought. The project had a toolchain behind it so by using python3 it was using toolchain python which didn't have the library needed. Hopefully this is helpful to those in the future.