title: Caching virtual environment for gitlab-ci
body: <p>I cached Pip packages using a Gitlab CI script, so that's not an issue.</p>
  
  <p>Now I also want to catch a Conda virtual environment, because it reduces time to setup the environment.</p>
  
  <p>I cached a virtual environment. Unfortunately it takes a long time at the end to cache all the venv files.</p>
  
  <p>I tried to cache only the <code>$CI_PROJECT_DIR/myenv/lib/python3.6/site-packages</code> folder and it seems to reduce run time of the pipe.</p>
  
  <p>My question is: am I doing it correctly?</p>
  
  <p>The script is given below:</p>
  
  <p>gitlab-ci.yml</p>
  
  <pre><code>image: continuumio/miniconda3:latest
  
  cache:
    paths:
      - .pip
      - ls -l $CI_PROJECT_DIR/myvenv/lib/python3.6/site-packages
      - $CI_PROJECT_DIR/myvenv/lib/python3.6/site-packages
  
  before_script:
    - chmod +x gitlab-ci.sh
    - ./gitlab-ci.sh
  
  stages:
    - test
  
  test:
    stage: test
    script:
      - python eval.py
  </code></pre>
  
  <p>gitlab-ci.sh</p>
  
  <pre><code>#!/usr/bin/env bash
  ENV_NAME=myenv
  ENV_REQUIREMENTS=requirements.txt
  
  if [ ! -d $ENV_NAME ]; then
      echo "Environment $ENV_NAME does not exist. Creating it now!"
      conda create --path --prefix "$CI_PROJECT_DIR/$ENV_NAME"
  fi
  
  echo "Activating environment: $CI_PROJECT_DIR/$ENV_NAME"
  source activate "$CI_PROJECT_DIR/$ENV_NAME"
  
  echo "Installing PIP"
  conda install -y pip
  
  echo "PIP: installing required packages"
  echo `which pip`
  pip --cache-dir=.pip install -r "$ENV_REQUIREMENTS"
  </code></pre>