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 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. 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, once 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, Linux 64-bit installer from https://www.continuum.io/downloads.
  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.5 is used.
    bash Anaconda3-2.5.0-Linux-x86_64.sh
    Answer yes to 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%:}
    
Note: Regarding 64-bit Linux, the conda create and source activate commands must be run from a bash or zsh shell.

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. This does not work 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 the SAS Web Application Server, do so from a shell, in which you have activated Python, thus allowing the server 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.
When you add packages to an Anaconda environment, the packages are placed in <your-environment-path>/lib/python3.4/site-packages. To make the Python scripts that use these packages work, 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_ENV_PATH when you activate an environment, and you can use CONDA_ENV_PATH when setting PYTHONPATH.
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_ENV_PATH/lib/python3.4/site-packages
export PYTHONPATH=.:$CONDA_ENV_PATH/lib/python3.4
export PYTHONPATH=$PYTHONPATH:$SITE_PACKAGES
export PYTHONPATH=$PYTHONPATH:$SITE_PACKAGES/numpy
export PYTHONPATH=$PYTHONPATH:$SITE_PACKAGES/numpy/lib