Repository: streamlit/streamlit

Issue:
Streamlit fails to start without Git executable
# Summary

Streamlit version `0.69.1` fails to start when run inside a Docker container that doesn't have Git installed.

# Steps to reproduce

1. Create a `Dockerfile` with the following contents:
```dockerfile
FROM python:3.8-slim
RUN pip install streamlit
CMD ["streamlit", "hello"]
```
2. Build the image:
```bash
docker build -t demo .
```
3. Run the app:
```bash
docker run -it --rm demo
```

## Expected behavior:

Streamlit starts without issues.

## Actual behavior:

Streamlit fails to start and displays the following error message:

```bash
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/git/__init__.py", line 83, in <module>
    refresh()
  File "/usr/local/lib/python3.8/site-packages/git/__init__.py", line 73, in refresh
    if not Git.refresh(path=path):
  File "/usr/local/lib/python3.8/site-packages/git/cmd.py", line 278, in refresh
    raise ImportError(err)
ImportError: Bad git executable.
The git executable must be specified in one of the following ways:
    - be included in your $PATH
    - be set via $GIT_PYTHON_GIT_EXECUTABLE
    - explicitly set via git.refresh()

All git commands will error until this is rectified.

This initial warning can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:
    - quiet|q|silence|s|none|n|0: for no warning or exception
    - warn|w|warning|1: for a printed warning
    - error|e|raise|r|2: for a raised exception

Example:
    export GIT_PYTHON_REFRESH=quiet
```

## Is this a regression?

**yes** (worked up until at least version `0.67.1`)

# Debug info

- Streamlit version: `0.69.1`
- Python version: `3.8.6`
- Using Conda? PipEnv? PyEnv? Pex? **NO**
- OS version: `4.19.76-linuxkit`

# Additional information

This bug can be worked around by setting `GIT_PYTHON_REFRESH=quiet` environment variable inside the Docker image.



Discussion:
+1 
This worked up until version `0.68.0`
Thanks for reporting, we're looking into making a patch for this.
Hi, getting the same error in `streamlit==0.73.0`.

Dockerfile

```
FROM python:3.7.4-slim-stretch

COPY requirement.txt requirement.txt

RUN pip install -r requirement.txt

# copy code base in docker image
COPY . .

# exposing default port for streamlit
EXPOSE 8501

# run app
CMD streamlit run frontend.py
```

I wasn't getting any error with `streamlit==0.70.0`.

Resolving patch:
diff --git a/lib/streamlit/git_util.py b/lib/streamlit/git_util.py
--- a/lib/streamlit/git_util.py
+++ b/lib/streamlit/git_util.py
@@ -2,8 +2,6 @@
 import re
 from typing import Optional, Tuple
 
-import git  # type: ignore[import]
-
 # Github has two URLs, one that is https and one that is ssh
 GITHUB_HTTP_URL = r"^https://(www\.)?github.com/(.+)/(.+).git$"
 GITHUB_SSH_URL = r"^git@github.com:(.+)/(.+).git$"
@@ -21,6 +19,8 @@ def __init__(self, path):
         self.git_version = None  # type: Optional[Tuple[int, ...]]
 
         try:
+            import git  # type: ignore[import]
+
             self.repo = git.Repo(path, search_parent_directories=True)
             self.git_version = self.repo.git.version_info
             if self.git_version >= MIN_GIT_VERSION:
@@ -29,6 +29,7 @@ def __init__(self, path):
 
         except:
             # The git repo must be invalid for the following reasons:
+            #  * git binary or GitPython not installed
             #  * No .git folder
             #  * Corrupted .git folder
             #  * Path is invalid


Test patch: