# Wrong Python version invoked when using \`alias\`

**URL:** <https://travis-ci.community/t/wrong-python-version-invoked-when-using-alias/10059>\
**Category:** macOS\
**Tags:** build-env, python\
**Created:** [October 1, 2020, 1:36pm UTC](https://travis-ci.community/t/wrong-python-version-invoked-when-using-alias/10059 "2020-10-01T13:36:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaoyu2006](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/xiaoyu2006/32/5258_2.png) [@xiaoyu2006](https://travis-ci.community/u/xiaoyu2006)\
**Post date:** [October 1, 2020, 1:36pm UTC](https://travis-ci.community/t/wrong-python-version-invoked-when-using-alias/10059/1 "2020-10-01T13:36:34Z")

</div>

My build config is like this:

```auto
language: python

dist: bionic

os:
  - linux

python:
  - "2.7"
  - "3.5"
  - "3.6"
  - "3.7"
  - "3.8"
  - "3.8-dev"
  - "nightly"
  - "pypy3"

jobs:
    - name: "Python 3.7 on macOS"
      os: osx
      osx_image: xcode11.2
      language: shell
      before_install:
        - alias python='python3'
  allow_failures:
    - python: "3.8-dev"
    - python: "nightly"

install:
  # Upgrade pip
  - python -m pip install --upgrade pip

script:
  - python --version
  - python setup.py install
  - python setup.py test

```

As you can see, I have a project and it is tested with `pytest`. Everything goes well until my `osx` build. (The build didn’t even fail on the `Python2.7 Bionic Ubuntu` environment.)

The special configuration of `osx` is pasted and modified from the [documentation](https://docs.travis-ci.com/user/languages/python/#running-python-tests-on-multiple-operating-systems). But python failed to install my `pytest` framework on the `python setup.py install` sentence.

The error goes like:

```auto
Searching for pytest
Reading https://pypi.org/simple/pytest/
Downloading https://files.pythonhosted.org/packages/d4/d1/61dbeb5e6d6a694c4d024043ad67a01ba236c54d253558b3019b6fac2c68/pytest-6.1.0.tar.gz#sha256=d010e24666435b39a4cf48740b039885642b6c273a3f77be3e7e03554d2806b7
Best match: pytest 6.1.0
Processing pytest-6.1.0.tar.gz
Writing /var/folders/17/5mc7816d3mndxjqgplq6057w0000gn/T/easy_install-jhPaOa/pytest-6.1.0/setup.cfg
Running pytest-6.1.0/setup.py -q bdist_egg --dist-dir /var/folders/17/5mc7816d3mndxjqgplq6057w0000gn/T/easy_install-jhPaOa/pytest-6.1.0/egg-dist-tmp-4xoTGJ
  File "build/bdist.macosx-10.14-x86_64/egg/pytest/collect.py", line 24
    def __init__ (self) -> None:
                       ^
SyntaxError: invalid syntax

```

PS: The dependencies are declared in `setuptools.setup(tests_require=[...])`.  
PS2: The `python --version` shows that `python2` is still actually executed.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [October 2, 2020, 1:22am UTC](https://travis-ci.community/t/wrong-python-version-invoked-when-using-alias/10059/2 "2020-10-02T01:22:57Z")

</div>

As you can see, the problem is your `alias` has no effect for some reason. I’d need to see the build to understand why exactly, but why not do smth like this instead?

```auto
before_install:
  - python3 -m pip install virtualenv
  - python3 -m virtualenv v
  - source v/bin/activate

```

This will make `python` point to virtualenv like in Linux with `language: python`.

---

<div class="post-metadata">

**Author:** ![xiaoyu2006](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/xiaoyu2006/32/5258_2.png) [@xiaoyu2006](https://travis-ci.community/u/xiaoyu2006)\
**Post date:** [October 2, 2020, 6:28am UTC](https://travis-ci.community/t/wrong-python-version-invoked-when-using-alias/10059/3 "2020-10-02T06:28:21Z")

</div>

@native-api It errored again:

```auto
$ python3 -m virtualenv v
/usr/local/opt/python/bin/python3.7: No module named virtualenv
The command "python3 -m virtualenv v" failed and exited with 1 during .

```

Maybe I should try tox.

PS: [raw log](https://api.travis-ci.com/v3/job/394047009/log.txt).

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [October 2, 2020, 12:24pm UTC](https://travis-ci.community/t/wrong-python-version-invoked-when-using-alias/10059/4 "2020-10-02T12:24:43Z")

</div>

> [@xiaoyu2006](#):
>
> `/usr/local/opt/python/bin/python3.7: No module named virtualenv`

Then you need to install it first. I thought it was preinstalled.

---

<div class="post-metadata">

**Author:** ![xiaoyu2006](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/xiaoyu2006/32/5258_2.png) [@xiaoyu2006](https://travis-ci.community/u/xiaoyu2006)\
**Post date:** [October 3, 2020, 8:29am UTC](https://travis-ci.community/t/wrong-python-version-invoked-when-using-alias/10059/5 "2020-10-03T08:29:29Z")

</div>

This is creepy. Your (@native-api ) PR does not work.  
And this is more creepy: [https://travis-ci.com/github/proj-cfpm/cfpm/jobs/394532440](https://travis-ci.com/github/proj-cfpm/cfpm/jobs/394532440).

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [October 3, 2020, 8:08pm UTC](https://travis-ci.community/t/wrong-python-version-invoked-when-using-alias/10059/6 "2020-10-03T20:08:35Z")

</div>

No idea what you are talking about with “PR”. I forked your repo to see why `alias` has no effect.

---

<div class="post-metadata">

**Author:** ![xiaoyu2006](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/xiaoyu2006/32/5258_2.png) [@xiaoyu2006](https://travis-ci.community/u/xiaoyu2006)\
**Post date:** [October 4, 2020, 8:29am UTC](https://travis-ci.community/t/wrong-python-version-invoked-when-using-alias/10059/7 "2020-10-04T08:29:35Z")

</div>

Mistake. Sorry.  
Actually, this configuration works: [https://travis-ci.com/github/proj-cfpm/cfpm/jobs/394777541](https://travis-ci.com/github/proj-cfpm/cfpm/jobs/394777541).

But I still wonder why `alias` doesn’t work.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [October 5, 2020, 3:05am UTC](https://travis-ci.community/t/wrong-python-version-invoked-when-using-alias/10059/8 "2020-10-05T03:05:29Z")

</div>

> **[bash(1): GNU Bourne-Again SHell - Linux man page](https://linux.die.net/man/1/bash)**
>
> Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file.

> Aliases are not expanded when the shell is not interactive, unless the expand\_aliases shell option is set using shopt
