<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged pip</title>
<link>https://coderlegion.com/tag/pip</link>
<description>Powered by Question2Answer</description>
<item>
<title>Python Installing External Packages Sources</title>
<link>https://coderlegion.com/205/python-installing-external-packages-sources</link>
<description>&lt;h2 id=&quot;table-of-contents&quot;&gt;Table of Contents&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#introduction&quot;&gt;Introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#installing-packages-from-alternative-sources&quot;&gt;Installing packages from alternative sources&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#installing-packages-from-version-control-repositories-github-gitlab-bitbucket&quot;&gt;Installing packages from version control repositories (GitHub, GitLab, Bitbucket)&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#github&quot;&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#gitlab&quot;&gt;GitLab&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#bitbucket&quot;&gt;Bitbucket&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#installing-packages-from-local-directories-or-archives&quot;&gt;Installing packages from local directories or archives&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#installing-packages-from-directories&quot;&gt;Installing packages from directories&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#installing-packages-from-archives&quot;&gt;Installing packages from archives&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#virtual-environments-and-pip&quot;&gt;Virtual environments and pip&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#introduction-to-virtual-environments&quot;&gt;Introduction to virtual environments&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#creating-and-activating-virtual-environments&quot;&gt;Creating and activating virtual environments&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#creating-and-activating-virtual-environments-using-venv&quot;&gt;Creating and activating virtual environments using venv&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#windows-2&quot;&gt;Windows&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#linuxmacos-1&quot;&gt;Linux/macOS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#creating-and-activating-virtual-environments-using-virtualenv&quot;&gt;Creating and activating virtual environments using virtualenv&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#windows-3&quot;&gt;Windows&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#linuxmacos-2&quot;&gt;Linux/macOS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#requirements-files&quot;&gt;Requirements Files&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#creating-and-using-requirements-files&quot;&gt;Creating and using requirements files&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#handling-package-installation-errors&quot;&gt;Handling package installation errors&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#common-errors&quot;&gt;Common errors&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#package-not-found&quot;&gt;Package not found&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#dependency-conflict&quot;&gt;Dependency conflict&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#permission-error&quot;&gt;Permission error&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#permission-error-in-linux&quot;&gt;Permission error in linux&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#insufficient-user-privileges&quot;&gt;Insufficient user privileges&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#linuxmacos-3&quot;&gt;Linux/macOS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#windows-4&quot;&gt;Windows&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#advance-pip-features&quot;&gt;Advance pip features&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#environment-markers&quot;&gt;Environment markers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#editable-installs&quot;&gt;Editable installs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#faq&quot;&gt;FAQs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#conclusion&quot;&gt;Conclusion&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;#references&quot;&gt;References&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a name=&quot;introduction&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;1-introduction&quot;&gt;1. Introduction&lt;/h2&gt;
&lt;p&gt;In the previous article &lt;a rel=&quot;nofollow&quot; href=&quot;https://logiclair.org/1802/modules-and-packages%26gt-installing-external-packages-with-pip&quot;&gt;Modules and Packages Installing External Packages with pip&lt;/a&gt; we have discussed the basic package management with &lt;strong&gt;pip&lt;/strong&gt;. In this article, we will go through the more advanced topics that will help you manage your project packages professionally so let's get started.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;installing-packages-from-alternative-sources&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;2-installing-packages-from-alternative-sources&quot;&gt;2. Installing packages from alternative sources&lt;/h2&gt;
&lt;p&gt;Sometimes the required package is not available on &lt;a rel=&quot;nofollow&quot; href=&quot;https://pypi.org/&quot;&gt;&lt;strong&gt;PyPI&lt;/strong&gt;&lt;/a&gt;. In that case, pip will allow you to install packages from local directories or version control repositories.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;installing-packages-from-version-control-repositories-github-gitlab-bitbucket&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;installing-packages-from-version-control-repositories-github-gitlab-bitbucket-&quot;&gt;Installing packages from version control repositories (GitHub, GitLab, Bitbucket)&lt;/h3&gt;
&lt;p&gt;&lt;a name=&quot;github&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;github&quot;&gt;GitHub&lt;/h4&gt;
&lt;p&gt;Follow the below syntax to install packages from&lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/213/git-and-github-for-python-developers-a-comprehensive-guide?show=213#q213&quot; target=&quot;_blank&quot;&gt; GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install git+https://github.com/username/repository.git&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;Replace the original URL of the repository here &lt;code&gt;https://github.com/username/repository.git&lt;/code&gt;.  &lt;/p&gt;
&lt;p&gt;You can install the &lt;strong&gt;pandas&lt;/strong&gt; package from GitHub using the following syntax.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install git+https://github.com/pandas-dev/pandas.git&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=10535579976064557709&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;gitlab&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;gitlab&quot;&gt;GitLab&lt;/h4&gt;
&lt;p&gt;Follow the below syntax to install packages from GitLab.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install git+https://gitlab.com/username/repository.git&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;bitbucket&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;bitbucket&quot;&gt;Bitbucket&lt;/h4&gt;
&lt;p&gt;Follow the below syntax to install packages from Bitbucket.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install git+https://bitbucket.org/username/repository.git&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;installing-packages-from-local-directories-or-archives&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;installing-packages-from-local-directories-or-archives&quot;&gt;Installing packages from local directories or archives&lt;/h3&gt;
&lt;p&gt;&lt;a name=&quot;installing-packages-from-directories&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;installing-packages-from-directories&quot;&gt;Installing packages from directories&lt;/h4&gt;
&lt;p&gt;To install a package from the local directory follow the below syntax.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install -e /path/to/directory&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;&lt;code&gt;-e&lt;/code&gt;&lt;/strong&gt; flag simply means that if there are changes in the source code then it will be reflected and you don't have to reinstall.  &lt;/p&gt;
&lt;p&gt;Consider the following syntax of installing a &lt;strong&gt;package&lt;/strong&gt; from a local directory.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install -e /home/mypc/Documents/pandas&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;installing-packages-from-archives&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;installing-packages-from-archives&quot;&gt;Installing packages from archives&lt;/h4&gt;
&lt;p&gt;Similarly, you can also install packages from an archive file (e.g., .tar.gz, .zip) following the syntax below.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install /path/to/directory-archive.tar.gz&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;Consider the following syntax of installing a package name &lt;strong&gt;pandas&lt;/strong&gt; from an archive file.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install /home/mypc/Documents/pandas.tar.gz&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;virtual-environments-and-pip&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;3-virtual-environments-and-pip&quot;&gt;3. Virtual environments and pip&lt;/h2&gt;
&lt;p&gt;&lt;a name=&quot;introduction-to-virtual-environments&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;introduction-to-virtual-environments&quot;&gt;Introduction to virtual environments&lt;/h3&gt;
&lt;p&gt;If you are working with multiple projects then there is a high chance that you need different dependencies for different projects so you can't install the dependencies at the global level because it will conflict with other projects. To avoid those conflicts you can use &lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/250/setting-up-virtual-environment-in-python?show=250#q250&quot; target=&quot;_blank&quot;&gt;virtual environments&lt;/a&gt;. &lt;strong&gt;Virtual environments help you to isolate the project dependencies&lt;/strong&gt;. By doing that you can install different dependencies for each project in their isolated environment.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;creating-and-activating-virtual-environments&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;creating-and-activating-virtual-environments&quot;&gt;Creating and activating virtual environments&lt;/h3&gt;
&lt;p&gt;You can create a virtual environment either using &lt;code&gt;venv&lt;/code&gt; or &lt;code&gt;virtualevn&lt;/code&gt; . Let's discuss them one by one.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;creating-and-activating-virtual-environments-using-venv&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;creating-and-activating-virtual-environments-using-venv&quot;&gt;Creating and activating virtual environments using venv&lt;/h4&gt;
&lt;p&gt;Follow the below syntax to create a virtual environment using &lt;code&gt;venv&lt;/code&gt;.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;python3 -m venv env_name&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;windows-2&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h5 id=&quot;windows&quot;&gt;Windows&lt;/h5&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;python -m venv env&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=11236626685721995376&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The above command will create a virtual environment named &lt;code&gt;env&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can activate the virtual environment by using the command below.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;env\Scripts\activate&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=17119552273682905794&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;linuxmacos-1&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h5 id=&quot;linux-macos&quot;&gt;Linux/macOS&lt;/h5&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;python3 -m venv env&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=2547524687845449891&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The above command will create a virtual environment named &lt;code&gt;env&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can activate the virtual environment by using the command below.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;source env/bin/activate&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=16596829796341067525&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;creating-and-activating-virtual-environments-using-virtualenv&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;creating-and-activating-virtual-environments-using-virtualenv&quot;&gt;Creating and activating virtual environments using virtualenv&lt;/h4&gt;
&lt;p&gt;Before using &lt;code&gt;virtualenv&lt;/code&gt; to create virtual environments you have to install it by running the below command.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install virtualenv&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=4595713258860764725&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;After successful installation you can follow the following syntax to create a virtual environment using &lt;code&gt;virtualenv&lt;/code&gt;.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;virtualenv env_name&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;windows-3&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h5 id=&quot;windows-1&quot;&gt;Windows&lt;/h5&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;virtualenv env&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;The above command will create a virtual environment named &lt;code&gt;env&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can activate the virtual environment by using the command below.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;env\Scripts\activate&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;linuxmacos-2&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h5 id=&quot;linux-macos-1&quot;&gt;Linux/macOS&lt;/h5&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;virtualenv env&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;The above command will create a virtual environment named &lt;code&gt;env&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can activate the virtual environment by using the command below.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;source env/bin/activate&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;requirements-files&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;4-requirements-files&quot;&gt;4. Requirements Files&lt;/h2&gt;
&lt;p&gt;Requirements files are simply text files in which the project dependencies are listed. It helps manage and reproduce project environments. Following is an example of a &lt;code&gt;requirements.txt&lt;/code&gt; file.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;requests&amp;gt;=2.25.1
numpy==1.21.3
pandas~=1.3.4
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a name=&quot;creating-and-using-requirements-files&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;creating-and-using-requirements-files&quot;&gt;Creating and using requirements files&lt;/h3&gt;
&lt;p&gt;You can create a &lt;code&gt;requirements.txt&lt;/code&gt; file manually by listing down all the dependencies or you can use the following command.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 freeze &amp;gt; requirements.txt&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=5493596055788601878&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The above command will create a &lt;code&gt;requirements.txt&lt;/code&gt; containing all the dependencies listed in it.&lt;/p&gt;
&lt;p&gt;To install the dependencies using &lt;code&gt;requirements.txt&lt;/code&gt; you can follow the below command.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install -r requirements.txt&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=15600825113587659781&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;handling-package-installation-errors&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;5-handling-package-installation-errors&quot;&gt;5. Handling package installation errors&lt;/h2&gt;
&lt;p&gt;You might encounter errors during package installation using pip. In this section we will cover the common errors and we will see how to troubleshoot them.  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;common-errors&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;common-errors&quot;&gt;Common errors&lt;/h3&gt;
&lt;p&gt;Following are the common errors that you might encounter while installing packages using pip.  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;package-not-found&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;package-not-found&quot;&gt;Package not found&lt;/h4&gt;
&lt;p&gt;If you try to install a package that doesn't exist, or you misspelled the package's name then you will get the following error.  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=6346912291407152118&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error verify that the package you are trying to install exists. If so then check the spelling of the package name that you are trying to install.  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;dependency-conflict&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;dependency-conflict&quot;&gt;Dependency conflict&lt;/h4&gt;
&lt;p&gt;Dependency conflicts occur when two or more packages require different versions of the same dependency and those versions are incompatible with each other.  &lt;/p&gt;
&lt;p&gt;If you try to install the following packages you will get a dependency conflict.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install numpy==1.19.5&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install pandas==1.3.4&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;To resolve dependency conflicts you can upgrade or downgrade the package so that there will be no dependency conflicts.  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;permission-error&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;permission-error&quot;&gt;Permission error&lt;/h4&gt;
&lt;p&gt;Permission error indicates that you might not have the necessary permissions to install the package in the target directory.  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;permission-error-in-linux&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h5 id=&quot;permission-error-in-linux&quot;&gt;Permission error in linux&lt;/h5&gt;
&lt;p&gt;If you try to install a package outside a virtual environment in linux you will get the permission error.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install pandas&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;The above command will generate the following error. &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=4536803256314602106&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;To resolve the above error create the virtual environment as discussed above then run the command &lt;code&gt;pip3 install pandas&lt;/code&gt; again.  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;insufficient-user-privileges&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h5 id=&quot;insufficient-user-privileges&quot;&gt;Insufficient user privileges&lt;/h5&gt;
&lt;p&gt;Sometimes you might get this error due to user account privileges. In that case try to elevate the permissions while trying to install the packages.  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;linuxmacos-3&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h6 id=&quot;linux-macos-2&quot;&gt;Linux/macOS&lt;/h6&gt;
&lt;p&gt;Instead of using &lt;code&gt;pip3 install package_name&lt;/code&gt; try the following command to install the packages.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;sudo pip3 install package_name&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;Consider the following command of installing &lt;strong&gt;pandas&lt;/strong&gt; with elevated permissions.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;sudo pip3 install pandas&lt;/code&gt;&lt;/strong&gt;    &lt;/p&gt;
&lt;div class=&quot;div-red&quot;&gt;
&lt;span class=&quot;alert-header&quot;&gt;Caution:&lt;/span&gt;
&lt;span class=&quot;alert-body&quot;&gt;It is not recommended to use this method it is always encouraged to create a virtual environment &lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a name=&quot;windows-4&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h6 id=&quot;windows-2&quot;&gt;Windows&lt;/h6&gt;
&lt;p&gt;In windows, you have to run the command prompt in administrator mode to elevate the permissions. Follow the below steps to do so.  &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Right-click on the command prompt shortcut&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;Run as administrator&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once the command prompt is opened try to install the package again.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install pandas&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;advance-pip-features&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;6-advance-pip-features&quot;&gt;6. Advance pip features&lt;/h2&gt;
&lt;p&gt;Pip offers a range of advanced features that can enhance your package management experience.  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;environment-markers&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;environment-markers&quot;&gt;Environment markers&lt;/h3&gt;
&lt;p&gt;Environment markers allow you to specify conditional dependencies based on the python version, operating system, and other environment variables. By using environment markers you can avoid compatibility and conflict issues.&lt;br&gt;
If you have a python project that requires different dependencies based on the python version and operating system then you can use environment markers to enhance your &lt;code&gt;requirements.txt&lt;/code&gt; file as follows.  &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#Common dependencies for all environments
flask&amp;gt;=2.0.0
requests&amp;gt;=2.0.0

