Configuring Python

Python 2.7 and 3.4 on 64-Bit Windows

  1. Download and run the latest Anaconda Graphical Installer for 64-bit Windows from https://www.continuum.io/downloads.
    Note: The Python 2.7 and 3.x installers include both version 2 and version 3 of Python. Regardless of which installer you download, you can create environments for both of the supported versions: 2.7 and 3.4.
    Note: During the installation process, you are prompted for the destination folder. These instructions assume you installed the folder in C:\Anaconda3.
  2. Create a Python environment by entering the following at a Windows command prompt (note that there are two hyphens before name). Provide the Python version that you installed. In the following example, Python 3.4 is used.
    conda create -name python34 python=3.4
  3. Activate the environment (providing the appropriate Python version).
    activate python34
  4. Before adding any other Python packages to your new, activated environment, first install the nomkl package.
    conda install nomkl
  5. When multiple distributions of Python are installed, Python often misjudges which environment or distribution you want to use. Therefore, it is recommended that you set the PYTHONHOME environment variable to the value of your environment's top-level directory. Here is an example:
    export PYTHONHOME=\users\myuserid\anaconda3\envs\python34

Python 2.7 and 3.4 on 64-Bit Linux

  1. Download and run the latest Anaconda Linux 64-bit installer from https://www.continuum.io/downloads.
    Note: The Python 2.7 and 3.x installers include both version 2 and version 3 of Python. Regardless of which installer you download, you can create environments for both of the supported versions: 2.7 and 3.4.
  2. After downloading the installer, enter the following in a terminal window. Provide the Python version that you installed. In the following example, Python 3.6 is used.
    bash Anaconda3-4.3.0-Linux-x86_64.sh
    Answer yes to the question, Do you wish the installer to prepend the Anaconda3 install location to PATH in your .bashrc? These instructions assume that you have used the location /users/myuserid/anaconda3.
  3. Create a Python 3.4 environment by entering the following (note that there are two hyphens before name). Provide the appropriate Python version.
    bash
    conda create --name python34 python=3.4 
    
  4. Activate the environment (provide the appropriate Python version).
    source activate python34
  5. Prepend the Python environment's lib directory to the LD_LIBRARY_PATH environment variable. Provide the Python version that you installed. In the following example, Python 3.4 is used.
    LD_LIBRARY_PATH=/users/myuserid/anaconda3/envs/python34/lib:${LD_LIBRARY_PATH}
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH%:}
    
  6. When multiple distributions of Python are installed, Python often misjudges which environment or distribution you want to use. Therefore, it is recommended that you set the PYTHONHOME environment variable to the value of your environment's top-level directory. Here is an example:
    export PYTHONHOME=/users/myuserid/anaconda3/envs/python34
Note: Regarding 64-bit Linux, the conda create and source activate commands must be run from a bash or zsh shell.
Python 2.x uses ASCII as the default encoding. Therefore, you must specify another encoding at the top of the file to use non-ASCII Unicode characters in literals. As a best practice, when using Python 2.x, always use the following as the first line of your Python script:
# -*- coding: utf-8 -*-
Also, in Python 2.x, the Unicode literal must be preceded by the letter u. Therefore, literal strings should be written using the following form:
u”xxxxx”
Note: Python 3.x uses UTF-8 as the default encoding. Therefore, these issues affect Python 2.x only. When using Python 3.x, you can use the default encoding, and you can simply enclose literals in quotation marks.

Further Considerations for Configuring Python

The Anaconda documentation states that Python 3.4 can be run from an Anaconda 2.7 installation by creating and activating a Python 3.4 environment. You cannot do this with embedded Python. Therefore, it is recommended that you use the Python 3.x installer for both Python 2.7 and 3.4.
When starting SAS Event Stream Processing, do so from a shell in which you have activated Python, thus allowing the process to use Python.
A rich set of Python packages is available, covering a wide variety of computing needs. You might want to add some of these packages to your Python environment.
When you add packages to an Anaconda environment, the packages are placed in <your-environment-path>/lib/python3.4/site-packages. In order to use the Python scripts that these packages require, add their locations to the PYTHONPATH environment variable.
Note: The use of the configuration scripts espenv and espenv_print, when running Python is highly recommended. These scripts are described in Configuration Helper Scripts.
If your Python script imports your own .py files, you also must add their location to PYTHONPATH. An example location might be .(dot).
Some packages include a lib directory, which also needs to be added to PYTHONPATH.
Finally, you must add <your-environment-path>/lib/python3.4 to PYTHONPATH.
Anaconda sets the environment variable CONDA_PREFIX when you activate an environment. It sets it to the location where Anaconda stores any new Python packages that you install (for example, the site-packages folder).
Here is an example of the locations that you might set for PYTHONPATH, after adding packages to your Python 3.4 environment for 64-bit Linux:
export SITE_PACKAGES=$CONDA_PREFIX/lib/python3.4/site-packages
export PYTHONPATH=.:$CONDA_PREFIX/lib/python3.4
export PYTHONPATH=$PYTHONPATH:$SITE_PACKAGES
export PYTHONPATH=$PYTHONPATH:$SITE_PACKAGES/numpy
export PYTHONPATH=$PYTHONPATH:$SITE_PACKAGES/numpy/lib
Last updated: March 2, 2017