Install python module from within script

5853
11
Jump to solution
06-06-2016 02:50 AM
AnthonyCheesman1
Occasional Contributor II

I've got a small project that I'm working on that requires installation of the dropbox Python library, as the script needs to a write files to it.

Ideally I'm going to deploy this to a number of users either via a toolbox or a Python add-in.

The catch is that dropbox is not a standard module, and at Python 2.7.5, pip (which I would normally use to install new module) is not a standard module either.

What I'm wondering is:

1/ how would I programatically go about installing a new module from inside a running script; or

2/ is there a way I can bundle the module either into my code, or as part of my code package ('bundle of files') so that the script can find and install the missing module?

3/ I posted a similar question on Reddit and it was suggested that I look at 'freezing' my code (effectively convert to an .exe) - but I'm unsure whether this will allow the script to interact with the toolbox to access parameters etc. Would compiling the code to a .pyc allow this to work?

Any and all help gratefully received!

0 Kudos
11 Replies
AnthonyCheesman1
Occasional Contributor II

I think for portability and ease of use, I prefer the add-in option. The ability to deploy and install a single .addin file beats the pants off trying to manage the location of multiple files (especially when multiple users of varying technical abilities are involved). Add-in gives the option of the tool being run disconnected from our internal network as well.

If I'm really smart, I can add it as an additional tool to a python .addin toolbar I'm already using.

Could be a good tinkering job for this weekend.

0 Kudos
AnthonyCheesman1
Occasional Contributor II

For those still interested in this - Dropbox has now upgraded it's API to v2. This has meant updating the module install (no problems there).