Repository: oppia/oppia

Issue:
Running scripts.clean led to unexpected import errors
<!--
  - Thanks for taking the time to report a bug in the Oppia project.
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->

**Describe the bug**
Was trying to fix error `ImportError: No module named auth`  by running scripts.clean, After running it I had to deal with two ImportErrors before being able to run any start scripts.
1. `ImportError: No module named builtin`  
2. `ImportError: No module named certifi`

In order to be able to run the scripts I needed to run `pip install future` `and pip install certifi`

**To Reproduce**
Steps to reproduce the behavior:
 1. Run scripts.clean
 2. Afterwards attempt to run scripts.start or scripts.install_third_pary
 3. See error

**Observed behavior**
Running scripts.clean led to Import errors for builtin and certifi

**Expected behavior**
There should be no errors after running scripts.clean or at least documentation on how to handle it in the clean script

**Desktop (please complete the following information; delete this section if the issue does not arise on desktop):**
 - OS: [MacOS Intel]

Running scripts.clean led to unexpected import errors
<!--
  - Thanks for taking the time to report a bug in the Oppia project.
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->

**Describe the bug**
Was trying to fix error `ImportError: No module named auth`  by running scripts.clean, After running it I had to deal with two ImportErrors before being able to run any start scripts.
1. `ImportError: No module named builtin`  
2. `ImportError: No module named certifi`

In order to be able to run the scripts I needed to run `pip install future` `and pip install certifi`

**To Reproduce**
Steps to reproduce the behavior:
 1. Run scripts.clean
 2. Afterwards attempt to run scripts.start or scripts.install_third_pary
 3. See error

**Observed behavior**
Running scripts.clean led to Import errors for builtin and certifi

**Expected behavior**
There should be no errors after running scripts.clean or at least documentation on how to handle it in the clean script

**Desktop (please complete the following information; delete this section if the issue does not arise on desktop):**
 - OS: [MacOS Intel]



Discussion:
Can anyone replicate this issue?
@jimbyo even I faced this same issue today.
@jimbyo But I had yaml module missing instead of builtin.
I faced this issue for certifi today after running scripts.clean. 

The fix was to run `python -m pip install certifi==2020.12.5 --target ../oppia_tools/certifi-2020.12.5` manually before running scripts.start. I think we might need to refactor our scripts to ensure that this does not arise in the future, since it's a serious blocker for newer contributors.

/cc @DubeySandeep 
@jimbyo I was not able to reproduce the issue, I wanted to check whether you have followed the [prerequisites step for installation](https://github.com/oppia/oppia/wiki/Installing-Oppia-%28Linux%29#prerequisites)?
I found that we need to run scripts.install_third_party_libs to download all the libraries. (It internally downloads certifi) Can you try that?

(Also, in general running start.py script will download all the libs, have you tried running scripts.start after cleaning?)
Stack trace:

```
$ python -m scripts.clean
Temporary and installed files deleted
$ python -m scripts.start
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/opensource/oppia/scripts/start.py", line 30, in <module>
    from constants import constants
  File "constants.py", line 26, in <module>
    import python_utils
  File "python_utils.py", line 46, in <module>
    import certifi  # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
ImportError: No module named certifi
```
![image](https://user-images.githubusercontent.com/30050862/116778336-eb9dd700-aa8e-11eb-9b0c-e7100c0ad001.png)

**To Reproduce**
Steps to reproduce the behavior:
1. Run `scripts.clean`
2. Run `scripts.start`

Attempted to resolve error:

1. Ran `python -m pip install contextlib2==0.6.0.post1`
2. Ran `scripts.start`
2. The following error came:
![image](https://user-images.githubusercontent.com/30050862/116778409-57803f80-aa8f-11eb-96c6-b2ed55dbdcad.png)

Can anyone replicate this issue?
@jimbyo even I faced this same issue today.
@jimbyo But I had yaml module missing instead of builtin.
I faced this issue for certifi today after running scripts.clean. 

The fix was to run `python -m pip install certifi==2020.12.5 --target ../oppia_tools/certifi-2020.12.5` manually before running scripts.start. I think we might need to refactor our scripts to ensure that this does not arise in the future, since it's a serious blocker for newer contributors.

/cc @DubeySandeep 
@jimbyo I was not able to reproduce the issue, I wanted to check whether you have followed the [prerequisites step for installation](https://github.com/oppia/oppia/wiki/Installing-Oppia-%28Linux%29#prerequisites)?
I found that we need to run scripts.install_third_party_libs to download all the libraries. (It internally downloads certifi) Can you try that?

(Also, in general running start.py script will download all the libs, have you tried running scripts.start after cleaning?)
Stack trace:

```
$ python -m scripts.clean
Temporary and installed files deleted
$ python -m scripts.start
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/opensource/oppia/scripts/start.py", line 30, in <module>
    from constants import constants
  File "constants.py", line 26, in <module>
    import python_utils
  File "python_utils.py", line 46, in <module>
    import certifi  # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
ImportError: No module named certifi
```
![image](https://user-images.githubusercontent.com/30050862/116778336-eb9dd700-aa8e-11eb-9b0c-e7100c0ad001.png)

**To Reproduce**
Steps to reproduce the behavior:
1. Run `scripts.clean`
2. Run `scripts.start`

Attempted to resolve error:

1. Ran `python -m pip install contextlib2==0.6.0.post1`
2. Ran `scripts.start`
2. The following error came:
![image](https://user-images.githubusercontent.com/30050862/116778409-57803f80-aa8f-11eb-96c6-b2ed55dbdcad.png)


Resolving patch:
diff --git a/scripts/start.py b/scripts/start.py
--- a/scripts/start.py
+++ b/scripts/start.py
@@ -27,7 +27,6 @@
 import subprocess
 import time
 
-from constants import constants
 
 from . import install_third_party_libs
 # This installs third party libraries before importing other files or importing
@@ -37,6 +36,7 @@
 from . import build # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
 from . import common # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
 
+from constants import constants # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
 import feconf # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
 import python_utils # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
 


Test patch: