Search code examples
bashpipenv

source not found for source $(pipenv --venv)/bin/activate


I'm trying to learn how to use pipenv, and while I can start it and use it from the shell, I can't work out how to open in from a script, the tutorial I am using says to write the following file:

#!/bin/sh

export FLASK_APP=./myapp/index.py

source $(pipenv --venv)/bin/activate

flask run -h 0.0.0.0

as a shell script, but I get the following error:

./bootstrap.sh: 5: source: not found
* Serving Flask app "./catalogueService/index.py"
* Environment: production
  WARNING: This is a development server. Do not use it in a production deployment.
  Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]

Error: Could not import "index".

The could not import index, is fine, I can work with that, what I don't know is what:

source $(pipenv --venv)/bin/activate

Does, and what it should really be so it can find pipenv, I installed it using pip the usual way. Why is it not finding it please


Solution

  • On Linux or macOS:

    source "$(pipenv --venv)/bin/activate"
    

    On Windows:

    source "$(pipenv --venv)/Scripts/activate"
    

    OR

    activate(){
        activate_file=$(pipenv --venv)/bin/activate
        if [ -e "$activate_file" ]; then
            . $activate_file
    
            # the pipenv shell normally enables these as well
            export PYTHONDONTWRITEBYTECODE=1
            export PIPENV_ACTIVE=1
    
            if [ -f "${VIRTUAL_ENV}/.project" ]; then
                cd $(cat "${VIRTUAL_ENV}/.project")
            fi
            return
        fi
    }