Bug 1560193 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

Attempting to run `./mach browsertime` with a global installation of node will fail:

```
0:00.40 /usr/bin/nodejs /home/barret/Workspace/src/hg.mozilla.org/mozilla-central/tools/browsertime/node_modules/browsertime/bin/browsertime.js --skipHar --visualMetrics https://google.com/search?q=firefox -b firefox --firefox.binaryPath /home/barret/.local/opt/firefox-nightly/firefox --video
[2019-06-18 15:38:37] INFO: Running tests using Firefox - 3 iteration(s)
[2019-06-18 15:38:38] INFO: Testing url https://google.com/search?q=firefox iteration 1
[2019-06-18 15:38:49] ERROR: Visual Metrics failed to analyse the video Error: Command failed: python /home/barret/Workspace/src/hg.mozilla.org/mozilla-central/tools/browsertime/node_modules/browsertime/vendor/visualmetrics.py --dir /home/barret/Workspace/src/hg.mozilla.org/mozilla-central/browsertime-results/google.com-search-query-d943c9da/2019-06-18T153836-0700/pages/google.com/search/query-d943c9da/data/video/images/1 --video /home/barret/Workspace/src/hg.mozilla.org/mozilla-central/browsertime-results/google.com-search-query-d943c9da/2019-06-18T153836-0700/pages/google.com/search/query-d943c9da/data/video/1.mp4 --orange --perceptual --contentful --force --renderignore 5 --json --viewport -q 75




    at makeError (/home/barret/Workspace/src/hg.mozilla.org/mozilla-central/tools/browsertime/node_modules/browsertime/node_modules/execa/index.js:174:9)
    at /home/barret/Workspace/src/hg.mozilla.org/mozilla-central/tools/browsertime/node_modules/browsertime/node_modules/execa/index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
[2019-06-18 15:38:49] INFO: https://google.com/search?q=firefox BackEndTime: 358 DomInteractiveTime: 1237 DomContentLoadedTime: 1237 FirstPaint: 433 PageLoadTime: 3757
```

As it turns out, the global installation of python ends up being used instead of the python in the virtual environment generated in the mozilla-central checkout. This happens because to [execa](https://github.com/sindresorhus/execa), the library that browsertime uses to execute processes, prepends the directory that node is in to your `PATH `environment variable, which when node is installed globally, is `/usr/bin`. Thus `/usr/bin/python` will be executed to run browsertime's `visualmetrics.py` instead of the virtualenv wrapped python which will fail if you do not have all the python dependencies installed globally.

We already have support in our fork of browsertime for specifying which python to use (via the `PYTHON` environment variable), so we can manually set this to the path of the python executable in the virtualenv.
Attempting to run `./mach browsertime` with a global installation of node will fail:

```
0:00.40 /usr/bin/nodejs /home/barret/Workspace/src/hg.mozilla.org/mozilla-central/tools/browsertime/node_modules/browsertime/bin/browsertime.js --skipHar --visualMetrics https://google.com/search?q=firefox -b firefox --firefox.binaryPath /home/barret/.local/opt/firefox-nightly/firefox --video
[2019-06-18 15:38:37] INFO: Running tests using Firefox - 3 iteration(s)
[2019-06-18 15:38:38] INFO: Testing url https://google.com/search?q=firefox iteration 1
[2019-06-18 15:38:49] ERROR: Visual Metrics failed to analyse the video Error: Command failed: python /home/barret/Workspace/src/hg.mozilla.org/mozilla-central/tools/browsertime/node_modules/browsertime/vendor/visualmetrics.py --dir /home/barret/Workspace/src/hg.mozilla.org/mozilla-central/browsertime-results/google.com-search-query-d943c9da/2019-06-18T153836-0700/pages/google.com/search/query-d943c9da/data/video/images/1 --video /home/barret/Workspace/src/hg.mozilla.org/mozilla-central/browsertime-results/google.com-search-query-d943c9da/2019-06-18T153836-0700/pages/google.com/search/query-d943c9da/data/video/1.mp4 --orange --perceptual --contentful --force --renderignore 5 --json --viewport -q 75




    at makeError (/home/barret/Workspace/src/hg.mozilla.org/mozilla-central/tools/browsertime/node_modules/browsertime/node_modules/execa/index.js:174:9)
    at /home/barret/Workspace/src/hg.mozilla.org/mozilla-central/tools/browsertime/node_modules/browsertime/node_modules/execa/index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
[2019-06-18 15:38:49] INFO: https://google.com/search?q=firefox BackEndTime: 358 DomInteractiveTime: 1237 DomContentLoadedTime: 1237 FirstPaint: 433 PageLoadTime: 3757
```

As it turns out, the global installation of python ends up being used instead of the python in the virtual environment generated in the mozilla-central checkout. This happens because to [execa](https://github.com/sindresorhus/execa), the library that browsertime uses to execute processes, [prepends the directory that node is in to your `PATH `environment variable](https://github.com/sindresorhus/execa/issues/153), which when node is installed globally, is `/usr/bin`. Thus `/usr/bin/python` will be executed to run browsertime's `visualmetrics.py` instead of the virtualenv wrapped python which will fail if you do not have all the python dependencies installed globally.

We already have support in our fork of browsertime for specifying which python to use (via the `PYTHON` environment variable), so we can manually set this to the path of the python executable in the virtualenv.

Back to Bug 1560193 Comment 0