Читать книгу SAS Viya - Kevin D. Smith - Страница 7

Оглавление

Chapter 1: Installing Python, SAS SWAT, and CAS

Installing Python

Installing SAS SWAT

Installing CAS

Making Your First Connection

Conclusion

There are three primary pieces of software that must be installed in order to use SAS Cloud Analytic Services (CAS) from Python:

● Python 2.7 if you use Python 2, or a minimum of Python 3.4 if you use Python 3

● the SAS SWAT Python package

● the CAS server

We cover the recommended ways to install each piece of software in this chapter.

Installing Python

The Python packages that are used to connect to CAS have a minimum requirement of Python 2.7. If you are using version 3 of Python, you need a minimum of Python 3.4. There are some significant differences between Python 2 and Python 3, which are only touched on in this book. We recommend that you conduct your own research about the two primary versions of Python and choose the version that is appropriate for your needs. If you are not familiar with Python or if you don’t have a version preference, we recommend that you use the most recent release of Python 3. If you have an installation of Python 2 that you are using for existing work, then you can continue to use it. The Python package that is used to connect to CAS is compatible with both Python 2 and Python 3.

If you plan to use Microsoft Windows as your client operating system, you might not have an existing Python installation. If you use the Linux operating system or the Macintosh operating system, you probably have a Python installation already. In either case, you might need to install some prerequisite packages. We recommend that you start with a Python distribution such as Anaconda from Continuum Analytics at www.continuum.io which contains all of the prerequisites.

The Anaconda Python distribution includes dozens of the most popular Python packages, which can be installed easily on Windows, Linux, and Macintosh platforms. It also enables you to install a complete Python installation at any location on your system, including your home directory, so that you don’t need administrator privileges. Even if you do have administrator privileges and you have an existing Python installation on the Linux or Macintosh platforms, installing Anaconda as a separate Python is a good idea in order to prevent any mishaps that might occur while installing packages in the existing Python installation.

After you have installed Python, the next step is to install the SWAT package.

Installing SAS SWAT

The SAS SWAT package is the Python package created by SAS which is used to connect to CAS. SWAT stands for SAS Scripting Wrapper for Analytics Transfer. It includes two interfaces to CAS: 1) natively compiled client for binary communication, and 2) a pure Python REST client for HTTP-based connections. Support for the different protocols varies based on the platform that is used. So, you’ll have to check the downloads on the GitHub project to find out what is available for your platform.

To install SWAT, you use the standard Python installation tool pip. On Linux and Macintosh, the pip command is in the bin directory of your Anaconda installation. On Windows, it is in the Scripts directory of the Anaconda distribution. The SWAT installers are located at GitHub in the python-swat project of the sassoftware account. The available releases are listed at the following link:

https://github.com/sassoftware/python-swat/releases

You can install SWAT directly from the download link using pip as follows.

pip install https://github.com/sassoftware/python-

swat/releases/download/vX.X.X/python-swat-X.X.X-platform.tar.gz

Where X.X.X is the version number, and platform is the platform that you are installing on. If your platform isn’t available, you can install using the source code URL on the releases page instead, but you are restricted to using the REST interface over HTTP or HTTPS. The source code release is pure Python, so it will run wherever Python and the prerequisite packages are supported.

Note that if you have both Python 2 and Python 3 installed on your system (or even multiple installations of a particular Python version), you need to be careful to run the pip command from the installation where SWAT is installed. In any case, the same SWAT package works for both Python 2 and Python 3.

After SWAT is installed, you should be able to run the following command in Python in order to load the SWAT package:

>>> import swat

With Anaconda, you can submit the preceding code in several ways. You can use the python command at the command line. However, if you are going to use the command line, we’d recommend that you at least use the ipython command, which is preferred for interactive use. You also have the option of using the Spyder IDE that comes bundled with Anaconda. The Spyder IDE is useful for debugging as well as for development and interactive use. You can also use the popular Jupyter notebook, which was previously known as the IPython notebook. Jupyter is most commonly used within a web browser. It can be launched with the jupyter notebook command at the command line, or you can launch it from the Anaconda Launcher application.

In this book, we primarily show plain text output using the IPython interpreter. However, all of the code from this book is also available in the form of Jupyter notebooks here,

https://github.com/sassoftware/sas-viya-the-python-perspective

Now that we have installed Python and SWAT, the last thing we need is a CAS server.

Installing CAS

The installation of CAS is beyond the scope of this book. Installation on your own server requires a CAS software license and system administrator privileges. You need to contact your system administrator about installing, configuring, and running CAS.

Making Your First Connection

With all of the pieces in place, we can make a test connection just to verify that everything is working. From Python, you should be able to run the following commands:

>>> import swat

>>> conn = swat.CAS('server-name.mycompany.com', port-number,

'userid', 'password')

>>> conn.serverstatus()

>>> conn.close()

Where server-name.mycompany.com is the name or IP address of your CAS server, port-number is the port number that CAS is listening to, userid is your CAS user ID, and password is your CAS password. The serverstatus method should return information about the CAS grid that you are connected to, and the close method closes the connection. If the commands run successfully, then you are ready to move on. If not, you’ll have to do some troubleshooting before you continue.

Conclusion

At this point, you should have Python and the SWAT package installed, and you should have a running CAS server. In the next chapter, we’ll give a brief summary of what it’s like to use CAS from Python. Then, we’ll dig into the chapters that go into the details of each aspect of SWAT.

SAS Viya

Подняться наверх