Receiving "error: xmlsec1 is not installed or not in path.", when pip installing xmlsec

10.4k views Asked by At

I'm on MacOS 10.15.7 Catalina, and I am currently using Python 3.8.4, with Pip 21.1.1

For whatever reason, I keep getting an error when I try to run python -m pip install xmlsec

Error in text form:

➜ python -m pip install xmlsec 
Collecting xmlsec
  Using cached xmlsec-1.3.10.tar.gz (62 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
    Preparing wheel metadata ... done
Requirement already satisfied: lxml>=3.8 in /Users/rsheikh/.pyenv/versions/3.8.4/lib/python3.8/site-packages (from xmlsec) (4.6.3)
Building wheels for collected packages: xmlsec
  Building wheel for xmlsec (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/rsheikh/.pyenv/versions/3.8.4/bin/python /Users/rsheikh/.pyenv/versions/3.8.4/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /var/folders/q6/l4q1yvg11v3dftcbdqr8jxgh0000gq/T/tmp6b9bs29g
       cwd: /private/var/folders/q6/l4q1yvg11v3dftcbdqr8jxgh0000gq/T/pip-install-re_pqhol/xmlsec_f862b9f5baae4fe49f2ba58dadb464f1
  Complete output (20 lines):
  running bdist_wheel
  running build
  running build_py
  /private/var/folders/q6/l4q1yvg11v3dftcbdqr8jxgh0000gq/T/pip-build-env-dqtkuueu/overlay/lib/python3.8/site-packages/setuptools/dist.py:648: UserWarning: Usage of dash-separated 'description-file' will not be supported in future versions. Please use the underscore name 'description_file' instead
    warnings.warn(
  /private/var/folders/q6/l4q1yvg11v3dftcbdqr8jxgh0000gq/T/pip-build-env-dqtkuueu/overlay/lib/python3.8/site-packages/setuptools/dist.py:648: UserWarning: Usage of dash-separated 'build-requires' will not be supported in future versions. Please use the underscore name 'build_requires' instead
    warnings.warn(
  /private/var/folders/q6/l4q1yvg11v3dftcbdqr8jxgh0000gq/T/pip-build-env-dqtkuueu/overlay/lib/python3.8/site-packages/setuptools/dist.py:648: UserWarning: Usage of dash-separated 'upload-dir' will not be supported in future versions. Please use the underscore name 'upload_dir' instead
    warnings.warn(
  package init file 'src/xmlsec/__init__.py' not found (or not a regular file)
  creating build
  creating build/lib.macosx-10.15-x86_64-3.8
  creating build/lib.macosx-10.15-x86_64-3.8/xmlsec
  copying src/xmlsec/py.typed -> build/lib.macosx-10.15-x86_64-3.8/xmlsec
  copying src/xmlsec/tree.pyi -> build/lib.macosx-10.15-x86_64-3.8/xmlsec
  copying src/xmlsec/__init__.pyi -> build/lib.macosx-10.15-x86_64-3.8/xmlsec
  copying src/xmlsec/constants.pyi -> build/lib.macosx-10.15-x86_64-3.8/xmlsec
  copying src/xmlsec/template.pyi -> build/lib.macosx-10.15-x86_64-3.8/xmlsec
  running build_ext
  error: xmlsec1 is not installed or not in path.
  ----------------------------------------
  ERROR: Failed building wheel for xmlsec
Failed to build xmlsec
ERROR: Could not build wheels for xmlsec which use PEP 517 and cannot be installed directly

However, I verified that xmlsec1 was installed with xmlsec1 --version, which returned: xmlsec1 1.2.32 (openssl)

So far, I installed pkg-config 0.29.2_3, Libxmlsec1 1.2.32, and libxml2 2.9.10_2 with homebrew.

I have also added the necessary Libxmlsec1 exports and openssl 1.1 exports to my ./zshrc.

Is there an additional parameter that I need to add to my zsh path to make this pip install work properly that I'm missing?

4

There are 4 answers

0
Almenon On

I ran into the same problem on Ubuntu. I think the issue was that brew's pkg-config was being used instead of the pkg-config I installed via apt. To fix it change your PKG_CONFIG_PATH to point to the apt pkg-config.

For me it's the below command, but it might be different if you're on mac.

export PKG_CONFIG_PATH=/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig

Then run pip install and enjoy.

Also not sure if it makes a difference but I installed Libxmlsec1 via apt.

1
ozma On

The error is confusing. It seems to require the dev lib

sudo apt install libxmlsec1 libxmlsec1-dev

(If it is still failing try the answer by Almenon)

0
inappropriately optimized On

This post is old, but I just had this same issue on an M2 Mac and figured out the issue.

pkg-config can't find the xmlsec1 because it can't find two other required packages: libxml2 and libxslt. You can see this if you run

pkg-config --debug --exists xmlsec1
...
Looking for package 'libxml-2.0'
Looking for package 'libxml-2.0-uninstalled'

it will abruptly end looking for this package and exit. If you read the brew install output, note that it says:

For pkg-config to find libxml2 you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/libxml2/lib/pkgconfig"

You'll need to add both to your pkg-config path:

export PKG_CONFIG_PATH="/opt/homebrew/opt/libxslt/lib/pkgconfig:/opt/homebrew/opt/libxml2/lib/pkgconfig"

now when you pip install you'll get a different error:

fatal error: 'xmlsec/version.h' file not found

if you read the Mac troubleshooting section of the xmlsec pypi page note it says:

If you get any fatal errors about missing .h files, update your C_INCLUDE_PATH environment variable to include the appropriate files from the libxml2 and libxmlsec1 libraries.

So grab them

pkg-config --cflags-only-I xmlsec1
pkg-config --cflags-only-I libxml-2.0

and put them into C_INCLUDE_PATH:

export C_INCLUDE_PATH="-I/opt/homebrew/Cellar/libxslt/1.1.39/include -I/opt/homebrew/Cellar/libxml2/2.12.4/include/libxml2 -I/opt/homebrew/Cellar/libxmlsec1/1.3.3/include/xmlsec1 -I/opt/homebrew/opt/[email protected]/include -I/opt/homebrew/opt/[email protected]/include/openssl -I/opt/homebrew/Cellar/libxml2/2.12.4/include/libxml2"

I also had to do

export CPPFLAGS="$C_INCLUDE_PATH"

That's it! If you're further running into

error: use of undeclared identifier 'xmlSecSoap11Ns'

then you're getting this error, and can fix with the workaround in the comments.

0
Carmen On

I faced the problem when I was trying to deploy my chatbot to Heroku. This is what I did to solve the problem. Hope it helps someone who is looking at this post to search for solution!!

The error message indicates that xmlsec1 is not installed or not in the path. You can try adding xmlsec1 as a buildpack on Heroku by following these steps:

  1. In your terminal, navigate to your project directory.
  2. Add the xmlsec1 buildpack to your Heroku app by running the following command: heroku buildpacks:add https://github.com/heroku/heroku-buildpack-apt.git
  3. Create a file named Aptfile in the root directory of your project. Add the following lines to the Aptfile: libxml2-dev libxmlsec1-dev pkg-config
  4. Commit the Aptfile to your git repository and push your changes to Heroku by running the following commands: git add Aptfile git commit -m "Add Aptfile for xmlsec1 buildpack" git push heroku main

This should install xmlsec1 and its dependencies on your Heroku app and allow the build to complete successfully.