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

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.



Solution 1:[1]

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

Solution 2:[2]

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

Solution 3:[3]

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

Solution 4:[4]

You need some extra state(s) to store the results of your quizzes and style your ImageOverlays accordingly.

A minimal change to your current code could consist in having an extra state dictionary:

function MapContent({ doc }) {
  // State to store results
  // { id: true or false (quizz result for doc id) }
  const [resultsDictionary, setResults] = useState({});

  function result2class(id) {
    if (id in resultsDictionary) {
      return resultsDictionary[id] ? "img-overlay-correct" : "img-overlay-wrong";
    } else {
      return "img-overlay";
    }
  }

  const valueCompare = (e, id) => {
    const data = e.target.dataset.tag;
    const value = e.target.value;
    let result;
    if (data != value) {
      console.log("WRONG");
      result = false;
    } else {
      console.log("CORRECT");
      result = true;
    }
    // Shallow clone to force React to see a change
    setResults({
      ...resultsDictionary,
      [id]: result, // new result
    });
  };

  return (<>
    {doc.map((d) => (
      <ImageOverlay
    className={result2class(d.id)}
    key={d.id}
    bounds={[
      [d.latitude - 2, d.longitude - 2],
      [d.latitude + 2, d.longitude + 2],
    ]}
    interactive={true}
    url={`./${d.shape}`}
  >
    <Popup>
      <input type="text" data-tag={d.name} onChange={(e) => valueCompare(e, d.id)}></input>
      <button
        onClick={() => {
          console.log(test);
        }}
      ></button>
    </Popup>
  </ImageOverlay>
    ))}
  </>);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user39430
Solution 2
Solution 3
Solution 4 ghybs