Configuring Python

Python 2.7 and 3.4 on 64-Bit Windows

  1. Run Anaconda for Windows, Python 3.5, Windows 64-bit Graphical Installer from https://www.continuum.io/downloads.
    Note: During the installation process, you are prompted for the destination folder. These instructions assume that your Anaconda Python installation folder is 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
    Note: Intel Math Kernel Library (MKL) is incompatible with the SAS kernel. Installing nomkl instructs Anaconda to select a non-MKL dependent package version whenever Python packages are added to your environment. If you have a pre-existing environment that has MKL-dependent packages, follow the instructions at www.continuum.io for removing MKL and replacing the packages that have MKL dependencies before using SAS Micro Analytic Service.
  5. This step is for Python 3.4 only.
    Set environment variable PYTHONHOME, according to the location where Python is installed. Here is an example:
    set PYTHONHOME=C:\anaconda3
    Note: When enabling the SAS Web Application Server to use Python, disable the service and start the SAS Web Application Server in the foreground from a DOS command shell in which you have activated your Python environment. For example, after you have activated your Python environment in a DOS command shell as described in above, change your shell's present working directory to the server's bin directory and enter tcruntime-ctl run. You can stop the server using Control-C. The tcruntime-ctl.bat script is located in the SAS-configuration-directory/LevN/Web/WebAppServer/SASServer13_N/bin directory.

Python 2.7 and 3.4 on 64-Bit Linux

  1. Download Anaconda for Linux, Python 3.5, and Linux 64-bit installer from https://www.continuum.io/downloads.
  2. After downloading the installer, enter the following code in a terminal window. Provide the Python version that you installed. In the following example, Python 3.5 is used.
    bash Anaconda3-2.5.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 used the location /users/myuserid/anaconda3.
  3. Create a Python 3.4 environment by entering the following code (note that there are two hyphens before name). Provide the appropriate Python version.
    bash
    conda create --name python34 python=3.4 
    
  4. Before adding any other Python packages to your new, activated environment, first install the nomkl package.
    conda install nomkl
    Note: Intel Math Kernel Library (MKL) is incompatible with the SAS kernel. Installing nomkl instructs Anaconda to select a non-MKL dependent package version whenever Python packages are added to your environment. If you have a pre-existing environment that has MKL-dependent packages, follow the instructions at www.continuum.io for removing MKL and replacing the packages that have MKL dependencies before using SAS Micro Analytic Service.
  5. Activate the environment (provide the appropriate Python version).
    source activate python34
  6. 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%:}
    
Note: Regarding 64-bit Linux, the conda create and source activate commands must be run from a bash or zsh shell.
If you encounter a message at run-time, such as “Could not find platform independent libraries” and “Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]”, then set the PYTHONHOME environment variable. Here is an example:
export PYTHONHOME=$CONDA_PREFIX

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. However, you cannot do this with embedded Python. Therefore, it is recommended that you use the Python 3.5 installer for both Python 2.7 and 3.4.
When starting SAS Web Application Server, do so from a shell in which you have activated Python, thus enabling the process to use Python. For example, when starting the server using a script such as tcruntime-ctl.sh, do so from the shell in which you activated Python, as described above.
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.
Note: Make sure nomkl has been installed as the first package, as instructed in the previous sections.
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.
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 and 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