Hi,

I use gunicorn in my venv

I have quite few venv that run gunicorn.

I would like to reuse gunicorn for other venv

I launch my web application like this

#PWD = venv dir
source ./bin/activate
gunicorn A_WebApp:app
#A_WebApp is my python file A_WebApp.py

I supposes that gunicorn is a shell program ? if yes I should use $PATH ?
or gunicorn is a Python program only ? and then what I should do to use gunicorn in another venv ?

Thanks.

  • SpongeB0B@programming.devOP
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    4 months ago

    I don’t want to make the venv portable…
    I want to use the gunicorn that is installed in one venv accessible to other venv

    • onlinepersona@programming.dev
      link
      fedilink
      English
      arrow-up
      4
      ·
      4 months ago

      I don’t think that’s possible without some dirty, dirty hacks i.e adding the right paths from the other venv to your running process. Do you want dirty hacks? Because that’s just asking for trouble. If you have an application that requires libA-v1 and the gunicorn venv uses libA-v2, you’re going to have a conflict at runtime.

      I supposes that gunicorn is a shell program ?

      source ./bin/activate
      which gunicorn # outputs the path to gunicorn
      less `which gunicorn` # reads gunicorn
      

      gunicorn takes a module and a module name with a variable name. Modules are found by searching in specific paths. You can add to that search path by modifying PYTHONPATH. How it works is explained here (quite wordy).

      To know which path to add to PYTHONPATH, you can either read .bin/activate and figure it out, or run something like bash -c "source ./bin/activate ; env" and it’ll list all the environment variables. You can then expand (not replace) the environment variables of the current environment with those of the other environment - either in bash or in python - up to you.


      As I said, dirty dirty and honestly I’d just install gunicorn in every venv then you’re done with it. But if you really want to, try what I explained and see how it works for you. It’s good to experiment and find out first hand.

      Anti Commercial-AI license