warvariuc
warvariuc

Reputation: 59674

Fully isolated Python environment

Right now I am using virtualenv for my applications deployed in production.

I am running my apps like

cd $PROJECT_DIR
venv/bin/gunicorn -c gunicorn.conf.py my_app.wsgi:application

or

cd $PROJECT_DIR
venv/bin/celery worker --app=my_app.celery_tasks

Recently we have migrated to Python 3. The most recent Python 3.6 wasn't available for Ubuntu 14.04, so I compiled it by myself. Compiling it also allows me to benefit from optimizations using ./configure --enable-optimizations.

So I am thinking about always compiling Python by myself in my deployments. But at the same time keeping virtualenv file structure, so that the commands I am using for running apps in my virtual environment would remain the same.

I've seen people recommending using pyenv, but what I don't like about it is that it stores the Python itself in ~/.penv and, apparently, I need to fiddle with PATH environment variables to make my commands work in Cron and shell scripts, which I don't like. I'd like to keep all my environment in one directory if possible.

So my question is, can I somehow compile Python into venv directory in my project directory, so that the directory structure would be the same as when using virtualenv? Like:

$PROJECT_DIR/
    my_app/
    venv/
        bin/
            python
            python3.6
            celery
            gunicorn
            ...
        lib/
            python3.6/
                site-packages/
                    celery/
                    gunicorn/
                    ...

Upvotes: 2

Views: 1290

Answers (1)

Harald Nordgren
Harald Nordgren

Reputation: 12409

You can specify Python binary when creating the virutalenv:

virtualenv env -p /path/to/compiled/python3.6

Upvotes: 2

Related Questions