.. _installmodulerst: ======================== Ways to install a module ======================== .. only:: html **Links:** :download:`notebook `, :downloadlink:`html `, :download:`PDF `, :download:`python `, :downloadlink:`slides `, :githublink:`GitHub|_doc/notebooks/install_module.ipynb|*` Install a module from a notebook. .. code:: ipython3 from jyquickhelper import add_notebook_menu add_notebook_menu() .. contents:: :local: The module `pymyinstall `__ 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: - **pip**: pip - **wheel**: use also pip but on Windows, it will fetch the wheel file from the location mentioned below (Unofficial…) - **github**: source (usually from `github `__), the owner of the source must be specified Old way which should not be used anymore: - exe: a setup on Windows (only on Windows), replaced by pip in Linux/Max - exe_xd: only for Windows, some setups gathered on my website `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: - `Unofficial Windows Binaries for Python Extension Packages `__ - `Anaconda `__ `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 `__. .. code:: ipython3 from pymyinstall import ModuleInstall The following only works if you have enough permissions to do it which is the case if the notebook server is started with admin permissions or if you are using a virtual environment. .. code:: ipython3 ModuleInstall("numbers_extractor", "pip").install() .. parsed-literal:: installation of numbers_extractor:pip:import numbers_extractor .. parsed-literal:: True wheel (for files \*.whl) ~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: ipython3 ModuleInstall("numpy", "wheel").install() .. parsed-literal:: True The function checks first if the module was already installed. That’s why it displays only True. All modules are not available at `Unofficial Windows Binaries for Python Extension Packages `__ such as `xgboost `__. For this one, ``wheel`` must be replaced by ``wheel2``. The wheel file will be picked from `xavierdupre.fr `__. 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 `__. .. code:: ipython3 ModuleInstall("bottle", "github", "defnull").install() .. parsed-literal:: 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 .. parsed-literal:: 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. .. code:: ipython3 ModuleInstall("bottle", "github", "defnull").install() .. parsed-literal:: installation of bottle:github:import bottle unzipping .\bottle.zip install C warning: Successfully installed not found .. parsed-literal:: True We finally check the module can be imported. It sometimes requires the kernel to restarted. .. code:: ipython3 import bottle The two previous methods download files and create others when some file needs to be uncompressed. .. code:: ipython3 import os os.listdir(".") .. parsed-literal:: ['bottle-master', 'bottle.zip', 'install_module.ipynb', 'python-snappy-0.5.win32-py3.4.exe']