Adam
Adam

Reputation: 2455

Heroku Web Server Won't Start Locally

I am having problems starting heroku web server localy. Here is the error message I am constantlly getting:

PS C:\Users\Dragan\heroku_workspace\python-getting-started> heroku local
[OKAY] Loaded ENV .env File as KEY=VALUE Format
10:01:32 web.1   |  Traceback (most recent call last):
10:01:32 web.1   |    File "c:\users\dragan\anaconda3\lib\runpy.py", line 170, in _run_module_as_main
10:01:32 web.1   |      "__main__", mod_spec)
10:01:32 web.1   |    File "c:\users\usr1\anaconda3\lib\runpy.py", line 85, in _run_code
10:01:32 web.1   |      exec(code, run_globals)
10:01:32 web.1   |    File 
C:\Users\Dragan\Anaconda3\Scripts\gunicorn.exe\__main__.py", line 5, in <module>
10:01:32 web.1   |    File "c:\users\dragan\anaconda3\lib\site-packages\gunicorn\app\wsgiapp.py", line 10, in <module>
10:01:32 web.1   |      from gunicorn.app.base import Application
10:01:32 web.1   |    File "c:\users\dragan\anaconda3\lib\site-packages\gunicorn\app\base.py", line 12, in <module>
10:01:32 web.1   |      from gunicorn import util
10:01:32 web.1   |    File "c:\users\dragan\anaconda3\lib\site-packages\gunicorn\util.py", line 9, in <module>
10:01:32 web.1   |      import fcntl
10:01:32 web.1   |  ImportError: No module named 'fcntl'
[DONE] Killing all processes with signal  null
10:01:33 web.1   Exited with exit code 1

I am following every step described in this tutorial LINK I installed the virtual environment inside the project 'python-getting-started'. I am trying to start the local web server from the project's root directory.

Can anybody help me resolve this issue?

UPDATE_1: I have installed Heroku Toolbelt for Windows, and I have installed Anaconda for Python.

Upvotes: 12

Views: 6424

Answers (3)

Irfan wani
Irfan wani

Reputation: 5075

Answer by @vkc is correct but incomplete.

As mentioned by the documentation, we should use heroku local web -f Procfile.windows command on windows to run our app locally.

This command simply means run the app locally and use Procfile.windows as the Procfile instead of the default one ('Procfile').

So for this to work, we need to create a file called Procfile.windows at the root directory of our project and add this line to it;

web: python manage.py runserver 0.0.0.0:5000

Which means run the server at port 5000.

Also before doing that, we need to have environment variables (if any) available locally in a .env file.

We can get the list of our env variables by running this command;

heroku config

copy the result and create a .env file and paste the result in it.

Also don't forget to set the variables properly;

VAR_NAME=VAR_VALUE (no quotes required)

Also add this file to .gitignore.

After that, run this command;

python manage.py collectstatic

And you are good to go.

Upvotes: 0

vkc
vkc

Reputation: 626

According to the Heroku tutorial, try this in Windows instead of heroku local:

heroku local web -f Procfile.windows

https://devcenter.heroku.com/articles/getting-started-with-python#run-the-app-locally

Upvotes: 20

rdegges
rdegges

Reputation: 33824

You are trying to deploy a Python web application to Heroku using the gunicorn web server. This works great on Heroku, but CANNOT WORK on Windows because gunicorn only runs on *nix based operating systems.

What you can do instead of running heroku local is run your web server WITHOUT gunicorn locally. Simply say something like $ python myapp.py or whatever your main python web server file is. That will start your server locally using Python ONLY, and not gunicorn.

Upvotes: 3

Related Questions