why gunicorn command not found with gunicorn installed?
Asked Answered
L

8

26

I have intalled gunicorn,but gunicorn command not found:

# pip3.4 install gunicorn
Requirement already satisfied (use --upgrade to upgrade): gunicorn in /usr/local/python3.4/lib/python3.4/site-packages

# gunicorn
-bash: gunicorn: command not found

what is the problem,is gunicorn install path not be recognized by system?

Lifeordeath answered 16/4, 2015 at 15:54 Comment(14)
I presume you have installed it to the system and to a venv. Use locate to find the gunicorn binary and ensure that directory is within your PATH.Featheredge
i am not using venv ,gunicorn is not in my system path,i create a gunicorn in system path and type some code ,then it worked, but why not it is automaticaly included in path?Lifeordeath
I'm not 100% sure. What OS are you using?Featheredge
production server centos 6.5 x64,that's kind of weird,my development env is virtual machine,the same OS with my production serverLifeordeath
There is probably something screwy with the path. I would check itFeatheredge
sure,thanks,please keep me updated when you find something~and i'v got a solution in the posted answer,that's what i can do.Lifeordeath
Are you using Python3?Featheredge
yes,python3.4.2 exactly.Lifeordeath
How did you install it? Am I correct in thinking CentOS has python 2 by default?Featheredge
yes,the system default python2.6.what i do is :first,i installed python3.4.2 from source python3.4.2.tar.gz with cutom path --prefix=/usr/local/python3.4 ,then i put python3.4 into sys path /usr/bin/python3.4, and pip3.4 into /usr/bin/pip3,4, second,i installed gunicorn using pip3.4 install gunicorn,that' all.Lifeordeath
Okay. Locate the gunicorn executable from the pip install which will be somewhere in /usr/local/python3.4 I would imagine as add the location to your path. Gunicorn is not being picked up because the executable isn't going in to /usr/bin.Featheredge
yeah,it seems thing happens as what you say,i recalled that i installed python3.4 in my development server without custom path --prefix,but my productions server did,and in dev server gunicorn went into /usr/local/bin/gunicorn automatically,and i checked my production server,it did locate in /usr/local/python3.4/bin/.And,why would this happen?Lifeordeath
Because pip places the files within Pythons bin directory and this needs to be in PATH. You can see this with virtualenv. When you install a package with a binary it goes in to the venv bin. This is auto in path because of the the source command.Featheredge
oh,i see,Thanks,Thanks for your time,I very appreciate what you did to me :)Lifeordeath
M
20

I faced the same issue and it turns out I had to add gunicorn binary path to Linux PATH variable. You can start by echoing $PATH to see all binary path listed on the system. Then find out where gunicorn is installed. For my case I was using python virtual environment and pyenv which helps manage several python versions and dependencies separately.

(venv3.6) dave@daverig (develop)✗ % pip show gunicorn
Name: gunicorn
Version: 19.7.1
Summary: WSGI HTTP Server for UNIX
Home-page: http://gunicorn.org
Author: Benoit Chesneau
Author-email: [email protected]
License: MIT
Location: /home/dave/.pyenv/versions/3.6.2/envs/venv3.6/lib/python3.6/site-packages

Notice gunicorn is installed in /home/dave/.pyenv/versions/3.6.2/envs/venv3.6/lib/python3.6/site-packages and the corresponding path for the binaries for this particular python version is at /home/dave/.pyenv/versions/3.6.2/envs/venv3.6/bin. So I had to add that to Linux path via ~/.profile file like so;

export PATH=$PATH:$HOME/.pyenv/versions/3.6.2/envs/venv3.6/bin then ofcourse you want to refresh this using source ~/.profile or restart your terminal. Once I was able to do this, gunicorn binary was now available on my console;

(venv3.6) dave@daverig (develop)✗ % gunicorn --version
gunicorn (version 19.7.1)
Mallarme answered 7/5, 2019 at 15:26 Comment(2)
How would one do this from within a deployed Google App Engine instance? I ask because locally, the docker container does have gunicorn on the path.Forwent
Thank you so much David for this elaborated response. I spent so much time on figuring this out. I use mac and zhc terminal. I followed your instructions for my case and it worked. Can you explain why had to do both: add to the file (your case ~/.profile) and to export the path?Institutive
B
16

I had the same problem on Debian.

It turns out that on Debian the documentation advises to install gunicorn via apt:

$ sudo apt install gunicorn
Barbour answered 26/6, 2019 at 14:15 Comment(3)
sudo apt install gunicorn3 if you are using Python3Hydrography
And differences between this and python3-gunicorn ?Repudiation
There is no gunicorn3, it is just alias for gunicorn debian package - as I understand it is a /usr/bin/gunicorn wrapper for python3-gunicorn!?Gerda
F
6

Installing gunicorn from source saved me after 2 hours trying!

pip3 install git+https://github.com/benoitc/gunicorn.git
Frayne answered 13/5, 2018 at 6:46 Comment(0)
L
5

i just created a file named gunicorn and type these codes below which is the same as my development server , and included it into system path,such as /usr/bin

#!/usr/local/bin/python3.4

#-*- coding: utf-8 -*-
import re
import sys

from gunicorn.app.wsgiapp import run


if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$','',sys.argv[0])
        sys.exit(run())

in this way, it solved my problem,but still confused me,why gunicorn command not generated and included into system path automatically?and why my development server did ,both the same OS (centos 6.5 x64)

Lifeordeath answered 16/4, 2015 at 17:52 Comment(1)
This also happened to me, using a Framework-version of Python 3 on OS X . Thanks for sharing the script!Meat
E
2

This worked for me

python3 -m gunicorn -c server.py core.wsgi

My server.py

from multiprocessing import cpu_count
from os import environ


def max_workers():
    return cpu_count()


bind = "0.0.0.0:" + environ.get("PORT", "8080")
max_requests = 1000
worker_class = "gevent"
workers = max_workers()

env = {
    "DJANGO_SETTINGS_MODULE": 'core.settings'
}

reload = True
name = "core"
Ethics answered 22/12, 2023 at 4:38 Comment(0)
J
1

If you installed python3 from source compiled, you should export your python3 PATH:

export PATH=$PATH:/usr/local/python3/bin
Jamieson answered 25/11, 2020 at 9:17 Comment(0)
C
0

Are you use python3.4-venv?

if true

  • Delete env folder
  • Just reinstall: python3.4-venv. Ex for ubuntu: apt install python3.4-venv
  • Exec: python3.4 -m venv env
  • source env/bin/activate
  • reinstall gunicorn by : pip3 install gunicorn or install from requirements.txt by pip3 install -r requirements.txt
Cerebro answered 6/10, 2022 at 7:29 Comment(0)
B
-4

go to terminal and change directory to environment and then type the below command.

pip install gunicorn

#Enjoy1

Butene answered 26/6, 2020 at 13:34 Comment(1)
Why was this answer downgraded? It's valid if the OP is trynna install the gunicorn in his/her emvironment.Glossectomy

© 2022 - 2024 — McMap. All rights reserved.