.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/basics/installing_packages.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_basics_installing_packages.py: ========================= 1.20 installing packages ========================= .. GENERATED FROM PYTHON SOURCE LINES 9-10 What is meaning of installing a python package? .. GENERATED FROM PYTHON SOURCE LINES 10-16 .. code-block:: default def foo(): pass foo() .. GENERATED FROM PYTHON SOURCE LINES 17-29 Above we used the function `foo` which was defined above in the same file where it was called. However, if the `foo` was defined not in the same file, but in some other file, we would have to ``import`` the `foo` function from that file. That file containing `foo` function can be located anywhere in the hard drive/storage of our machine/computer. If python is able to 'see' that file and consequently the foo function in that file, you can import foo from that file. But if python is not able to see that file, even if it is located somewhere in your computer, you can not import that function. This applies not only to functions by to every python object like variables, classes etc. The process of putting the required files in required format at the required location can be termed as installing a library/module/package in python. When we say that we want to install a library say ``numpy`` in python, it means we want all the files of this library at a place in our computer so that python can see it. Moreover, the files should be in such a form that we can import our desired functions from them. .. GENERATED FROM PYTHON SOURCE LINES 31-39 putting module in cwd --------------------- A simpler solution of installing a package/library is to simply put in our current working directory. This is because if we print ``sys.path``, the first directory is the current working directory. This means, whenever we try to import something, python will look into current working directory. Therefore, if we put some file/package/library in our current working directory, we can simply import that library without any problem. .. GENERATED FROM PYTHON SOURCE LINES 41-48 using site ----------------------- Putting a lot of libraries/packages in our current working library can clutter current working direcotry. This is because we may need hundred of libraries to work with. One solution is to place those packages at any place in our desired location in our machine, and then import that package from that location. We can add the location of that package into python's ``path`` during runtime using ``site.addsitedir`` function. .. GENERATED FROM PYTHON SOURCE LINES 48-52 .. code-block:: default import site site.addsitedir('path/to/my/package') .. GENERATED FROM PYTHON SOURCE LINES 53-62 pip ------- An easy and one of the most commonly used tool to install a package is using ``pip`` command. We can do this in the terminal and not in python console. However, since ipython console allows us to run terminal commands by prefixing them with ``!``, we can also use ``pip`` in ipython console. Remember that ``pip`` installs the package in ``site_packages`` directory of python. Also note that the built-in python modules can not be installed using ``pip``. Following examples show how to use ``pip`` to install a package called ``easy_mpl``. .. GENERATED FROM PYTHON SOURCE LINES 64-67 .. code-block:: python pip install easy_mpl .. GENERATED FROM PYTHON SOURCE LINES 70-73 .. code-block:: python pip install easy_mpl==0.21.3 .. GENERATED FROM PYTHON SOURCE LINES 76-79 .. code-block:: python pip install -update easy_mpl .. GENERATED FROM PYTHON SOURCE LINES 82-85 .. code-block:: python pip install easy_mpl[all] .. GENERATED FROM PYTHON SOURCE LINES 88-90 conda -------- .. GENERATED FROM PYTHON SOURCE LINES 90-92 .. code-block:: default # -e . .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.001 seconds) .. _sphx_glr_download_auto_examples_basics_installing_packages.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/AtrCheema/python-seekho/master?urlpath=lab/tree/notebooks/auto_examples/basics/installing_packages.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: installing_packages.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: installing_packages.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_