I am having issues deploying my Pyramid app on Heroku. It runs fine locally but as soon as I try to launch it I receive this error "pkg_resources.DistributionNotFound: mymedaproject". mymedaproject is the name of my project and is not a python library which is why I am confused. I followed the instructions from this recipe to get to this point:
http://pyramid-cookbook.readthedocs.org/en/latest/deployment/heroku.html
Any ideas?
May be you forgot to put your python project mymedaproject in development mode. What follows is the relevant part of the cookbook recipe.
Create a Procfile
$ echo "web: ./run" > Procfile
Create run with the following:
#!/bin/bash
python setup.py develop
python runapp.py
The first line puts your python project in development mode and enables Paste to load it using your INI file. Make sure Procfile, run, runapp.py and setup.py are in same directory.
References
Getting Started with Python on Heroku
Process Types and the Procfile
Optimization
running a script using a Procfile should work without making it executable
$ echo "web: sh ./run" > Procfile
Check your .gitignore file that it isn't blocking any egg or egg-info information.
If it is, Heroku won't be receiving the egg for your application.
Related
I made a website in node.js and I have used child process to run python scripts and use their results in my website. But when I host my application on heroku, heroku is unable to run the python scripts.
I have noticed that heroku was able to run python scripts which only had inbuilt python packages like sys, json but it was failing for scripts which were using external packages like requests, beautifulsoup.
Attempt-1
I made a requirements.txt file inside the project folder and pushed my code to heroku again. But it was still not working. I noticed that heroku uses the requirements.txt file only for python based web applications but not for node.js applications.
Attempt-2
I made a python virtual env inside the project folder and imported the required python packages into the venv. I then removed gitignore from the venv and pushed the whole venv folder to heroku. It still didn't work.
Please let me know if anyone came across a way to handle this.
You can use a Procfile to specify a command to install the python dependencies then start the server.
Procfile:
web: pip install -r requirements.txt && npm start
Place Procfile in your project's root directory and deploy to heroku.
Solution:
Have a requirements.txt file in your project folder.
After you create a heroku app using "heroku create", heroku will identify your app as python based and will not download any of the node dependencies.
Now, go to your heroku profile and go to your app's settings. There is an option named "Add Buildpack" in there. Click on that and add node.js as one of the buildpacks.
Go back to your project and push it to heroku. This time heroku will identify your app as both python and node.js based and will download all the required files.
I build my flask app, it requires external files through the runtime.
when I build the app, meaning I run > gunicorn app:app (the app startup file is called app.py but that didn't bother). It runs awesomely.
Now when I decided to make a sort of shell script to execute it (actually to make a couple of dependencies and environment checking but for the sake of simplifying, I created startup.sh in the same directory as app.py and it contains only the following instruction unquoted: "gunicorn app:app"), it just throws errors.
and this is the last one ...
Please help..
yep just as I guessed, it should be run within the script inside a virtualenv so that it will execute python 3 :)
I'm not experienced with Django. I just want to get this project running on a localhost (on Mac). Normally I run python manage.py runserver inside a virtualenv but I can't do that without a manage.py file! I must be doing something obviously wrong if this project has 264 GitHub stars.
https://github.com/shacker/django-todo
How can I make this work?
First, it's almost impossible to get a project running without manage.py not just because of the server but also the migrations..
Second, the django codes in the github link especially the todo folder is an app of a django project and you need to add that on your INSTALLED_APPS in your settings.py file
setup script is used to install whole project with required dependency packages, once you done with setup script installation then you can import that project into your local project
Goto Project directory and run below commands:
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
Finally u can see the project in the browser http://127.0.0.1:8000
I'm trying to run a simple hello world python program on my heroku server. I'm new to heroku.I was able to successfully deploy my script to heroku.
My python script and procfile are given below,
hi.py
print("hello world")
Procfile
web: python hi.py
I got "Hello world" as output when i ran heroku run web on my terminal.But when i try to run the app using heroku web url it shows the following error.
Application Error An error occurred in the application and your page
could not be served. Please try again in a few moments.
What did i do wrong here? I'm newbie to heroku & its concepts, please do bare.
There are three types of dyno configurations available on Heroku:
Web -- receives web traffic.
Worker -- keeps processing tasks/queues in the background.
One-off -- executed once. e.g.: backup.
If you're interested in running a script, do not care about receiving web traffic on it, and don't have a queue to process, then One-off dynos are likely what you'll want to use. This would be useful for database migrations or backups and whatnot.
Minimal example below.
Sample one-off dyno with Heroku and python AKA “hello world”
This assumes you have already created your app on Heroku and are able to use Herolu CLI from the command-line.
A minimal “hello world” Python script would then look like this. Only 2 files required:
requirements.txt Required, but can be left empty.
task.py with content print("hello world")
Then deploy to Heroku, e.g.:
git add .;
git commit -m "My first commit";
git push heroku master
After that, you'll be able to run your script with heroku run python task.py (and should see the long-awaited hello world in the output.)
If you want to run your program at specific times, use the free Heroku Scheduler add-on.
FYI, Procfile is optional. If you set it to hello: python task.py then you'll be able to run your program with just heroku run hello.
(Note that leaving requirements.txt empty will trigger You must give at least one requirement to install (see "pip help install") warnings on deploy. It's just a warning though and doesn't prevent proper deployment of the program.)
I disagree and state you want flask
main_app.py
import flask
app = flask.Flask(__name__)
#app.route("/")
def index():
#do whatevr here...
return "Hello Heruko"
then change your procfile to web: gunicorn main_app:app --log-file -
I recently made some changes to the structure of my Flask app hosted on heroku and now heroku has decided to detect it as a Node.js app intead of a Python app. My application uses both python (Flask) for the backend api and javascript for the front end.
The changes I made included integrating npm and bower into my application to streamline the javascript development of the app.
The problem was introduced when I added a package.json to my root directory when I started using npm. It seems that the build detection script runs the nodejs detection first (here) which leads to this code: if [ -f $1/package.json ]; then
echo "Node.js" && exit 0 executing and Heroku thinks it's a nodejs app and exits before the python detection has a chance to run.
To solve this I had to manually tell Heroku that I wanted a python build using this command
heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-python.
The package.json file is causing Heroku to detect it as a node.js app. To prevent this, add the file name to a .slugignore file:
echo 'package.json' >> .slugignore
git add .slugignore
.slugignore is like .gitignore. It resides in the root directory of your repository and should contain a list of filenames and wildcard patterns. The matching files remain in your git repository, but are deleted from the slug after you push to Heroku. The deletion occurs before the buildpacks run, so the node.js buildpack won't find package.json and the app won't be misidentified as a node.js app.