{"id":189083,"date":"2023-04-21T10:38:00","date_gmt":"2023-04-21T14:38:00","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=189083"},"modified":"2023-04-21T10:39:09","modified_gmt":"2023-04-21T14:39:09","slug":"how-to-install-python-packages-part-i","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/","title":{"rendered":"How to Install Python Packages? &#8211; Part I"},"content":{"rendered":"\n<p>The beauty of Python is that we have a collection of modules and packages which have been created for the purpose of making coding with Python easier. Also, the fact that it is open-source makes it incredibly easy for one individual to build on top of another person\u2019s work and create something useful.<\/p>\n\n\n\n<p>Thus, you can get a simple code for performing simple arithmetic operations or a group of code, called modules and packages, which can help perform data analysis, all on the internet.<\/p>\n\n\n\n<p>Let us learn all about Python packages and their applications with this interesting guide that covers:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>What are modules and packages?<\/li>\n\n\n\n<li>The need to install Python packages<\/li>\n\n\n\n<li>Importing Python packages<\/li>\n\n\n\n<li>Installing Python packages\n<ul class=\"wp-block-list\">\n<li>PyPI &#8211; Python package index<\/li>\n\n\n\n<li>Bonus: dir() function<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Resolution of frequent user queries\n<ul class=\"wp-block-list\">\n<li>Cannot install iexfinance using conda install<\/li>\n\n\n\n<li>Import get_data from iexfinance does not work<\/li>\n\n\n\n<li>Dependency packages &#8211; scikit-learn<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-are-modules-and-packages\">What are modules and packages?<\/h2>\n\n\n\n<p>When we write Python code lines for a particular task, for instance, trade order execution or for entering a trade signal (buy or sell), we use the Python environment such as the Python or IPython console.<\/p>\n\n\n\n<p>In order to write a long program, we might consider a text editor to write the Python code lines. This is known as writing a script.<\/p>\n\n\n\n<p>As a program gets longer, we may want to split it into several small files for easier maintenance. Also, we can find a way to copy and paste the lines of code each time we wish to use the same, without having to create the code lines every time we want the same program.<\/p>\n\n\n\n<p>To support this, Python has a way to put a code definition in a file and use them in any Python script (code lines). Such a file is called a module. The definitions from a module can be imported into other modules or in the program that we code.<\/p>\n\n\n\n<p>Packages are nothing but a collection of modules. It is a way of structuring Python\u2019s module namespace by using &#8220;dotted module names&#8221;.<\/p>\n\n\n\n<p>For example, the module name \u201cmatplotlib.pyplot\u201d designates a submodule named \u201cpyplot\u201d in a package named \u201cmatplotlib\u201d.<\/p>\n\n\n\n<p>Packaging the modules in such a way saves the author of different modules from having to worry about each other\u2019s global variable names. Also, the use of dots in the module titles saves the author of multi-module packages from having to worry about each other\u2019s module names.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-need-to-install-python-packages\">The need to install Python packages<\/h2>\n\n\n\n<p>Python has certain in-built packages which are installed along with the installation of Python. But what about the packages that do not come along with Python installation?<\/p>\n\n\n\n<p>If you try to import such packages without installing them first you would get an error called &#8216;ModuleNotFoundError&#8217;.<\/p>\n\n\n\n<p>For example,&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/backtrader\/#:~:text=There%20is%20no%20special%20requirement,the%20package%20manager%20%E2%80%9Cpip%E2%80%9D.&amp;text=Although%20there%20are%20no%20dependencies,%2C%20%E2%80%9Cmatplotlib%E2%80%9D%20is%20required.\">Backtrader<\/a>&nbsp;is a Python package used for live trading and backtesting trading strategies. You can see the error when we try to import it.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># import the package\nimport backtrader<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/e613b413277bc2af0e3250ec9a9144ea#file-import_package-py\" target=\"_blank\" rel=\"noreferrer noopener\">import_package.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">---------------------------------------------------------------------------\nModuleNotFoundError Traceback (most recent call last)\nInput In [47], in &lt;module&gt;\n----&gt; 1 import backtrader\nModuleNotFoundError: No module named 'backtrader'<\/pre>\n\n\n\n<p>The output above shows an error which is because \u2018Backtrader\u2019 is not a built-in Python package and we tried to import it without installing it first.<\/p>\n\n\n\n<p>Hence, to install the Backtrader, you can do so by using the \u201cpip\u201d package manager, then open the command prompt (or terminal for Mac users) and type the below code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install backtrader<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/11b47ae04b28b1cfece20d80e08d93dd#file-backtrader-py\" target=\"_blank\" rel=\"noreferrer noopener\">Backtrader.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>Now, you can import Backtrader with the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import backtrader as bt<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/54ab8e1b1eca03d605ef908c691efe55#file-bt-py\" target=\"_blank\" rel=\"noreferrer noopener\">bt.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"importing-python-packages\">Importing Python packages<\/h2>\n\n\n\n<p>As we know Python is an open-source project. The Python developers community make their codes available for others in the form of packages under the open-source license.<\/p>\n\n\n\n<p>You will have access to some in-built packages such as&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/python-pandas-tutorial\/\">Pandas<\/a>,&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/python-numpy-tutorial-installation-arrays-random-sampling\/\">NumPy<\/a>&nbsp;by default when you install Python.<\/p>\n\n\n\n<p>You can import these packages in your code using the following syntax.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Import a Python package\nImport pandas<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/3d8ed4f874967cb5b51d70c92d16c779#file-pandas-py\" target=\"_blank\" rel=\"noreferrer noopener\">Pandas.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>Suppose we want to design a package (a collection of modules) for the uniform handling of various trading strategies and their data. There are many different data files based on data frequencies, so we may need to create and maintain a growing collection of modules for the conversion between the various data frequencies.<\/p>\n\n\n\n<p>Also, there are many different strategies and operations that we might need to perform. All of this put together means we would have to write a never-ending stream of modules to handle the combinatorics of data, strategies, and operations.<\/p>\n\n\n\n<p>Here\u2019s a possible package structure to make our lives easier.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>strats\/<br>__init__.py<br>data\/<br>__init__.py<br>equity.py<br>currency.py<br>options.py<br>&#8230;<br>strategies\/<br>__init__.py<br>rsi.py<br>macd.py<br>smalma.py<br>peratio.py<br>fundamentalindex.py<br>statisticalarbitrage.py<br>turtle.py<br>&#8230;<br>operations\/<br>__init__.py<br>performanceanalytics.py<br>dataconversion.py<br>&#8230;<\/td><td>Top-level package<br>Initialize strats package<br>Sub-package for data<br>Equity module<br>Sub-package for strategies<br>RSI module<br>Sub-package for operations<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>When importing the package, Python searches through the directories in sys.path looking for the package subdirectory. The __init__.py file is required to make Python treat the directories as containing packages.<\/p>\n\n\n\n<p>If we are to use this package, we can do so in the following manner:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import strats.data.equity\nimport strats.strategies.statisticalarbitrage<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/74e07b45cc3afede9260a841c92365c2#file-strats-py\" target=\"_blank\" rel=\"noreferrer noopener\">Strats.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>Above statements load the equity and statistical arbitrage modules from the data and strategies sub-packages respectively under the strats package.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"installing-python-packages\">Installing Python packages<\/h2>\n\n\n\n<p>But where can you find these packages and how to install them? That is what we will find in this section of the blog.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"pypi-python-package-index\">PyPI &#8211; Python package index<\/h3>\n\n\n\n<p>Most open-source Python packages are made available through PyPI &#8211; Python Package Index. It is a repository of software for the Python programming language. You can find the packages developed and shared by the Python community here \u207d<a href=\"https:\/\/pypi.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u00b9<\/a>\u207e. You can also publish your package through PyPI.<\/p>\n\n\n\n<p>To install the packages from PyPI you would need a package installer. The recommended package installer for PyPI is \u2018pip\u2019. Pip is installed when you install Python in your system.<\/p>\n\n\n\n<p><strong>Installing pip<\/strong><\/p>\n\n\n\n<p>We can install a pip via the command line by using the curl command, which downloads the pip installation perl script.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl -O https:\/\/bootstrap.pypa.io\/get-pip.py<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/3a42f0b2fc645e8e563399573c933464#file-curl-py\" target=\"_blank\" rel=\"noreferrer noopener\">curl.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>Once it is downloaded, we need to execute it in the command prompt with the Python interpreter. This command works for all operating systems such as Windows, Mac, etc.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python get-pip.py<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/05f1f20d42830254069cc81dafb064b9#file-pip_command-py\" target=\"_blank\" rel=\"noreferrer noopener\">pip_command.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>If the above command fails on a Mac and Linux distribution due to permission issues (most likely because Python does not have permission to update certain directories on the file system.<\/p>\n\n\n\n<p>These directories are read-only by default to ensure that random scripts cannot mess with important files and infect the system with viruses), we may need to run the following command.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo python get-pip.py<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/9755b374be38c81324d4b2291e2edc74#file-sudo_python-py\" target=\"_blank\" rel=\"noreferrer noopener\">sudo_python.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>In this section of \u2018how to install Python packages\u2019, we will understand how to use the following syntax to install a package using \u2018pip\u2019.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">!pip install package_name`<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/31f35af33936bfef95d5e0a213cad21d#file-pip_package-py\" target=\"_blank\" rel=\"noreferrer noopener\">pip_package.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>For example, to install the Backtrader package you have to replace the &#8216;package_name&#8217; with &#8216;backtrader&#8217;.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Install a Python package\n!pip install backtrader<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/28a5c5b8d1ef292bf5e0d22dddcea404#file-install_backtrader-py\" target=\"_blank\" rel=\"noreferrer noopener\">Install_backtrader.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Collecting backtrader\n Downloading backtrader-1.9.76.123-py2.py3-none-any.whl (410 kB)\n \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 410.1\/410.1 kB 2.9 MB\/s eta 0:00:00a 0:00:01\nInstalling collected packages: backtrader\nSuccessfully installed backtrader-1.9.76.123<\/pre>\n\n\n\n<p>After installation, you can see a success message in the last line. This means the package can now be imported and used in your code. There are a number of institutions along with individuals who use different versions of Python itself, so it goes without saying that there might be versions of packages too.<\/p>\n\n\n\n<p>Let\u2019s find out about package versions in the next section of the tutorial on \u2018how to install Python packages\u2019.<\/p>\n\n\n\n<p><strong>A version of the package<\/strong><\/p>\n\n\n\n<p>PyPI lets the developer submit any number of versions of the package. It holds a record for each combination of package name and version submitted in the repository.<\/p>\n\n\n\n<p>The &#8216;backtrader&#8217; package also has different versions \u207d<a href=\"https:\/\/pypi.org\/project\/backtrader\/1.9.70.122\/#history\" target=\"_blank\" rel=\"noreferrer noopener\">\u00b2<\/a>\u207e available.<\/p>\n\n\n\n<p><strong>Using a different version of the Python package<\/strong><\/p>\n\n\n\n<p>If you want to use a different version of the package, you can install that using the following command.<\/p>\n\n\n\n<p>Let us install the 1.9.68.122 version of the \u2018backtrader\u2019 package.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Install a specific version of the package\n!pip install backtrader==1.9.68.122<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/9d4e4720e95fefc624376c470603794f#file-pip_version-py\" target=\"_blank\" rel=\"noreferrer noopener\">pip_version.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Collecting backtrader==1.9.68.122\nstyle=\"padding-left: 40px;\"&gt;Using cached https:\/\/files.pythonhosted.org\/packages\/f5\/6f\/e51e5b5969ad1e8071rader-1.9.68.122-py2.py3-none-any.whl\nInstalling collected packages: backtrader\nFound existing installation: backtrader 1.9.78.122\nUninstalling backtrader-1.9.70.122:\nSuccessfully uninstalled backtrader-1.9.70.122\nSuccessfully installed backtrader-1.9.68.122<\/pre>\n\n\n\n<p><strong>Check for the version of the package<\/strong><\/p>\n\n\n\n<p>You can use the following syntax to check for the version of the package.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package_name.__version__<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/24ec900f24cb2d2c9bbb6fc9796d35dd#file-package_syntax-py\" target=\"_blank\" rel=\"noreferrer noopener\">package_syntax.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>But first, you need to import the package. You can check for the version of the &#8216;Backtrader&#8217; package as follows.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Import the package\nImport backtrader\n\n# Check the version of the package\nBacktrader._version_<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/a9d787a192b460c95c78ff218fd25d40#file-check_version-py\" target=\"_blank\" rel=\"noreferrer noopener\">Check_version.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">'1.9.68.122'<\/pre>\n\n\n\n<p><strong>Things to note<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Pip installs the latest version of the package by default.<\/li>\n\n\n\n<li>While installing the specific version pip replaces the existing version if there is any.<\/li>\n\n\n\n<li>You can use the above syntax for installing the packages through the IPython notebook.<\/li>\n\n\n\n<li>If you wish to install using the command prompt you can use the same syntax by just removing the exclamation mark.<\/li>\n<\/ol>\n\n\n\n<p>For example,<\/p>\n\n\n\n<p>IPython notebook:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">!pip install package name<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/a6a8de3b516fab6b183725dae2806bf8#file-ipython-py\" target=\"_blank\" rel=\"noreferrer noopener\">IPython.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>Command prompt:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install package name<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/db50e32542bc0c190d6475c9f6bbaf2d#file-command_prompt-py\" target=\"_blank\" rel=\"noreferrer noopener\">Command_prompt.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>I hope this will clarify any queries or doubts that you might have about installing Python packages. One of the popular ways to traverse through the Python codes and packages is the dir() function. Let\u2019s learn more about what it does in the next section of the tutorial on \u2018how to install Python packages\u2019.<\/p>\n\n\n\n<p><em>Stay tuned for the second installment to learn about Bonus: dir()function.<\/em><\/p>\n\n\n\n<p><em>Originally posted on <a href=\"https:\/\/blog.quantinsti.com\/installing-python-packages\/\">QuantInsti<\/a> blog.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let us learn all about Python packages and their applications with this interesting guide that covers:<\/p>\n","protected":false},"author":368,"featured_media":189093,"comment_status":"open","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,349,338],"tags":[11809,806,4804,595],"contributors-categories":[13654],"class_list":{"0":"post-189083","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-python-development","10":"category-ibkr-quant-news","11":"tag-backtrader","12":"tag-data-science","13":"tag-pypi","14":"tag-python","15":"contributors-categories-quantinsti"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Install Python Packages? &#8211; Part I | IBKR Quant<\/title>\n<meta name=\"description\" content=\"Let us learn all about Python packages and their applications with this interesting guide that covers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/189083\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Install Python Packages? - Part I | IBKR Campus US\" \/>\n<meta property=\"og:description\" content=\"Let us learn all about Python packages and their applications with this interesting guide that covers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-21T14:38:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-21T14:39:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/04\/python-green-binary-background.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"563\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Chainika Thakar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Chainika Thakar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-install-python-packages-part-i\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-install-python-packages-part-i\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Chainika Thakar\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/c97b4c6a477fa019494f67cff50fcb10\"\n\t            },\n\t            \"headline\": \"How to Install Python Packages? &#8211; Part I\",\n\t            \"datePublished\": \"2023-04-21T14:38:00+00:00\",\n\t            \"dateModified\": \"2023-04-21T14:39:09+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-install-python-packages-part-i\\\/\"\n\t            },\n\t            \"wordCount\": 1553,\n\t            \"commentCount\": 0,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-install-python-packages-part-i\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/04\\\/python-green-binary-background.jpg\",\n\t            \"keywords\": [\n\t                \"Backtrader\",\n\t                \"Data Science\",\n\t                \"PyPi\",\n\t                \"Python\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Python Development\",\n\t                \"Quant\"\n\t            ],\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"CommentAction\",\n\t                    \"name\": \"Comment\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-install-python-packages-part-i\\\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-install-python-packages-part-i\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-install-python-packages-part-i\\\/\",\n\t            \"name\": \"How to Install Python Packages? - Part I | IBKR Campus US\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-install-python-packages-part-i\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-install-python-packages-part-i\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/04\\\/python-green-binary-background.jpg\",\n\t            \"datePublished\": \"2023-04-21T14:38:00+00:00\",\n\t            \"dateModified\": \"2023-04-21T14:39:09+00:00\",\n\t            \"description\": \"Let us learn all about Python packages and their applications with this interesting guide that covers.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-install-python-packages-part-i\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-install-python-packages-part-i\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/04\\\/python-green-binary-background.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/04\\\/python-green-binary-background.jpg\",\n\t            \"width\": 1000,\n\t            \"height\": 563,\n\t            \"caption\": \"Python\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/c97b4c6a477fa019494f67cff50fcb10\",\n\t            \"name\": \"Chainika Thakar\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/chainikathakar\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Install Python Packages? &#8211; Part I | IBKR Quant","description":"Let us learn all about Python packages and their applications with this interesting guide that covers.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/189083\/","og_locale":"en_US","og_type":"article","og_title":"How to Install Python Packages? - Part I | IBKR Campus US","og_description":"Let us learn all about Python packages and their applications with this interesting guide that covers.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/","og_site_name":"IBKR Campus US","article_published_time":"2023-04-21T14:38:00+00:00","article_modified_time":"2023-04-21T14:39:09+00:00","og_image":[{"width":1000,"height":563,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/04\/python-green-binary-background.jpg","type":"image\/jpeg"}],"author":"Chainika Thakar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Chainika Thakar","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/"},"author":{"name":"Chainika Thakar","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/c97b4c6a477fa019494f67cff50fcb10"},"headline":"How to Install Python Packages? &#8211; Part I","datePublished":"2023-04-21T14:38:00+00:00","dateModified":"2023-04-21T14:39:09+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/"},"wordCount":1553,"commentCount":0,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/04\/python-green-binary-background.jpg","keywords":["Backtrader","Data Science","PyPi","Python"],"articleSection":["Data Science","Programming Languages","Python Development","Quant"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/","name":"How to Install Python Packages? - Part I | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/04\/python-green-binary-background.jpg","datePublished":"2023-04-21T14:38:00+00:00","dateModified":"2023-04-21T14:39:09+00:00","description":"Let us learn all about Python packages and their applications with this interesting guide that covers.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-install-python-packages-part-i\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/04\/python-green-binary-background.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/04\/python-green-binary-background.jpg","width":1000,"height":563,"caption":"Python"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/c97b4c6a477fa019494f67cff50fcb10","name":"Chainika Thakar","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/chainikathakar\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/04\/python-green-binary-background.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/189083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/368"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=189083"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/189083\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/189093"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=189083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=189083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=189083"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=189083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}