Alexander Dunkel, Institute of Cartography, TU Dresden
An author of a repository on Github. We want to re-create this environment in Jupyter.
requiements.txt
requirements.txt
is usually a starting point only. Just two issues I immediately see:There are more problems that I go through step by step below.
Pytorch is scientific software and even under linux, conda still seems the preferred way to install these big scientific Python packages.
Create environment using conda.
g++, gdal-bindings
)venv
does not work here since we cannot define the Python version (it depends on the System Python(s) available)pytorch==1.8.0
as the specific version we want and let conda decide which matching python version is usedtorchvision==0.9.0
is needed because torchvision is tightly coupled with torch, and the the pytorch website provides official instructions, also for past versions, which states 0.9.0
as the matching version--channel pytorch
as the source of packages, according to the pytorch docs abovecpuonly
flag to indicate that we don't have a GPU ready, which makes things easier (e.g. we don't care for CUDA compatibility)--prefix /envs/cagis_env
for the environment. This folder is bind-mounted from the outside, meaning that it gets stored at a persistent location outside of this jupyter containerNote: Remove the > /dev/null
to see the (long) output in cells below.
%%bash
conda create \
--prefix /envs/cagis_env \
pytorch==1.8.0 torchvision==0.9.0 cpuonly --channel pytorch -y --quiet > /dev/null
Note that installing torch directly via requirements.txt
did not work due to unsolvable dependencies.
Now, make a copy of requirements.txt
(e.g. requirements-base.txt
)
pytorch
and add tensorflow-cpu>=2.6.0
.pytorch
abovetensorflow
is used in the authors notebook, but not added to the requirements.>=2.6.0
, <=0.8.1
etc.), this helps the dependency resolvernumpy==1.19.4
geopandas<=0.8.1
matplotlib==3.4.3
dgl==0.6.1
scikit-learn==0.24.2
fiona==1.8.13
tensorflow-cpu>=2.6.0
torchvision
We will install these additional dependencies via pip.
For fiona, geopandas (etc.), we also need to install c-dependency libgdal-dev
.
!apt-get update && apt-get install libgdal-dev -y > /dev/null
Install additional dependencies from requirements-base.txt
:
!/envs/cagis_env/bin/python -m pip install -r requirements-base.txt
Finally, install ipykernel, so this env can be loaded in jupyter:
%%bash
/envs/cagis_env/bin/python -m pip install ipykernel
/envs/cagis_env/bin/python -m ipykernel install --user --name=cagis_env
Now, hit F5 (or click refresh) and load cagiv_env
Kernel on the top-right corner of Jupyter Lab.
!jupyter nbconvert --to html_toc \
--output-dir=. dependencies.ipynb \
--template=./nbconvert.tpl \
--ExtractOutputPreprocessor.enabled=False >&- 2>&-