Repository: readthedocs/readthedocs.org

Issue:
`ModuleNotFoundError: No module named 'six'` on build
## Details

I tried building my docs for my project, yet this fails with a ModuleNotFoundError

[My conf file](https://github.com/Arthurdw/dblstats/blob/v0.1.6/docs/source/conf.py)
[Build url](https://readthedocs.org/projects/dblstats/builds/12441143/)

## Expected Result

A successful build

## Actual Result

The following error:
```
Running Sphinx v3.3.1

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/envs/latest/lib/python3.7/site-packages/sphinx/config.py", line 319, in eval_config_file
    execfile_(filename, namespace)
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/envs/latest/lib/python3.7/site-packages/sphinx/util/pycompat.py", line 89, in execfile_
    exec(code, _globals)
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/checkouts/latest/docs/source/conf.py", line 82, in <module>
    from six import string_types
ModuleNotFoundError: No module named 'six'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/envs/latest/lib/python3.7/site-packages/sphinx/cmd/build.py", line 279, in build_main
    args.tags, args.verbosity, args.jobs, args.keep_going)
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/envs/latest/lib/python3.7/site-packages/sphinx/application.py", line 219, in __init__
    self.config = Config.read(self.confdir, confoverrides or {}, self.tags)
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/envs/latest/lib/python3.7/site-packages/sphinx/config.py", line 174, in read
    namespace = eval_config_file(filename, tags)
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/envs/latest/lib/python3.7/site-packages/sphinx/config.py", line 332, in eval_config_file
    raise ConfigError(msg % traceback.format_exc()) from exc
sphinx.errors.ConfigError: There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/envs/latest/lib/python3.7/site-packages/sphinx/config.py", line 319, in eval_config_file
    execfile_(filename, namespace)
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/envs/latest/lib/python3.7/site-packages/sphinx/util/pycompat.py", line 89, in execfile_
    exec(code, _globals)
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/checkouts/latest/docs/source/conf.py", line 82, in <module>
    from six import string_types
ModuleNotFoundError: No module named 'six'


Configuration error:
There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/envs/latest/lib/python3.7/site-packages/sphinx/config.py", line 319, in eval_config_file
    execfile_(filename, namespace)
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/envs/latest/lib/python3.7/site-packages/sphinx/util/pycompat.py", line 89, in execfile_
    exec(code, _globals)
  File "/home/docs/checkouts/readthedocs.org/user_builds/dblstats/checkouts/latest/docs/source/conf.py", line 82, in <module>
    from six import string_types
ModuleNotFoundError: No module named 'six'
```


Discussion:
Same issue. I tried to recompile a version that were successfully compiled yesterday, and it failed, so it is not related to my sources.
Same error. I wanted to try this tool today for the first time. What bad luck !!! Red alert devs.
Hi, I had the same issue. At first, I followed the recommendation https://github.com/readthedocs/readthedocs.org/issues/7704#issuecomment-735030431 but it was not complete without specifying requirements in the settings. 

## Solved 
Here is how I **solved** it, first follow https://github.com/readthedocs/readthedocs.org/issues/7704#issuecomment-735030431, and then click **Admin**, **Advanced Settings** and then under the section **Requirements file** add the file path you created **docs/requirements.txt**. Click on **Save** and **build Version**. I hope this works out for you. 

Cheers. 

This is not a solution.
RTD must work on a simple configuration without declaring any external dependency, and recompiling previous builds must work.
@ynerant, agreed. If I am not wrong, Package `six` needs to be installed on the RTD's end. If it's not already there, we need to specify that in the requirements. This fixed the problem I had, but hopefully, the `dev team` comes up with a better alternative. 
I tried the above solution but it did not work for me...
> I tried the above solution but it did not work for me...

@Jonas231 it didn't for me either in the beginning, but when migrating the items from the `source` folder into the `docs` folder it did work.

> @ynerant, agreed. If I am not wrong, Package `six` needs to be installed on the RTD's end. If it's not already there, we need to specify that in the requirements. This fixed the problem I had, but hopefully, the `dev team` comes up with a better alternative.

I agree, I'll keep this issue open until its fixed.

Yep, that's an issue, docs start failing to build without any changes to their configuration.
> I tried the above solution but it did not work for me...

@Jonas231, the filename mentioned in [.yml](https://github.com/Jonas231/KDP_doc/blob/master/.readthedocs.yml) file is different than what you have in the docs [folder](https://github.com/Jonas231/KDP_doc/blob/master/docs/requirement.txt). I see it is commented for now. 

Also, the way you did `make html` to generate HTML files, you should `make clean` to clean the build folder before you commit on GitHub. Let me know if this works. 
I'm not sure why this started failing now. However, we are appending some extra logic to the user's `conf.py` file and this logic relies on `six` but we are not installing it as a "core requirements" together with the others.

I just did a quick test creating an empty virtualenv and installing our core requirements:

```
$ python -m pip install --upgrade --no-cache-dir setuptools==41.0.1 docutils==0.14 mock==1.0.1 pillow==5.4.1 'alabaster>=0.7,<0.8,!=0.7.5' commonmark==0.8.1 recommonmark==0.5.0 sphinx sphinx-rtd-theme 'readthedocs-sphinx-ext<2.2'

...

$ python
Python 3.7.7 (default, Apr 11 2020, 22:03:50) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import six
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'six'
>>>
```

None of them installed `six` as a dependency. So, we should 

- include it as a "core dependency"
- remove its usage (is seems we only use it to check for `string_types`)

We will have a patch for this soon.
As a workaround while we create the patch and deploy it, you can:

1. create a `requirements.txt` file and add `six` to it
1. use the `readthedocs.yml` config file to install those requirements (https://docs.readthedocs.io/en/stable/config-file/v2.html#python)

Resolving patch:
diff --git a/readthedocs/doc_builder/python_environments.py b/readthedocs/doc_builder/python_environments.py
--- a/readthedocs/doc_builder/python_environments.py
+++ b/readthedocs/doc_builder/python_environments.py
@@ -367,6 +367,7 @@ def install_core_requirements(self):
             'mock==1.0.1',
             'pillow==5.4.1',
             'alabaster>=0.7,<0.8,!=0.7.5',
+            'six',
             'commonmark==0.8.1',
             'recommonmark==0.5.0',
         ]
@@ -623,6 +624,7 @@ def _get_core_requirements(self):
         # Install pip-only things.
         pip_requirements = [
             'recommonmark',
+            'six',
         ]
 
         if self.config.doctype == 'mkdocs':


Test patch:
diff --git a/readthedocs/rtd_tests/tests/test_doc_building.py b/readthedocs/rtd_tests/tests/test_doc_building.py
--- a/readthedocs/rtd_tests/tests/test_doc_building.py
+++ b/readthedocs/rtd_tests/tests/test_doc_building.py
@@ -1197,6 +1197,7 @@ def setUp(self):
             'mock',
             'pillow',
             'alabaster',
+            'six',
         ]
         self.base_conda_requirements = [
             'mock',
@@ -1364,6 +1365,7 @@ def test_install_core_requirements_sphinx_conda(self, checkout_path):
         conda_requirements = self.base_conda_requirements + conda_sphinx
         pip_requirements = [
             'recommonmark',
+            'six',
             'readthedocs-sphinx-ext',
         ]
 
@@ -1405,6 +1407,7 @@ def test_install_core_requirements_mkdocs_conda(self, checkout_path):
         conda_requirements = self.base_conda_requirements
         pip_requirements = [
             'recommonmark',
+            'six',
             'mkdocs',
         ]