Skip to content

Commit dcad8d6

Browse files
committed
Merge branch 'master' of https://github.com/MicrosoftDocs/sql-docs-pr into 20180102_kubernetes
2 parents 908e665 + 0b01ad4 commit dcad8d6

36 files changed

Lines changed: 791 additions & 568 deletions

File tree

docs/advanced-analytics/TOC.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@
108108

109109
### [Install new R packages on SQL Server](r/install-additional-r-packages-on-sql-server.md)
110110

111+
### [Install new Python packages on SQL Server](python/install-additional-python-packages-on-sql-server.md)
112+
111113
### [Enable R package management for a SQL Server instance](r/r-package-how-to-enable-or-disable.md)
112114

113115
### [Determine which packages are installed on SQL Server](r/determine-which-packages-are-installed-on-sql-server.md)
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
title: "Install new Python packages on SQL Server | Microsoft Docs"
3+
ms.date: "01/04/2018"
4+
ms.reviewer:
5+
ms.suite: sql
6+
ms.prod: machine-learning-services
7+
ms.prod_service: machine-learning-services
8+
ms.component: python
9+
ms.technology:
10+
- "r-services"
11+
ms.tgt_pltfrm: ""
12+
ms.topic: "article"
13+
ms.assetid: 21456462-e58a-44c3-9d3a-68b4263575d7
14+
caps.latest.revision: 1
15+
author: "jeannt"
16+
ms.author: "jeannt"
17+
manager: "cgronlund"
18+
ms.workload: "On Demand"
19+
---
20+
# Install new Python packages on SQL Server
21+
22+
This article describes how to install new Python packages on an instance of SQL Server 2017.
23+
24+
It also describes how to list packages that are installed in the current environment.
25+
26+
## Prerequisites
27+
28+
The process for installing new packages is much like that in a standard Python environment. However, some additional steps are required if the server does not have an internet connection.
29+
30+
+ You must have installed Machine Learning Services (In-Database) with the Python language option. For instructions, see [Set up Python Machine Learning Services](setup-python-machine-learning-services.md).
31+
32+
+ For each server instance, you must install a separate copy of the package. Packages cannot be shared across instances.
33+
34+
+ Determine whether the package you intend to use will work with Python 3.5 and in the Windows environment.
35+
36+
In general, there are few limitations on the packages that you can import and use in the SQL Server environment. Possible problems include packages that use networking functionality that is blocked on the server or by the firewall, or packages with dependencies that cannot be installed on a Windows computer.
37+
38+
+ Administrative access to the server is required to install packages.
39+
40+
## Add a new Python package
41+
42+
For this example, we assume that you want to install a new package directly on the SQL Server computer.
43+
44+
The package installed in this example is [CNTK](https://docs.microsoft.com/cognitive-toolkit/), a framework for deep learning from Microsoft that supports customization, training, and sharing of different types of neural networks.
45+
46+
> [!TIP]
47+
> Need help configuring your Python tools? See these blogs:
48+
>
49+
> [Getting Started with Python Web Services using Machine Learning Server](https://blogs.msdn.microsoft.com/mlserver/2017/12/13/getting-started-with-python-web-services-using-machine-learning-server/)
50+
>
51+
> [David Crook: Microsoft Cognitive Toolkit + VS Code](http://dacrook.com/cntk-vs-code-awesome/)
52+
53+
### Step 1. Download the Windows version of the Python package
54+
55+
+ If you are installing Python packages on a server with no internet access, you must download the WHL file to a different computer and then copy it to the server.
56+
57+
For example, on a separate computer, you can download the WHL file from this site [https://cntk.ai/PythonWheel/CPU-Only](https://cntk.ai/PythonWheel/CPU-Only/cntk-2.1-cp35-cp35m-win_amd64.whl), and then copy the file `cntk-2.1-cp35-cp35m-win_amd64.whl` to a local folder on the SQL Server computer.
58+
59+
+ SQL Server 2017 uses Python 3.5. Be sure to get the Windows version of the package, and a version that is compatible with Python 3.5.
60+
61+
This page contains downloads for multiple platforms and for multiple Python versions: [Set up CNTK](https://docs.microsoft.com/cognitive-toolkit/Setup-CNTK-on-your-machine)
62+
63+
### Step 2. Open a Python command prompt
64+
65+
Locate the default Python library location used by SQL Server. If you have installed multiple instances, be sure to locate the PYTHON_SERVICE folder for the instance where you want to add the package.
66+
67+
For example, if Machine Learning Services has been installed using defaults, and machine learning is enabled on the default instance, the path would be as follows:
68+
69+
`C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES`
70+
71+
Open the Python command prompt associated with the instance.
72+
73+
> [!TIP]
74+
> We recommend that you set up a Python environment specific to Machine Learning Server or SQL Server.
75+
76+
### Step 3. Install the package using pip
77+
78+
+ If you are accustomed to using the Python command line, use PIP.exe to install new packages. You can find the **pip** installer in the `Scripts` subfolder.
79+
80+
If you get an error that **pip** is not recognized as an internal or external command, you can add the path of the Python executable and the Python scripts folder to the PATH variable in Windows.
81+
82+
The full path of the **Scripts** folder in a default installation is as follows:
83+
84+
`C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\Scripts`
85+
86+
+ If you are using Visual Studio 2017, or Visual Studio 2015 with the Python extensions, you can run `pip install` from the **Python Environments** window. Click **Packages**, and in the text box, provide the name or location of the package to install. You don't need to type `pip install`; it is filled in for you automatically.
87+
88+
- If the computer has Internet access, provide the name of the package, or the URL of a specific package and version. For example, to install the version of CNTK that is supported for Windows and Python 3.5, you coudl specify the download URL: `https://cntk.ai/PythonWheel/CPU-Only/cntk-2.1-cp35-cp35m-win_amd64.whl`
89+
90+
- If the computer does not have internet access, you should have downloaded the WHL file in advance. Then, specify the local file path and name. For example, paste the following path and file to install the WHL file downloaded from the site:
91+
`"C:\Downloads\CNTK\cntk-2.1-cp35-cp35m-win_amd64.whl"`
92+
93+
You might be prompted to elevate permissions to complete the install.
94+
95+
As installation progresses, you can see status messages in the command prompt window:
96+
97+
```python
98+
pip install https://cntk.ai/PythonWheel/CPU-Only/cntk-2.1-cp35-cp35m-win_amd64.whl
99+
Collecting cntk==2.1 from https://cntk.ai/PythonWheel/CPU-Only/cntk-2.1-cp35-cp35m-win_amd64.whl
100+
Downloading https://cntk.ai/PythonWheel/CPU-Only/cntk-2.1-cp35-cp35m-win_amd64.whl (34.1MB)
101+
100% |################################| 34.1MB 13kB/s
102+
...
103+
Installing collected packages: cntk
104+
Successfully installed cntk-2.1
105+
```
106+
107+
108+
109+
### Step 4. Load the package or its functions as part of your script
110+
111+
When installation is complete, you can immediately begin using the package as described in the next step.
112+
113+
For examples of deep learning using CNTK, see these tutorials: [Python API for CNTK](https://cntk.ai/pythondocs/tutorials.html)
114+
115+
To use functions from the package in your script, insert the standard `import <package_name>` statement in the initial lines of the script:
116+
117+
```python
118+
import numpy as np
119+
import cntk as cntk
120+
cntk._version_
121+
```
122+
123+
## How to view installed packages using conda
124+
125+
There are different ways that you can get a list of installed packages. For example, you can view the installed packages in the **Python Environments** windows of Visual Studio.
126+
127+
If you are using the Python command line, you can use the **conda** package manager, which is included with the Anaconda Python environment added by SQL Server setup.
128+
129+
To view Python packages that have been installed in the current environment, run this command from the command prompt windows:
130+
131+
```python
132+
conda list
133+
```
134+
135+
For more information about **conda** and how you can use it to create and manage multiple Python environments, see [Managing environments with conda](https://conda.io/docs/user-guide/tasks/manage-environments.html).

docs/advanced-analytics/r/create-a-local-package-repository-using-minicran.md

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Create a local package repository using miniCRAN | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "09/29/2017"
4+
ms.date: "01/04/2018"
55
ms.reviewer:
66
ms.suite: sql
77
ms.prod: machine-learning-services
@@ -30,7 +30,12 @@ There are two ways that you can prepare R packages for installation onto a serve
3030

3131
- [Manually download and copy packages one by one](#bkmk_manual)
3232

33-
This article describes how you can create an R package repository using both methods, and recommends use of the **miniCRAN** package.
33+
You can find the list of dependent packages in the DESCRIPTION file for the downloaded package.
34+
35+
However, packages listed in **Imports** might have second-level dependencies. For this reason, we recommend use of the **miniCRAN** method.
36+
37+
> [!TIP]
38+
> Did you know that you can use miniCRAN to prepare packages for use in Azure Machine Learning? For more information, see this blog: [Using miniCRAN in Azure ML, by Michele Usuelli](https://www.r-bloggers.com/using-minicran-in-azure-ml/)
3439
3540
## Prepare packages using miniCRAN
3641

@@ -48,6 +53,9 @@ There are many advantages to using miniCRAN to create the repository:
4853

4954
After creating the repository, you can modify it by adding new packages or upgrading the version of existing packages.
5055

56+
> [!NOTE]
57+
> The miniCRAN package itself is dependent on 18 other CRAN packages, among which is the RCurl package, which has a system dependency on the curl-devel package. Similarly, package XML has a dependency on libxml2-devel. We recommend, therefore, that you build your local repository initially on a machine with full Internet access, so that you can easily satisfy all these dependencies. After created, you can move the repository to a different location.
58+
5159
### Step 1. Install the miniCRAN package
5260

5361
You begin by creating a miniCRAN repository to use as a source. You should create this repository on a computer that has internet access.
@@ -67,9 +75,11 @@ You begin by creating a miniCRAN repository to use as a source. You should creat
6775
CRAN_mirror \<- c(CRAN = "https://mran.microsoft.com/snapshot/2017-08-01")
6876
```
6977

70-
2. Indicate a local folder in which to store the collected packages. You needn't name the folder miniCRAN; it could be a more descriptive name like "GeneticsPackages" or "ClientRPackages1.0.2".
78+
2. Type the name of a local folder in which to store the collected packages.
7179

72-
Just be sure to create the folder in advance. An error is raised if the `local_repo` folder does not exist when you run the R code later.
80+
Be sure to create the folder in advance. An error is raised if the `local_repo` folder does not exist when you run the R code later.
81+
82+
The folder should have a descriptive name. For example, avoid using "miniCRAN", and instead type something like "GeneticsPackages" or "TeamRPackages1.0.2".
7383

7484
```R
7585
local_repo <- "~/miniCRAN"
@@ -81,7 +91,7 @@ You begin by creating a miniCRAN repository to use as a source. You should creat
8191

8292
1. After miniCRAN is installed, create a list that specifies the additional packages you want to download.
8393

84-
Do not add dependencies to this initial list; the **igraph** package used by miniCRAN generates the list of dependencies for you. For more information about how to use this graph, see [Using miniCRAN to identify package
94+
Do not add dependencies to this initial list; the **igraph** package used by miniCRAN generates the list of dependencies for you. For more information about how to use the generated dependency graph, see [Using miniCRAN to identify package
8595
dependencies](https://cran.r-project.org/web/packages/miniCRAN/vignettes/miniCRAN-dependency-graph.html).
8696

8797
The following R script demonstrates how to get the target packages, "zoo"
@@ -90,7 +100,7 @@ You begin by creating a miniCRAN repository to use as a source. You should creat
90100
```R
91101
pkgs_needed <- c("zoo", "forecast")
92102
```
93-
2. Optionally, plot the dependency graph, which can be informative and looks cool.
103+
2. It is not required that you plot the dependency graph, but it can be informative.
94104

95105
```R
96106
plot(makeDepGraph(pkgs_needed))
@@ -122,15 +132,15 @@ After you have created the repository and added the packages you need, you must
122132

123133
Depending on the version of SQL Server, there are two options for adding new packages to the R library associated with the SQL Server instance:
124134

125-
- Install to the instance library using the miniCRAN repository and R tools.
135+
- Install to the instance library using the miniCRAN repository and R tools.
126136

127-
- Upload packages to a SQL database and install packages on a per-database basis, using the CREATE EXTERNAL LIBRARY statement. See [Install additional R packages on SQL Server](install-additional-r-packages-on-sql-server.md).
137+
- Upload packages to a SQL Server database and install using the CREATE EXTERNAL LIBRARY statement. This option requires SQL Server 2017. See [Install additional R packages on SQL Server](install-additional-r-packages-on-sql-server.md).
128138

129139
The following procedure describes how to install the packages using R tools.
130140

131-
1. Copy the folder containing the miniCRAN repository, in its entirety, to the server where you will install the packages.
141+
1. Copy the folder containing the miniCRAN repository, in its entirety, to the server where you plan to install the packages.
132142

133-
2. Open an R command prompt using the R tool associated with the instance.
143+
2. Open an R command prompt using the R tool associated with the instance.
134144

135145
- For SQL Server 2017, the default folder is `C:/Program Files/Microsoft SQL Server/MSSQL14.MSSQLSERVER/R_SERVICES/library`.
136146

@@ -140,58 +150,55 @@ The following procedure describes how to install the packages using R tools.
140150

141151
- If you have installed SQL Server to a different drive, or made any other changes in the installation path, be sure to make those changes as well.
142152

143-
3. Get the path for the instance library (in case you're in a user directory), and add it to the list of library paths.
153+
3. Get the path for the instance library, and add it to the list of library paths.
144154

145155
```R
146156
.libPaths()[1]
147157
lib \<- .libPaths()[1]
148158
```
149159

150-
This should return the instance path, "C:/Program Files/Microsoft SQL Server/MSSQL14.MSSQLSERVER/R_SERVICES/library "
160+
On SQL Server, this command should return the path of the library associated with the instance, such as: "C:/Program Files/Microsoft SQL Server/MSSQL14.MSSQLSERVER/R_SERVICES/library "
151161

152-
2. Specify the location on the server where you copied the mininCRAN repository in `server_repo`.
162+
4. Specify the location on the server where you copied the mininCRAN repository in `server_repo`.
153163

154164
In this example, we assume that you copied the repository to your user folder on the server.
155165

156166
```R
157167
R server_repo <- "C:\\Users\\MyUserName\\miniCRAN"
158168
```
159169

160-
3. Since you are working in a new R workspace on the server, you must also furnish the list of packages to install.
170+
5. Since you are working in a new R workspace on the server, you must also furnish the list of packages to install.
161171

162172
```R
163173
tspackages <- c("zoo", "forecast")
164174
```
165175

166-
4. Install the packages, using the path to the local copy of the miniCRAN repo.
176+
6. Install the packages, providing the path to the local copy of the miniCRAN repo.
167177

168178
```R
169179
install.packages(tspackages, repos = file.path("file://", normalizePath(server_repo, winslash = "/")), lib = lib, type = "win.binary", dependencies = TRUE)
170180
```
171181

172-
5. Now view the installed packages.
182+
7. From the instance library, you can view the installed packages using a command like the following:
173183

174184
```R
175185
installed.packages()
176186
```
177187

178188
> [!NOTE]
179-
>
180-
> In SQL Server 2017, additional database roles and T-SQL statements are provided to help server administrators manage permissions over packages. The database administrator can own the task of installing packages, using either R or T-SQL, if so desired. However, the DBA can also use roles to give users the ability to install their own packages. For more information, see [R package management for SQL Server](r-package-management-for-sql-server-r-services.md).
181-
>
182-
> In SQL Server 2016, a server administrator must install packages from the miniCRAN repository into the default library used by the instance. To do this, use the R tools as described in the [preceding section](#bkmk_Rtools).
189+
> In SQL Server, a server administrator must install packages from the miniCRAN repository into the default library used by the instance.
183190

184191
## Manually download single packages
185192

186193
If you do not want to use miniCRAN, you can also manually download the packages you need, and their dependencies. To do this requires that you are either an administrator or sole owner of a server.
187194

188195
After downloading the packages, you install the R packages from the zipped file location.
189196

190-
1. Download the packages zip files, and save them in a local folder
197+
1. Download the packages zip files, and save them in a local folder
191198

192-
2. Copy that folder to the [!INCLUDE[ssNoVersion_md](..\..\includes\ssnoversion-md.md)] computer.
199+
2. Copy that folder to the [!INCLUDE[ssNoVersion_md](..\..\includes\ssnoversion-md.md)] computer.
193200

194-
3. Install the packages into the SQL Server instance library.
201+
3. Install the packages into the SQL Server instance library.
195202

196203
> [!NOTE]
197204
> When you use R tools to install packages, they are installed for the instance as a whole.

0 commit comments

Comments
 (0)