Python libraries in deployment

787
4
Jump to solution
10-28-2012 07:23 PM
Labels (1)
MatthewBrown1
Occasional Contributor
Hi,

I am considering using a Python library to replace the Pivot tool in a geoprocessing model. Are there any considerations for deployment? Can I just drop the library in the deployment folder?

I can accomplish my goal with a for loop, would this be a better fit for the Runtime SDK?

Thanks,

Matt
0 Kudos
1 Solution

Accepted Solutions
KevinHibma
Esri Regular Contributor
Matt,

I just built a little sample to test this and it works.

I downloaded the 3rd party module, "xlrd" which allows you to read Excel files. My script tool does a simple "import xlrd" and simply reads the rows. To use this package in Desktop, it was installed into my Python27 directory at:
C:\Python27\ArcGIS10.1\Lib\site-packages\xlrd

As you've pointed out, 3rd party modules are not consolidated/included in the package (GPK).

When I first attempt to run my program using the GPK I created, I get a message back from the service that "no such module exists" when trying to import xlrd. (somewhat expected because this module isn't installed in the Runtime's Python)

To remedy this I took the xlrd directory from my Python27 site-packages and copied it into the Runtime's Python directory at:
C:\Program Files (x86)\ArcGIS SDKs\WPF1.0\ArcGISRuntime1.0\LocalServer32\Python\Lib\site-packages
I was then successfully able to run my service.

When building your deployment you'll have to manually include additional modules.
Note that if you're doing both a 32/64 deployment you'll have to get both modules and include them in your deployment.

So in short, with these 3rd party Python modules used in the Runtime - its just the manual step of copy/pasting them into the Runtime's Python during development and making sure to copy/paste them into your deployment.

View solution in original post

0 Kudos
4 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

There's a help article in the Desktop help which covers including Python libraries within your GP packages: http://resources.arcgis.com/en/help/main/10.1/index.html#/Packaging_Python_scripts/0057000000mn00000....

Cheers

Mike
0 Kudos
MatthewBrown1
Occasional Contributor
Hi,

There's a help article in the Desktop help which covers including Python libraries within your GP packages: http://resources.arcgis.com/en/help/main/10.1/index.html#/Packaging_Python_scripts/0057000000mn00000....

Cheers

Mike


Thanks Mike, I found this:


[INDENT]Third-party modules (any module that is not part of the core Python installation) are not consolidated. You need to ensure the module is installed on the machine where the packaged is unpacked. You should provide documentation for your tool and package that specifies what third-party modules are required. This does not apply to the numpy or matplotlib modules which are installed with ArcGIS for Desktop.[/INDENT]


So, not in \ArcGISRuntime1.0\LocalServer32\python\lib\site-packages? (I could install from source to this directory after creation.) The help article is a bit vague on HOW to "ensure the module is installed on the machine where the packaged is unpacked". What happens if the user doesn't have ArcGIS Desktop or Python installed locally? Doesn't seem like it will work when deploying Runtime SDK apps from a flash drive.
0 Kudos
KevinHibma
Esri Regular Contributor
Matt,

I just built a little sample to test this and it works.

I downloaded the 3rd party module, "xlrd" which allows you to read Excel files. My script tool does a simple "import xlrd" and simply reads the rows. To use this package in Desktop, it was installed into my Python27 directory at:
C:\Python27\ArcGIS10.1\Lib\site-packages\xlrd

As you've pointed out, 3rd party modules are not consolidated/included in the package (GPK).

When I first attempt to run my program using the GPK I created, I get a message back from the service that "no such module exists" when trying to import xlrd. (somewhat expected because this module isn't installed in the Runtime's Python)

To remedy this I took the xlrd directory from my Python27 site-packages and copied it into the Runtime's Python directory at:
C:\Program Files (x86)\ArcGIS SDKs\WPF1.0\ArcGISRuntime1.0\LocalServer32\Python\Lib\site-packages
I was then successfully able to run my service.

When building your deployment you'll have to manually include additional modules.
Note that if you're doing both a 32/64 deployment you'll have to get both modules and include them in your deployment.

So in short, with these 3rd party Python modules used in the Runtime - its just the manual step of copy/pasting them into the Runtime's Python during development and making sure to copy/paste them into your deployment.
0 Kudos
MatthewBrown1
Occasional Contributor
Hi Kevin,

Thanks for that info - looks promising. I will test out my gpk (which uses pandas) in the next couple of days using a deployment on a USB drive.
0 Kudos