openfisca / openfisca-core

OpenFisca core engine. See other repositories for countries-specific code & data.
https://openfisca.org
GNU Affero General Public License v3.0
169 stars 75 forks source link

Runnin openfisca serve on Windows #962

Open sdenier opened 4 years ago

sdenier commented 4 years ago

Hi there

Summary: can we install and run openfisca serve on Windows? Right now I have the following error:

ImportError: OpenFisca is missing some dependencies to run the Web API: 'No module named 'fcntl''. 

NB - my use case: I am not an active developer on OF, but I would like to run the legislation-explorer on a branch of openfisca-france (not yet merged into master). So I'm just trying to run it locally.

Steps followed:

Traceback (most recent call last):
  File "d:\workspace\of-france\venv-of-france\lib\site-packages\openfisca_web_api\scripts\serve.py", line 11, in <module>
    from gunicorn.app.base import BaseApplication
  File "d:\workspace\of-france\venv-of-france\lib\site-packages\gunicorn\app\base.py", line 11, in <module>
    from gunicorn import util
  File "d:\workspace\of-france\venv-of-france\lib\site-packages\gunicorn\util.py", line 9, in <module>
    import fcntl
ModuleNotFoundError: No module named 'fcntl'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\c82iden\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\c82iden\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\workspace\of-france\venv-of-france\Scripts\openfisca.exe\__main__.py", line 7, in <module>
  File "d:\workspace\of-france\venv-of-france\lib\site-packages\openfisca_core\scripts\openfisca_command.py", line 64, in main
    from openfisca_web_api.scripts.serve import main
  File "d:\workspace\of-france\venv-of-france\lib\site-packages\openfisca_web_api\scripts\serve.py", line 14, in <module>
    handle_import_error(error)
  File "d:\workspace\of-france\venv-of-france\lib\site-packages\openfisca_web_api\errors.py", line 9, in handle_import_error
    raise ImportError("OpenFisca is missing some dependencies to run the Web API: '{}'. To install them, run `pip install openfisca_core[web-api]`.".format(error))
ImportError: OpenFisca is missing some dependencies to run the Web API: 'No module named 'fcntl''. To install them, run `pip install openfisca_core[web-api]`.

I also tried to clone the repo and start from it, run with ConEmu, or look at this page https://openfisca.org/doc/installation/index.html but not luck.

I didn't go for the Docker solution yet.

sdenier commented 4 years ago

OK digging quickly into the issue I see this is related to gunicorn which does not support Windows (not yet... this issue is opened since 2013 https://github.com/benoitc/gunicorn/issues/524)

Maybe we can close this issue unless there is an easy solution

guillett commented 4 years ago

You should be able to run OpenFisca with Waitress. cf. https://github.com/mes-aides/simulateur/issues/57 We faced the same issue.

sdenier commented 4 years ago

Thanks for the tip!

I did a shameless/rudimentary copy of the serve script to use waitress and it worked: https://github.com/openfisca/openfisca-core/blob/master/openfisca_web_api/scripts/serve.py

for the record (not complete, just to get the idea)

from waitress import serve

DEFAULT_PORT = '5000'
HOST = '0.0.0.0'

def main(parser):
    configuration = {}
    configuration = read_user_configuration(configuration, parser)

    tax_benefit_system = build_tax_benefit_system(
        configuration.get('country_package'),
        configuration.get('extensions'),
        configuration.get('reforms')
        )
    app = create_app(
        tax_benefit_system,
        configuration.get('tracker_url'),
        configuration.get('tracker_idsite'),
        configuration.get('tracker_token'),
        configuration.get('welcome_message')
        )
    serve(app, host=HOST, port=DEFAULT_PORT)

Note sure if someone is interested in a PR, there would be some refactoring to perform.

Also note that legislation-explorer needs some tricks to start in Windows environment:

.env

HOST=localhost
PORT=2020
# PATHNAME=/ # otherwise SSR would output some urls such as http://bootstrap/css/bootstrap.css ?

API_URL=http://localhost:5000
CHANGELOG_URL=https://github.com/openfisca/country-template/blob/master/CHANGELOG.md

UI_STRINGS={"en":{"countryName":"the development environment"},"fr":{"countryName":"l’environnement de développement"}}

# MATOMO_URL=https://stats.data.gouv.fr
# MATOMO_SITE_ID=4

package.json

{
"scripts":
    "start": "set NODE_ENV=production&&node --require dotenv/config index.js",
}
pzuldp commented 3 years ago

Hi everyone! We (@clallemand and I) have encountered the same problem recently (we try to launch openfisca serve, which fails because of a missing fcntl package ; we follow the recommandation to first run pip install openfisca-core[web-api], which does not solve the issue) This problem is made a bit more acute when using openfisca-france, because testing the compatibility with the web api is now recommended as a validation step of any PR. As a temporary fix we have resolved to asking third parties (such as @benjello or @HAEKADI , thanks to both of you!!) to test our branch for us.