#Dependencies for Python 3.6 and above
pytz; python_version &amp;gt;= '3.6'

#Dependencies for Linux-based systems
linux-specific-package; sys_platform == 'linux'

#Dependencies for Windows
pywin32; sys_platform == 'win32'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Above you can see that we have created a &lt;code&gt;requirements.txt&lt;/code&gt; file that will install dependencies considering the specific environments.  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;editable-installs&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;editable-installs&quot;&gt;Editable installs&lt;/h3&gt;
&lt;p&gt;Editable installs also known as &lt;strong&gt;development mode&lt;/strong&gt; help you to install python packages from a local source directory in such a way that changes made to the source code are directly reflected in the installed package without reinstalling it.  &lt;/p&gt;
&lt;p&gt;Suppose you have a package name &lt;strong&gt;my_package&lt;/strong&gt; to install it in &lt;strong&gt;development mode&lt;/strong&gt; you have to go to the root directory of &lt;strong&gt;my_package&lt;/strong&gt; and run the following command.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install -e .&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;or&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;&lt;code&gt;pip3 install --editable .&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The above commands will install the package in editable mode the &lt;code&gt;.&lt;/code&gt; represents the current directory.  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;faq&quot;&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;&lt;div class=&quot;div-faq&quot;&gt;&lt;br&gt;
&lt;span class=&quot;faq-header&quot;&gt;FAQ&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;faq-body&quot;&gt;
Q. What is pip?&lt;br&gt;
A. Pip is a package manager in python that allows you to install manage and remove python packages from PyPI and other repositories. &lt;br&gt; &lt;br&gt;
Q. How do I install a package using pip?&lt;br&gt;
A. You can install a package using pip by running the command 'pip install package_name'. &lt;br&gt; &lt;br&gt;
Q. How can I upgrade a package using pip?&lt;br&gt;
A. You can upgrade a package using pip by running the command 'pip install --upgrade package_name'. &lt;br&gt; &lt;br&gt;
Q. How do I uninstall a package using pip?&lt;br&gt;
A. To uninstall a package, you can use the command 'pip uninstall package_name'. &lt;br&gt; &lt;br&gt;
Q. What is a virtual environment, and why should I use it?&lt;br&gt;
A. A virtual environment is an isolated python environment that allows you to install and manage dependencies separately from other projects. You should use it to avoid conflicts between different project dependencies. &lt;br&gt; &lt;br&gt;
Q. What is a requirements file, and how do I use it?&lt;br&gt;
A. A requirements file is a text file that lists the dependencies of a python project. You can use it to install all dependencies at once using the command 'pip install -r requirements.txt'. &lt;br&gt; 
&lt;/span&gt;&lt;br&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a name=&quot;conclusion&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;7-conclusion&quot;&gt;7. Conclusion&lt;/h2&gt;
&lt;p&gt;In this article we have covered some advanced package management techniques using &lt;strong&gt;pip&lt;/strong&gt;. You can use pip to install packages from &lt;strong&gt;PyPI&lt;/strong&gt;, local directories, or other sources like &lt;strong&gt;github&lt;/strong&gt;, &lt;strong&gt;gitlab&lt;/strong&gt;, etc. Pip allows you to install packages in &lt;strong&gt;virtual environments&lt;/strong&gt; to avoid any conflicts. Pip allows you to create &lt;strong&gt;requirements files&lt;/strong&gt; which is helpful to manage project dependencies at a larger scale. You can use &lt;strong&gt;environment markers&lt;/strong&gt; to install specific dependencies for certain environments. Pip helps you to install the packages in editable mode which is helpful in the development phase. Overall pip provides basic to advanced features to manage packages in python.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;references&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;8-references&quot;&gt;8. References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.python.org/3/library/venv.html&quot;&gt;https://docs.python.org/3/library/venv.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://pip.pypa.io/en/stable/reference/requirements-file-format/&quot;&gt;https://pip.pypa.io/en/stable/reference/requirements-file-format/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://peps.python.org/pep-0496/#:~:text=An%20environment%20marker%20describes%20a%20condition%20about%20the,constraints%20beyond%20the%20availability%20of%20a%20Python%20runtime.&quot;&gt;https://peps.python.org/pep&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>Mod &amp; Packages</category>
<guid isPermaLink="true">https://coderlegion.com/205/python-installing-external-packages-sources</guid>
<pubDate>Mon, 25 Mar 2024 10:49:52 +0000</pubDate>
</item>
<item>
<title>Python Installing External Packages with pip</title>
<link>https://coderlegion.com/204/python-installing-external-packages-with-pip</link>
<description>&lt;p&gt;&lt;a name=&quot;introduction&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;1-introduction-1&quot;&gt;1. Introduction&lt;/h2&gt;
&lt;p&gt;In python development, the utilization of various packages is a common practice. &lt;strong&gt;Pip&lt;/strong&gt; plays a vital role in managing these packages. In this article, we will be covering basic package management using &lt;strong&gt;pip&lt;/strong&gt; including installation, uninstallation, and upgrading of packages. &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;what-is-pip&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;what-is-a-pip-&quot;&gt;What is a pip?&lt;/h3&gt;
&lt;p&gt;Python has a rich ecosystem of libraries and packages. Managing these packages is crucial for any python developer, and that's where &lt;strong&gt;pip&lt;/strong&gt; comes into play. Pip is a standard package manager for python. It allows you to install packages from the &lt;a rel=&quot;nofollow&quot; href=&quot;https://pypi.org/&quot;&gt;Python Package Index&lt;/a&gt; and other indexes.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;history-and-evolution-of-pip&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;history-and-evolution-of-pip&quot;&gt;History and evolution of pip&lt;/h3&gt;
&lt;p&gt;First introduced as &lt;strong&gt;pyinstall&lt;/strong&gt; in &lt;strong&gt;2008&lt;/strong&gt; by &lt;strong&gt;Ian Bicking&lt;/strong&gt; (the creator of the virtualenv package) as an alternative to &lt;strong&gt;easy install&lt;/strong&gt;. Pip was chosen as the new name from one of several suggestions that the creator received in his blog post. According to Bicking himself, the name is a recursive acronym for &lt;strong&gt;&quot;Pip Installs Packages&quot;&lt;/strong&gt;. In 2011, the &lt;strong&gt;Python Packaging Authority&lt;/strong&gt; &lt;strong&gt;(PyPA)&lt;/strong&gt; was created to take over the maintenance of pip and virtualenv from Ian Bicking, led by Carl Meyer, Brian Rosner, and Jannis Leidel.&lt;/p&gt;
&lt;p&gt;Over the years, it has evolved into a standard package manager for python, offering enhanced features and performance. Major features include dependency resolution, version management, and integration with virtual environments.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;installing-pip&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;2-installing-pip&quot;&gt;2. Installing pip&lt;/h2&gt;
&lt;p&gt;&lt;a name=&quot;verify-python-installation&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;verify-python-installation&quot;&gt;Verify python installation&lt;/h3&gt;
&lt;p&gt;Before installing &lt;strong&gt;pip&lt;/strong&gt; verify that python is installed in your system by running the following command in the terminal/command prompt.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;windows&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;windows-3&quot;&gt;Windows&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;python --version&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=6242982192873945186&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;linuxmacos&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;linux-macos-3&quot;&gt;Linux/macOS&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;python3 --version&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=1892075831668570486&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;after running the command if it returns something like &lt;code&gt;Python 3.12.1&lt;/code&gt; then it means python is already installed in your system otherwise you can download it here &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.python.org/downloads/&quot;&gt;Download Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;installation-of-pip&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;installation-of-pip&quot;&gt;Installation of pip&lt;/h3&gt;
&lt;p&gt;Once python is installed you can proceed further to install pip by running the following commands in the terminal/command prompt.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;windows-1&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;windows-4&quot;&gt;Windows&lt;/h4&gt;
&lt;p&gt;Run the following command to download the get-pip.py script.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;Now execute the downloaded python script by running the following command.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;python get-pip.py&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;Finally, verify the installation by running the following command.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip --version&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;linux&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;linux&quot;&gt;Linux&lt;/h4&gt;
&lt;p&gt;Run the following command to download and install pip.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;sudo apt-get update&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;&lt;code&gt;sudo apt-get install python3-pip&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;You can verify the installation by running the following command.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 --version&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;macos&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;macos&quot;&gt;macOS&lt;/h4&gt;
&lt;p&gt;Run the following command to download the get-pip.py script.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;Now execute the downloaded python script by running the following command.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;python get-pip.py&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;Finally, verify the installation by running the following command.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 --version&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;basic-usage-pip&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;3-basic-usage-of-pip&quot;&gt;3. Basic usage of pip&lt;/h2&gt;
&lt;p&gt;&lt;a name=&quot;syntax-for-installing-packages-using-pip&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;syntax-for-installing-packages-using-pip&quot;&gt;Syntax for installing packages using pip&lt;/h3&gt;
&lt;p&gt;To install a package using &lt;strong&gt;pip&lt;/strong&gt; you have to follow the following syntax.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip install package_name&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can go more specifically when installing python3 packages to avoid potential conflicts as follows.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install package_name&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;installing-packages-using-pip-1&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;installing-packages-using-pip&quot;&gt;Installing packages using pip&lt;/h3&gt;
&lt;p&gt;Let's try to install a package named &lt;strong&gt;pandas&lt;/strong&gt; using pip.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install pandas&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you have followed the tutorial step by step, the pip will start installing &lt;strong&gt;pandas&lt;/strong&gt; after running the above command.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=14517782051803760204&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;You can also &lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/205/python-installing-external-packages-sources&quot; target=&quot;_blank&quot;&gt; install external packages &lt;/a&gt; and use them in your code other than available in &lt;strong&gt;Python Package Index&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;installing-specific-package-versions&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;4-installing-specific-package-versions&quot;&gt;4. Installing specific package versions&lt;/h2&gt;
&lt;p&gt;&lt;a name=&quot;specifying-package-versions&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;specifying-package-versions&quot;&gt;Specifying package versions&lt;/h3&gt;
&lt;p&gt;If you are a developer you might be working on existing projects that rely on specific versions of packages. In such cases, you have to install packages that are compatible with your project for that you have to specify the package version while installing it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install package_name==version&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Let's say you want to install &lt;strong&gt;pandas&lt;/strong&gt; version 1.3.4 here's how you will do it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install pandas=1.3.4&lt;/code&gt;&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=17553160961951298095&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;specifying-package-version-ranges&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;specifying-package-version-ranges&quot;&gt;Specifying package version ranges&lt;/h3&gt;
&lt;p&gt;Similarly, you can specify the minimum and maximum version ranges.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install package_name&amp;gt;=min_version&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;It will install the package of version equal to or greater than &lt;code&gt;min_version&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install package_name&amp;lt;=max_version&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;It will install the package of version equal to or less than &lt;code&gt;max_version&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can use the above syntax to install packages in the specified range.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install pandas&amp;gt;=1.3.4&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The above command will install a pandas version equal to or greater than &lt;code&gt;1.3.4&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=3289499676729900093&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;upgrading-and-uninstalling-packages&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;5-upgrading-and-uninstalling-packages&quot;&gt;5. Upgrading and uninstalling packages&lt;/h2&gt;
&lt;p&gt;Often while working with python you have to upgrade packages or remove the packages from your project so let's see how you can do that using &lt;strong&gt;pip&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;upgrading-packages&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;upgrading-packages&quot;&gt;Upgrading packages&lt;/h3&gt;
&lt;p&gt;To upgrade an existing package using pip you can follow the below syntax.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install --upgrade package_name&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;or&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;&lt;code&gt;pip3 install -U package_name&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can upgrade your packages by following either of the syntax. Let's upgrade the &lt;strong&gt;pandas&lt;/strong&gt; package to the latest version.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install --upgrade pandas&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;or&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;&lt;code&gt;pip3 install -U pandas&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=3793111574261019960&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Both commands will upgrade the pandas to the latest version you can use either of them.  &lt;/p&gt;
&lt;div class=&quot;div-green&quot;&gt;
&lt;span class=&quot;alert-header&quot;&gt;Tip:&lt;/span&gt;
&lt;span class=&quot;alert-body&quot;&gt;The command 'pip3 install -U pandas' will also install the pandas if it does not exist in your project&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a name=&quot;upgrading-pip-1&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;upgrading-pip&quot;&gt;Upgrading pip&lt;/h3&gt;
&lt;p&gt;You can upgrade the &lt;strong&gt;pip&lt;/strong&gt; using pip itself, yea it looks odd but trust me it works considering the syntax below.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 install --upgrade pip&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;or&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;&lt;code&gt;pip3 install -U pip&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=16457708622499222664&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;As we discussed before, you can follow either syntax to upgrade the pip.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;uninstalling-packages&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;uninstalling-packages&quot;&gt;Uninstalling packages&lt;/h3&gt;
&lt;p&gt;You can uninstall a package by using the following syntax.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 uninstall package_name&lt;/code&gt;&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;Let's try to uninstall &lt;strong&gt;pandas&lt;/strong&gt; using the above syntax.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pip3 uninstall pandas&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=11486672624817789753&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;div class=&quot;div-green&quot;&gt;
&lt;span class=&quot;alert-header&quot;&gt;Tip:&lt;/span&gt;
&lt;span class=&quot;alert-body&quot;&gt;You can upgrade and uninstall multiple packages at the same time as : 'pip install --upgrade package_name_1 package_name_2...' and 'pip uninstall package_name_1 package_name_2...'&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a name=&quot;conclusion&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;6-conclusion&quot;&gt;6. Conclusion&lt;/h2&gt;
&lt;p&gt;In this article, we discussed &lt;strong&gt;Pip&lt;/strong&gt; as the standard package manager in Python, emphasizing its versatility in package installation, upgrading, and removal. Through commands like &lt;strong&gt;&lt;code&gt;pip3 install package_name&lt;/code&gt;&lt;/strong&gt; for installation and &lt;strong&gt;&lt;code&gt;pip3 install --upgrade package_name&lt;/code&gt;&lt;/strong&gt; for upgrades, &lt;strong&gt;Pip&lt;/strong&gt; facilitates efficient package management. Furthermore, we explored installing specific package versions and uninstalling packages using &lt;strong&gt;&lt;code&gt;pip3 uninstall package_name.&lt;/code&gt;&lt;/strong&gt; Looking ahead, in the next article we will dive into advanced &lt;strong&gt;Pip&lt;/strong&gt; usage.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;references&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;7-references&quot;&gt;7. References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://logiclair.org/1803/modules-and-packages%26gt-installing-external-packages-with-pip-2&quot;&gt;Modules and Packages Installing External Packages with pip 2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://en.wikipedia.org/wiki/Pip_(package_manager)&quot;&gt;https://en.wikipedia.org/wiki/Pip_(package_manager)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://packaging.python.org/en/latest/tutorials/installing-packages/&quot;&gt;https://packaging.python.org/en/latest/tutorials/installing-packages/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>Mod &amp; Packages</category>
<guid isPermaLink="true">https://coderlegion.com/204/python-installing-external-packages-with-pip</guid>
<pubDate>Mon, 25 Mar 2024 10:44:19 +0000</pubDate>
</item>
</channel>
</rss>