At the current moment I'm playing with Cython and trying to figure out how I can host a Cython Flask app (for example) on heroku.
Let's say my project looks like this (after cython compile):
_/cythonheroku
|-- requirements.txt
|-- run.py
|-- Procfile
|__/app
|-- __init__.py
|-- app.c
|-- app.cpython-36m-darwin.so
|-- app.pyx
Now, app.pyx has a standard Flask app in it with some cython adjustments, like so:
#cython: infer_types=True
from flask import Flask
app = Flask(__name__)
@app.route('/', methods=['GET'])
def index():
cdef long x = 10000000
cdef long long y = 0
cdef int i
for i in range(x):
y += i
return str(y)
Then, with the command cythonize -i app/app.pyx
I compile my app.pyx code.
In run.py
file I have:
from app.app import app
app.run()
And starting this from my command line python run.py
will start a server on a localhost when I see a returned value from my for
loop.
The problem: After I push this to heroku I get the error on the first line of run.py:
no module named app
As far as I understand – heroku just cant see my compiled app file.
UPD: Command in Procfile
:
web: gunicorn run:app --log-file=-
UPD2:
After some tests I figured out that Heroku can't recognize app.cpython-36m-darwin.so
as a module. That's why I got that error.
Now the question is – how can I make heroku recognize .so
file as python module?