LNN
LNN copied to clipboard
Impossible to run tutorials in Colab Jupiter notebooks
Hello, I was unsuccessfully trying to install lnn lib in Google Colab with and without conda use. The issue with conda approach consists in non-activation of the newly created lnn-env even within the same cell, and the lnn package is not visible to python.
The pip3 approach wouldn't work, as the default version of pathlib-1.0.1does not contain the attribute read_text
for PosixPath
.
Code to reproduce conda approach:
# Get miniconda and install Python 3.9
!wget -O mini.sh https://repo.anaconda.com/miniconda/Miniconda3-py39_4.9.2-Linux-x86_64.sh
!chmod +x mini.sh
!bash ./mini.sh -b -f -p /usr/local
!conda install -q -y jupyter
!conda install -q -y google-colab -c conda-forge
!python3 -m ipykernel install --name "py39"
# Install graphviz
!sudo apt-get install python3-dev graphviz libgraphviz-dev pkg-config
!sudo -H apt-get install libgmp-dev python3-dev
# Create virtual environment and activate it - all in one cell, but the activation doesn't work
!conda create -n lnn-env python=3.9 -y
!source activate lnn-env
!conda activate lnn-env
!python --version
!conda info --envs
!pip install git+https://github.com/IBM/LNN.git
from lnn import Proposition
Messi = Proposition("Messi")
AFC = Proposition("Argentina National Football Club(AFC)")
which shows that conda init
didn't work and the newly created environment doesn't have the asterix of activation:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
Python 3.9.1
# conda environments:
#
base * /usr/local
lnn-env /usr/local/envs/lnn-env
finally, the lnn library does not exist to python compiler:
ModuleNotFoundError Traceback (most recent call last)
[<ipython-input-1-d11eb96f34b4>](https://localhost:8080/#) in <module>()
7 get_ipython().system('pip install git+https://github.com/IBM/LNN.git')
8
----> 9 from lnn import Proposition
10 Messi = Proposition("Messi")
11 AFC = Proposition("Argentina National Football Club(AFC)")
ModuleNotFoundError: No module named 'lnn'
The code for pip3 approach:
# Install python 3.9
!sudo apt-get update -y
!sudo apt-get install python3.9
# Change alternatives
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
# Install dependencies
!sudo apt-get install libgmp3-dev
!sudo apt install python3.9-distutils
!sudo apt-get install python3-pip
!python3 -m pip install --upgrade pip
# Install graphviz
!sudo apt-get install python3-dev graphviz libgraphviz-dev pkg-config
!sudo -H apt-get install libgmp-dev python3-dev
# Install pathlib: the default version taken is 1.0.1
!pip3 install pathlib
# Install lnn lib
!pip3 install git+https://github.com/IBM/LNN.git
which results in an error from the logs: AttributeError: 'PosixPath' object has no attribute 'read_text'
I also couldn't install it, which made me create a docker container for it and run notebooks on Jupyter UI. For now, it's available here, and merge request #67 is created for it.
@asnota Can you retry the install again? The dependencies have been updated to remove some of the problematic libraries like graphviz/libgmp