SciPy Recipes
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. Create the new environment with the following command:
conda create --name python27 python=2.7

conda will display information about the changes and ask for confirmation. Go ahead and enter yes to accept the environment creation.

  1. To activate the environment on Linux and macOS, use the following command:
source activate python27
  1. On Windows, the command to activate an environment is as follows:
activate python27
  1. Let's now test the new environment. Start Python in the usual way after activating the environment. Notice that in the startup message, it should state that version 2.7 of Python is being run. Now run the following statement in the Python prompt:
zip([['a','b'],[1,2]])
  1. This will produce the following output:
[('a', 1), ('b', 2)]
  1. This confirms that we are running Python 2, since in Python 3 the zip() function returns an iterator object instead of a list. To leave the Python shell, run the following in the Python prompt:
quit()
  1. When done with the environment, deactivate it by running the following command on Linux and macOS:
source deactivate python27
  1. On Windows, run the following:
deactivate python27