Getting syntax error while using virtualenv package in Ubuntu 16.04

Question:

I am running Ubuntu 16.04 in VMware virtual environment. When I try to install virtualenv, I am facing issues.

What I did:

sudo apt install python3-pip

sudo pip3 install virtualenv

virtualenv --version

The last command is showing this:

Traceback (most recent call last):
  File "/home/sbedanabett/.local/bin/virtualenv", line 7, in <module>
    from virtualenv.__main__ import run_with_catch
  File "/home/sbedanabett/.local/lib/python3.5/site-packages/virtualenv/__init__.py", line 1, in <module>
    from .run import cli_run, session_via_cli
  File "/home/sbedanabett/.local/lib/python3.5/site-packages/virtualenv/run/__init__.py", line 70
    raise RuntimeError(f"failed to find interpreter for {discover}")
                                                                  ^
SyntaxError: invalid syntax

This seems because it is using Python2 interpreter. But I have changed my default interpreter to be Python3, following this question. So I am clueless why this error.

$ python --version
Python 3.5.2
$ python2 --version
Python 2.7.12
Asked By: Sourav Kannantha B

||

Answers:

To install an older version of virtualenv you try this command

For example to install 16.7.9

pip install https://github.com/pypa/virtualenv/tarball/16.7.9

To install in local

pip install --user https://github.com/pypa/virtualenv/tarball/16.7.9

and while running the command line for virtualenv use python -m

Example

python -m virtualenv --version
Answered By: Dickens A S