The module pymysintall proposes an easy to install module mostly on Windows as it is already quite easy to do it on Linux/Mac through pip. There are a couple of ways to install a module and they should be tried in that way:
Old way which should not be used anymore:
pip is great because it deals with dependencies for you. I recommend to use Pyhon 3.4 because that is the first version which includes pip
. It takes the modules from PyPI. The only drawback happens on Windows when a module includes Fortran/C/C++ files which must be compiled. As opposed to Linux or Mac with gcc, there is not an official compiler to handle every package and it has to be installed first. On Windows, it can be done by installing Visual Studio Express 2010 but sometimes, the dependencies can be tricky. That's why it is recommended to install already compiled python extensions. Not every module provides a compiled version but there exists two main ways to get them:
pymysintall takes the setup from the first source. The following snippets of code gives an example for each described way to install a module. The setup way only works on Windows.
pip
Let's try with the following module: numbers_extractor.
from pymyinstall import ModuleInstall
ModuleInstall("numbers_extractor", "pip").install()
installation of numbers_extractor:pip:import numbers_extractor
True
wheel (for files *.whl)
ModuleInstall("numpy", "wheel").install()
True
The function checks first if the module was already installed. That explains why a second run does not print anything.
ModuleInstall("numbers_extractor", "pip").install()
True
exe
We try with the module snappy.
ModuleInstall("python-snappy", "exe", mname="snappy").install()
installation of python-snappy:exe:import snappy downloading python-snappy-0.5.win32-py3.4.exe writing python-snappy-0.5.win32-py3.4.exe executing python-snappy-0.5.win32-py3.4.exe
True
Here again a second call does not do anything. python-snappy
is the prefix of the setup, snappy
is its name when we need to import it: import snappy
.
ModuleInstall("python-snappy", "exe", mname="snappy").install()
True
Unfortunately, some modules are missing from Unofficial Windows Binaries for Python Extension Packages such as paramiko which I use to open a SSH connection. For this one, exe
must be replaced by exe_xd
. This way only works in Windows but not on Linux or Mac.
github
github holds the source of most of the open source project. This one is no exception. You can check this page for example Top 400 Python Projects in Github. We try here with the module bottle <https://github.com/defnull/bottle>
_.
ModuleInstall("bottle", "github", "defnull").install()
installation of bottle:github:import bottle downloading https://github.com/defnull/bottle/archive/master.zip unzipping .\bottle.zip creating folder .\bottle-master unzipped bottle-master/.coveragerc to .\bottle-master/.coveragerc unzipped bottle-master/.gitignore to .\bottle-master/.gitignore unzipped bottle-master/.travis.yml to .\bottle-master/.travis.yml unzipped bottle-master/AUTHORS to .\bottle-master/AUTHORS unzipped bottle-master/LICENSE to .\bottle-master/LICENSE unzipped bottle-master/MANIFEST.in to .\bottle-master/MANIFEST.in unzipped bottle-master/Makefile to .\bottle-master/Makefile unzipped bottle-master/README.rst to .\bottle-master/README.rst unzipped bottle-master/bottle.py to .\bottle-master/bottle.py creating folder .\bottle-master/docs creating folder .\bottle-master/docs/_locale unzipped bottle-master/docs/_locale/README.txt to .\bottle-master/docs/_locale/README.txt unzipped bottle-master/docs/_locale/update.sh to .\bottle-master/docs/_locale/update.sh creating folder .\bottle-master/docs/_locale/zh_CN unzipped bottle-master/docs/_locale/zh_CN/api.po to .\bottle-master/docs/_locale/zh_CN/api.po unzipped bottle-master/docs/_locale/zh_CN/async.po to .\bottle-master/docs/_locale/zh_CN/async.po unzipped bottle-master/docs/_locale/zh_CN/changelog.po to .\bottle-master/docs/_locale/zh_CN/changelog.po unzipped bottle-master/docs/_locale/zh_CN/configuration.po to .\bottle-master/docs/_locale/zh_CN/configuration.po unzipped bottle-master/docs/_locale/zh_CN/contact.po to .\bottle-master/docs/_locale/zh_CN/contact.po unzipped bottle-master/docs/_locale/zh_CN/deployment.po to .\bottle-master/docs/_locale/zh_CN/deployment.po unzipped bottle-master/docs/_locale/zh_CN/development.po to .\bottle-master/docs/_locale/zh_CN/development.po unzipped bottle-master/docs/_locale/zh_CN/faq.po to .\bottle-master/docs/_locale/zh_CN/faq.po unzipped bottle-master/docs/_locale/zh_CN/index.po to .\bottle-master/docs/_locale/zh_CN/index.po unzipped bottle-master/docs/_locale/zh_CN/plugindev.po to .\bottle-master/docs/_locale/zh_CN/plugindev.po unzipped bottle-master/docs/_locale/zh_CN/plugins.po to .\bottle-master/docs/_locale/zh_CN/plugins.po unzipped bottle-master/docs/_locale/zh_CN/recipes.po to .\bottle-master/docs/_locale/zh_CN/recipes.po unzipped bottle-master/docs/_locale/zh_CN/routing.po to .\bottle-master/docs/_locale/zh_CN/routing.po unzipped bottle-master/docs/_locale/zh_CN/stpl.po to .\bottle-master/docs/_locale/zh_CN/stpl.po unzipped bottle-master/docs/_locale/zh_CN/tutorial.po to .\bottle-master/docs/_locale/zh_CN/tutorial.po unzipped bottle-master/docs/_locale/zh_CN/tutorial_app.po to .\bottle-master/docs/_locale/zh_CN/tutorial_app.po unzipped bottle-master/docs/api.rst to .\bottle-master/docs/api.rst unzipped bottle-master/docs/async.rst to .\bottle-master/docs/async.rst unzipped bottle-master/docs/changelog.rst to .\bottle-master/docs/changelog.rst unzipped bottle-master/docs/conf.py to .\bottle-master/docs/conf.py unzipped bottle-master/docs/configuration.rst to .\bottle-master/docs/configuration.rst unzipped bottle-master/docs/contact.rst to .\bottle-master/docs/contact.rst unzipped bottle-master/docs/deployment.rst to .\bottle-master/docs/deployment.rst unzipped bottle-master/docs/development.rst to .\bottle-master/docs/development.rst unzipped bottle-master/docs/faq.rst to .\bottle-master/docs/faq.rst unzipped bottle-master/docs/index.rst to .\bottle-master/docs/index.rst unzipped bottle-master/docs/plugindev.rst to .\bottle-master/docs/plugindev.rst creating folder .\bottle-master/docs/plugins unzipped bottle-master/docs/plugins/index.rst to .\bottle-master/docs/plugins/index.rst unzipped bottle-master/docs/recipes.rst to .\bottle-master/docs/recipes.rst unzipped bottle-master/docs/routing.rst to .\bottle-master/docs/routing.rst unzipped bottle-master/docs/stpl.rst to .\bottle-master/docs/stpl.rst unzipped bottle-master/docs/tutorial.rst to .\bottle-master/docs/tutorial.rst unzipped bottle-master/docs/tutorial_app.rst to .\bottle-master/docs/tutorial_app.rst unzipped bottle-master/setup.cfg to .\bottle-master/setup.cfg unzipped bottle-master/setup.py to .\bottle-master/setup.py creating folder .\bottle-master/test unzipped bottle-master/test/.coveragerc to .\bottle-master/test/.coveragerc unzipped bottle-master/test/build_python.sh to .\bottle-master/test/build_python.sh unzipped bottle-master/test/servertest.py to .\bottle-master/test/servertest.py unzipped bottle-master/test/test_auth.py to .\bottle-master/test/test_auth.py unzipped bottle-master/test/test_config.py to .\bottle-master/test/test_config.py unzipped bottle-master/test/test_configdict.py to .\bottle-master/test/test_configdict.py unzipped bottle-master/test/test_contextlocals.py to .\bottle-master/test/test_contextlocals.py unzipped bottle-master/test/test_environ.py to .\bottle-master/test/test_environ.py unzipped bottle-master/test/test_fileupload.py to .\bottle-master/test/test_fileupload.py unzipped bottle-master/test/test_formsdict.py to .\bottle-master/test/test_formsdict.py unzipped bottle-master/test/test_importhook.py to .\bottle-master/test/test_importhook.py unzipped bottle-master/test/test_jinja2.py to .\bottle-master/test/test_jinja2.py unzipped bottle-master/test/test_mako.py to .\bottle-master/test/test_mako.py unzipped bottle-master/test/test_mdict.py to .\bottle-master/test/test_mdict.py unzipped bottle-master/test/test_mount.py to .\bottle-master/test/test_mount.py unzipped bottle-master/test/test_outputfilter.py to .\bottle-master/test/test_outputfilter.py unzipped bottle-master/test/test_plugins.py to .\bottle-master/test/test_plugins.py unzipped bottle-master/test/test_resources.py to .\bottle-master/test/test_resources.py unzipped bottle-master/test/test_route.py to .\bottle-master/test/test_route.py unzipped bottle-master/test/test_router.py to .\bottle-master/test/test_router.py unzipped bottle-master/test/test_securecookies.py to .\bottle-master/test/test_securecookies.py unzipped bottle-master/test/test_sendfile.py to .\bottle-master/test/test_sendfile.py unzipped bottle-master/test/test_server.py to .\bottle-master/test/test_server.py unzipped bottle-master/test/test_stpl.py to .\bottle-master/test/test_stpl.py unzipped bottle-master/test/test_wsgi.py to .\bottle-master/test/test_wsgi.py unzipped bottle-master/test/testall.py to .\bottle-master/test/testall.py unzipped bottle-master/test/tools.py to .\bottle-master/test/tools.py unzipped bottle-master/test/travis-requirements.txt to .\bottle-master/test/travis-requirements.txt unzipped bottle-master/test/travis_setup.sh to .\bottle-master/test/travis_setup.sh creating folder .\bottle-master/test/views unzipped bottle-master/test/views/jinja2_base.tpl to .\bottle-master/test/views/jinja2_base.tpl unzipped bottle-master/test/views/jinja2_inherit.tpl to .\bottle-master/test/views/jinja2_inherit.tpl unzipped bottle-master/test/views/jinja2_simple.tpl to .\bottle-master/test/views/jinja2_simple.tpl unzipped bottle-master/test/views/mako_base.tpl to .\bottle-master/test/views/mako_base.tpl unzipped bottle-master/test/views/mako_inherit.tpl to .\bottle-master/test/views/mako_inherit.tpl unzipped bottle-master/test/views/mako_simple.tpl to .\bottle-master/test/views/mako_simple.tpl unzipped bottle-master/test/views/stpl_include.tpl to .\bottle-master/test/views/stpl_include.tpl unzipped bottle-master/test/views/stpl_no_vars.tpl to .\bottle-master/test/views/stpl_no_vars.tpl unzipped bottle-master/test/views/stpl_simple.tpl to .\bottle-master/test/views/stpl_simple.tpl unzipped bottle-master/test/views/stpl_t2base.tpl to .\bottle-master/test/views/stpl_t2base.tpl unzipped bottle-master/test/views/stpl_t2inc.tpl to .\bottle-master/test/views/stpl_t2inc.tpl unzipped bottle-master/test/views/stpl_t2main.tpl to .\bottle-master/test/views/stpl_t2main.tpl unzipped bottle-master/test/views/stpl_unicode.tpl to .\bottle-master/test/views/stpl_unicode.tpl unzipped bottle-master/tox.ini to .\bottle-master/tox.ini install C warning: Successfully installed not found
True
The function downloads the source from GitHub and install them using the instruction python setup.py install
. The function still has to be improved because analyzing the output is always obvious if there are dependencies or error messages. We check again a second call does not install the module again.
ModuleInstall("bottle", "github", "defnull").install()
installation of bottle:github:import bottle unzipping .\bottle.zip install C warning: Successfully installed not found
True
We finally check the module can be imported. It sometimes requires the kernel to restarted.
import bottle
The two previous methods download files and create others when some file needs to be uncompressed.
import os
os.listdir(".")
['bottle-master', 'bottle.zip', 'install_module.ipynb', 'python-snappy-0.5.win32-py3.4.exe']