how to make '!tree' work after '!pip install tree' on google colab notebook?

Viewed 2441

I did !pip install tree on google colab notebook. It showed that Pillow in /usr/local/lib/python3.6/dist-packages (from tree) (4.3.0). But when I use !tree. The notebook reminded me that bin/bash: tree: command not found. How to solve it?

I tried several times but all failed.

It showed:

Collecting tree
  Downloading https://files.pythonhosted.org/packages/29/3f/63cbed2909786f0e5ac30a4ae5791ad597c6b5fec7167e161c55bba511ce/Tree-0.2.4.tar.gz
Requirement already satisfied: Pillow in /usr/local/lib/python3.6/dist-packages (from tree) (4.3.0)
Collecting svgwrite (from tree)
  Downloading https://files.pythonhosted.org/packages/87/ce/3259f75aebb12d8c7dd9e8c479ad4968db5ed18e03f24ee4f6be9d9aed23/svgwrite-1.2.1-py2.py3-none-any.whl (66kB)
     |████████████████████████████████| 71kB 23.9MB/s 
Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from tree) (41.0.1)
Requirement already satisfied: click in /usr/local/lib/python3.6/dist-packages (from tree) (7.0)
Requirement already satisfied: olefile in /usr/local/lib/python3.6/dist-packages (from Pillow->tree) (0.46)
Requirement already satisfied: pyparsing>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from svgwrite->tree) (2.4.0)
Building wheels for collected packages: tree
  Building wheel for tree (setup.py) ... done
  Stored in directory: /root/.cache/pip/wheels/c7/08/aa/42261411808c634cd1d0e9fe6cde5e78bf47c2c8028f3930af
Successfully built tree
Installing collected packages: svgwrite, tree
Successfully installed svgwrite-1.2.1 tree-0.2.4

!pip install tree
!tree

I expect it shows the structure of the files in the directory.

3 Answers

You seem to have confused pip with the local package manager?

!apt-get install tree does what you want:

.
└── sample_data
    ├── anscombe.json
    ├── california_housing_test.csv
    ├── california_housing_train.csv
    ├── mnist_test.csv
    ├── mnist_train_small.csv
    └── README.md

1 directory, 6 files

I think you have installed wrong tree with pip https://pypi.org/project/Tree/

Right code for install on Mac brew install tree

sudo apt-get install tree

the command for Debian / Ubuntu Linux / Mint sudo apt install tree

Any request feel free for contact

also, it's doesn't work for me but here is an alternative code for the tree dictionary

import os
for path, dirs, files in os.walk('/content/sample_data'):
  print (path)
  for f in files:
    print (f)

enter image description here

Related