Score:1

How to use pipenv to install 'global' applications to be run as services

nc flag

Cross-posted from Stack Overflow as it was possibly off-topic there.

I am trying to use pipenv to distribute a Python application to a server (in this case, it's Windows, but I have similar uncertainty with Linux).

I have previously done the following:

  1. Install system-wide Python
  2. pip install pipenv

Then pipenv install and pipenv run as normal. This has the advantage (I think) that any user or indeed a service user can run these commands. My aim is that the Python application will normally be run as a service (using nssm on Windows) but failing that can be run by any user without them having to install pipenv.

However, the official docs advise a user install to 'avoid breaking system packages' pip install --user pipenv or via pipx. In both cases, the result is that the pipenv binary ends up in a user folder which has to be added to the PATH unless you want to reference it using the full path. It feels wrong to have a service pointing at a binary in my personal folders, similarly other users would have to install their own pipenv or add my folders to their paths. This all seems very odd, but perhaps I've missed something. Is there something wrong with my approach? Is there a 'best practice' approach to using pipenv for deployment?

Some further confusion I've experimented with this a bit more and realized that even when pipenv is installed at a system level, the "virtualenvs" are created at a user level. However, I see this can be changed with an environment variable to put the "virtualenv" inside the project. Further, I have found that on Windows I can't get pipenv run to work from a service as it doesn't seem to activate the virtualenv. Instead, I had to create a batch file that activates the virtualenv and executes main.py, then point NSSM at that.

TLDR: I am looking for a deployment workflow using pipenv for Python software to be run as a service*. Ideally, I'd like this to be platform-independent, so I can use a similar workflow in Windows and Linux servers.

*On Windows I intend to use NSSM to run the service, on Linux systemd. I'm happy(ish) with these tools, it's pipenv that is confusing me.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.