设置 virtualenvwrapper 以使用 Python 2.7.9

Setting up virtualenvwrapper to work with Python 2.7.9

由于工作原因,我不得不使用Python 2.7.9。在我的系统上,OS X Yosemite,我有版本 2.7.11。有一种方法可以通过 virtualenvwrapper 设置环境,以便使用特定版本的 Python?

您可以在同一个系统上拥有 python 的多个二进制文件。安装您需要的版本并使用此命令。

virtualenv -p {python binary location} {name of virtualenv}

virtualenvwrapper 命令 mkvirtualenvmkproject 都将接受 -p 参数并在创建虚拟环境时将其传递给 virtualenv

看看-p选项:

$ virtualenv --help
Usage: virtualenv [OPTIONS] DEST_DIR

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -v, --verbose         Increase verbosity.
  -q, --quiet           Decrease verbosity.
  -p PYTHON_EXE, --python=PYTHON_EXE
                        The Python interpreter to use, e.g.,
                        --python=python2.5 will use the python2.5 interpreter
                        to create the new environment.  The default is the
                        interpreter that virtualenv was installed with
                        (/usr/bin/python3.5)

您需要先在您的系统上安装Python 2.7.9。正如在另一个答案中所说,您可以在系统上并排安装多个 Python 版本。