def install(plugin_package, plugins_directory, server_url=DEFAULT_SERVER_URL):
import pip_helpers<EOL>if path(plugin_package).isfile():<EOL><INDENT>plugin_is_file = True<EOL>with open(plugin_package, '<STR_LIT:rb>') as plugin_file:<EOL><INDENT>plugin_file_metadata = extract_metadata(plugin_file)<EOL><DEDENT>name = plugin_file_metadata['<STR_LIT>']<EOL>version = plugin_file_metadata['<STR_LIT:version>']<EOL><DEDENT>else:<EOL><INDENT>plugin_is_file = False<EOL>try:<EOL><INDENT>name, releases = pip_helpers.get_releases(plugin_package,<EOL>server_url=server_url)<EOL>version, release = list(releases.items())[-<NUM_LIT:1>]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>plugin_path = plugins_directory.joinpath(name)<EOL>if not plugin_path.isdir():<EOL><INDENT>existing_version = None<EOL><DEDENT>else:<EOL><INDENT>plugin_metadata = yaml.load(plugin_path.joinpath('<STR_LIT>')<EOL>.bytes())<EOL>existing_version = plugin_metadata['<STR_LIT:version>']<EOL><DEDENT>if version == existing_version:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(name,<EOL>version))<EOL><DEDENT>if existing_version is not None:<EOL><INDENT>uninstall(name, plugins_directory)<EOL><DEDENT>print('<STR_LIT>'.format(name, version))<EOL>if not plugin_is_file:<EOL><INDENT>download = requests.get(release['<STR_LIT:url>'], stream=True)<EOL>plugin_archive_bytes = StringIO.StringIO()<EOL>total_bytes = int(download.headers['<STR_LIT>'])<EOL>bytes_read = <NUM_LIT:0><EOL>with progressbar.ProgressBar(max_value=total_bytes) as bar:<EOL><INDENT>while bytes_read < total_bytes:<EOL><INDENT>chunk_i = download.raw.read(<NUM_LIT:1> << <NUM_LIT:8>)<EOL>bytes_read += len(chunk_i)<EOL>plugin_archive_bytes.write(chunk_i)<EOL>bar.update(bytes_read)<EOL><DEDENT><DEDENT>plugin_archive_bytes.seek(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>plugin_archive_bytes = open(plugin_package, '<STR_LIT:rb>')<EOL><DEDENT>plugin_path, plugin_metadata = install_fileobj(plugin_archive_bytes,<EOL>plugin_path)<EOL>assert(all([plugin_metadata['<STR_LIT>'] == name,<EOL>plugin_metadata['<STR_LIT:version>'] == version]))<EOL>print('<STR_LIT>')<EOL>plugin_archive_bytes.close()<EOL>return plugin_path, plugin_metadata<EOL>
Parameters
----------
plugin_package : str
    Name of plugin package hosted on MicroDrop plugin index. Version
    constraints are also supported (e.g., ``"foo", "foo==1.0",
    "foo>=1.0"``, etc.)  See `version specifiers`_ reference for more
    details.
plugins_directory : str
    Path to MicroDrop user plugins directory.
server_url : str
    URL of JSON request for MicroDrop plugins package index.  See
    ``DEFAULT_SERVER_URL`` for default.

Returns
-------
(path, dict)
    Path to directory of installed plugin and plugin package metadata
    dictionary.


.. _version specifiers:
    https://www.python.org/dev/peps/pep-0440/#version-specifiers

.. versionchanged:: 0.25.2
    Import `pip_helpers` locally to avoid error `sci-bots/mpm#5`_.

    .. _sci-bots/mpm#5: https://github.com/sci-bots/mpm/issues/5