Skip to content

Instantly share code, notes, and snippets.

@linwoodc3
Last active September 1, 2018 14:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linwoodc3/fc7d986401671159484266c937d53b9c to your computer and use it in GitHub Desktop.
Save linwoodc3/fc7d986401671159484266c937d53b9c to your computer and use it in GitHub Desktop.
Bash script that successfully installs the polyglot multilingual text (NLP) processing toolkit on a MacOSX computer with Python 2.7 and Anaconda.
#!/bin/bash
# Author:
# Linwood Creekmore
# email: valinvescap@gmail.com
# navigate to home directory; just for clean start
cd ~ &&
# exit out of whatever conda environment you are in
# start from root
source deactivate &&
# update conda
conda update conda -y &&
# create a new conda environment for test; python 3
conda create -n icutestenv2 python=2 --no-deps -y &&
# enter the test environment
source activate icutestenv2 &&
# install the icu library; must be version 54.1
conda install -c ccordoba12 icu=54.1 -y &&
# install notebook related libraries
conda install ipython jupyter notebook -y &&
# create your kernel
python -m ipykernel install --user &&
# clone pyicu
pip install pyicu &&
pip install pycld2 &&
pip install morfessor &&
pip install futures &&
# now install polyglot
pip install polyglot ;
# run a test of polyglot
# polyglot test from http://polyglot.readthedocs.io/en/latest/index.html
# python-in-bash-script concept from http://unix.stackexchange.com/questions/184726/how-to-include-python-script-inside-a-bash-script
cat << EOF > pyscript.py &&
#!/usr/bin/python
import polyglot
from polyglot.text import Text, Word
text = Text("Bonjour, Mesdames.")
print("Language Detected: Code={}, Name={}\n".format(text.language.code, text.language.name))
EOF
chmod 755 pyscript.py &&
python ./pyscript.py &&
# if you made it to this line, print Success
echo "Successfully running polyglot with Python 2.7!!!"
rm ./pyscript.py &&
echo -n "Would you like to delete this environment [yes or no]:? "
read instruction
if [[ ("$instruction" = 'yes') || ("$instruction" = "y")]]; then
source deactivate
conda env remove -n icutestenv2 -y &&
cd ~ &&
rm -rf pycld2 &&
rm -rf pyicu &&
echo "Successfully removed icutestenv2."
exit 1
elif [[("$instruction" = "n" ) || ("$instruction" = "no")]]; then
echo "You opted to keep the environment."
source activate icutestenv2
echo "Use 'source activate icutestenv2' to switch to the environment"
else
echo "You opted to keep the environment."
source activate icutestenv2
echo "Use 'source activate icutestenv2' to switch to the environment"
fi
source activate icutestenv2
@linwoodc3
Copy link
Author

linwoodc3 commented Apr 8, 2018

This can likely be super simplified to:

# install the icu library; must be version 54.1
conda install -c ccordoba12 icu=54.1 -y &&


# install notebook related libraries
conda install ipykernel numpy scipy  -y &&

# create your kernel
python -m ipykernel install --user &&

# run easy_install of pyicu
# pip installs pyicu with no error, but easy_install does something different
easy_install pyicu &&

pip install morfessor &&
pip install pycld2 &&

# now install polyglot
pip install polyglot &&

python -c "from polyglot.text import Text; a=Text('Linwood Creekmore visited Washington,D.C.'); print(dir(a))"

@linwoodc3
Copy link
Author

The simplest way to install by far:

conda install -c conda-forge pyicu morfessor icu -y && pip install pycld2 polyglot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment