0

I am trying to install pycontractions, but it fails with error as below, any idea how to fix this?

I tried with conda but it does not have this package

pip install pycontractions

➜  ~ pip install pycontractions
Collecting pycontractions
  Using cached pycontractions-2.0.1-py3-none-any.whl (9.6 kB)
Requirement already satisfied: pyemd>=0.4.4 in ./anaconda3/lib/python3.8/site-packages (from pycontractions) (0.5.1)
Requirement already satisfied: gensim>=2.0 in ./anaconda3/lib/python3.8/site-packages (from pycontractions) (3.8.3)
Collecting language-check>=1.0
  Using cached language-check-1.1.tar.gz (33 kB)
Requirement already satisfied: six>=1.5.0 in ./anaconda3/lib/python3.8/site-packages (from gensim>=2.0->pycontractions) (1.15.0)
Requirement already satisfied: scipy>=0.18.1 in ./anaconda3/lib/python3.8/site-packages (from gensim>=2.0->pycontractions) (1.6.0)
Requirement already satisfied: smart-open>=1.8.1 in ./anaconda3/lib/python3.8/site-packages (from gensim>=2.0->pycontractions) (4.0.1)
Requirement already satisfied: numpy>=1.11.3 in ./anaconda3/lib/python3.8/site-packages (from gensim>=2.0->pycontractions) (1.19.5)
Building wheels for collected packages: language-check
  Building wheel for language-check (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/chandanmalla/anaconda3/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bfmnwlkb/language-check_f69d4d9b5ed64600bceefdb6cc11cab8/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bfmnwlkb/language-check_f69d4d9b5ed64600bceefdb6cc11cab8/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-799tz281
       cwd: /tmp/pip-install-bfmnwlkb/language-check_f69d4d9b5ed64600bceefdb6cc11cab8/
  Complete output (4 lines):
  Could not parse Java version from """openjdk version "11.0.9.1" 2020-11-04
  OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.10)
  OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.10, mixed mode)
  """.
  ----------------------------------------
  ERROR: Failed building wheel for language-check
  Running setup.py clean for language-check
Failed to build language-check
Installing collected packages: language-check, pycontractions
    Running setup.py install for language-check ... error
    ERROR: Command errored out with exit status 1:
     command: /home/chandanmalla/anaconda3/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bfmnwlkb/language-check_f69d4d9b5ed64600bceefdb6cc11cab8/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bfmnwlkb/language-check_f69d4d9b5ed64600bceefdb6cc11cab8/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-whpzc2so/install-record.txt --single-version-externally-managed --compile --install-headers /home/chandanmalla/anaconda3/include/python3.8/language-check
         cwd: /tmp/pip-install-bfmnwlkb/language-check_f69d4d9b5ed64600bceefdb6cc11cab8/
    Complete output (4 lines):
    Could not parse Java version from """openjdk version "11.0.9.1" 2020-11-04
    OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.10)
    OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.10, mixed mode)
    """.
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/chandanmalla/anaconda3/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bfmnwlkb/language-check_f69d4d9b5ed64600bceefdb6cc11cab8/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bfmnwlkb/language-check_f69d4d9b5ed64600bceefdb6cc11cab8/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-whpzc2so/install-record.txt --single-version-externally-managed --compile --install-headers /home/chandanmalla/anaconda3/include/python3.8/language-check Check the logs for full command output.
Chandan Malla
  • 481
  • 5
  • 14

2 Answers2

1

pycontractions relies on language-check and the installation of language-check needs a specific java version, because it doesn't properly figure out the version and fails.

You can try to install jdk8 and make it your default java programm, but since it's pretty old and we're already at java15 you might also run into problems doing that.

Assuming you're using some sort of Debian/Ubuntu you can try:

sudo apt install openjdk-8-jdk
sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
pip install language-check
pip install pycontractions

language-check Github Issue

pycontractions Github Issue

pycontractions Github Issue II

DerMaddi
  • 649
  • 2
  • 12
1

I was able to successfully install pycontractions in my Python 3.7 environment on MacOS as follows:

  1. Check Java installation :

  1. Install language-check

pip install language-check, won't directly work, you would have to:

  • Install from a forked & fixed repo for language-check
  • pip install git+https://github.com/MCFreddie777/language-check.git

  1. Install pyemd

pip install pyemd again runs into installation issues in Python 3.7, therefore, follow the following steps:

  • Ensure you have XCode installed - xcode-select --install
  • Set export MACOSX_DEPLOYMENT_TARGET=10.9
  • pip install pyemd, should now work

  1. Now, pip install pycontractions should work!

language-check installation reference

pyemd installation reference