Pip path? jinja2 was not found in your path!

How do you install pip packages? I think I’ve gone through all the flags for pip with zero success

matrix:
  include:
    - os: linux
      dist: trusty
      sudo: required
      services:
      - docker

#language: node_js
#node_js:
#  - "8"
language: python
python:
    - "3.6"

before_install:
# install nsenter which is required for port forwarding
#- sudo -H pip3 install --upgrade --ignore-installed --user --install-option="--prefix=$HELM_INSTALL_DIR" jinja2
#- sudo -H pip3 install --upgrade --ignore-installed --user jinja2
#- pip install jinja2
- pip install --upgrade --ignore-installed --install-option="--prefix=$HELM_INSTALL_DIR" jinja2

script:
  - export PATH=/home/travis/.local/bin:$PATH
  - echo "export PATH=/home/travis/.local/bin:$PATH" >> /home/travis/.bashrc
  - env
  - which jinja2

Just pip install should be fine. Travis CI creates and activates a virtualenv before execution of your steps.

Another question would be is jinja2 shipped with a script now? Never heard of it…

ah you are correct, I was looking for jinja2-cli! My mistake entirely.

I will add that I had to add the --user or the prefix, or use sudo

It is strongly discouraged to use sudo. You’ll mess up your system python installation this way.

So do use --user but not if you specified language: python

matrix:
  include:
    - os: linux
      dist: trusty
      sudo: required
      services:
      - docker

language: python
python:
    - "3.6"

before_install:
- pip install --user jinja2-cli

script:
  - which jinja2

results in:

pip install --user jinja2-cli
Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
The command "pip install --user jinja2-cli" failed and exited with 1 during .

however if you use something else like node:

matrix:
  include:
    - os: linux
      dist: trusty
      sudo: required

language: node_js
node_js:
  - "8"

before_install:
- pip install --user jinja2-cli

script:
  - which jinja2

so use sudo only if you want to break your system python in this ephemeral system that is about to be deleted, don’t use --user with pip if your language is speciffied as python, but feel free elsewhere.

I’m glad this is perfectly clear :wink:

1 Like

In case you’re still wondering why:

  • Python installations have 2 “site packages”, locations where they install packages. The default one and the user one.
  • When you specify the python language Travis sets up what’s known as a virtual environment. Since those are isolated environments they have their own site packages but they have just the default one, which is why --user will fail. (You’re already specifying an environment by being inside a virtualenv, --user is conceptually n/a here)
  • When you don’t specify a python language you’re installing the packages to the system pythons which do have a user site packages

Never use sudo to pip install though:

  • You expose yourself to arbitrary code execution through a variety of package manager attacks
  • The installed files might not be readable to your regular user
  • You might overwrite packages that your system python relied on and mess up your linux distro

If you don’t know which situation you’re in you could alwys try a user install and if it errors chain it to a normal install:

pip install … --user || pip install …