1 year ago

#355725

test-img

David Poundall

Running a python environment and python code in that env from a bash shell script

I am trying to create a @reboot entry in in a cron file to run a bash script to initialise a python virtual environment and following that run my python programs. Before I can do that I need to be able to do this from a bash script. My knowledge of scripting is not great, however, you have to soldier on.

I create the environment for my python programs on a day to day basis by navigating to my project folder and typing.

cd ~/project_folder
pipenv shell

The shell is running and within it I can invoke my python scripts from the cli. In trying to automate this I tried the following in a .sh file.

#! /usr/bin/bash
cd ~/project_file
pipenv shell 

When I ran the .sh script it worked, however any cli code I try following the 'pipenv shell' line is not run because the bash script is waiting for the environment to drop. But if the environment drops I can't run the python scripts.

There is more that I am aiming to do with the scripting but this is the first hurdle I am having difficulty getting over. Sadly, I have been on this all day and so I am now shouting out for a leg up. If anyone could point me in the right direction I would be much obliged.

python

shell

ubuntu

environment

pipenv

0 Answers

Your Answer

Accepted video resources