Install update or remove packages/libraries in Python
-
Python uses the concept of modularization and this is achieved using Python Libraries/Packages.
Python itself has many built-in libraries like datetime, math etc.
In addition to this, there are tons of third-party libraries, which will be required in our projects.
And these libraries can have multiple versions as well.
All the open source and licensed packages and its different versions are listed in Python Package Index repository. We can use the pip command to install a package which is available in this repository. -
Installation commands
pip install by default installs the latest version of the package.
These are also options to select a particular version as below.To install:
pip install PackageName or python -m pip install PackageName
For specific version:
pip install PackageName==3.0.2
For min version:
pip install PackageName>=3.0.2
For upgrade:
pip install -upgrade PackageName
To remove:
pip uninstall PackageName -
To use older python versions
Some times, it may be required to work with older versions of Python and the packages installed should be compatible with this version.
Use commands in below format to do this.For Windows:py -3.3 -m pip install PackageNamefor python 3.3 versionpy -3 -m pip install PackageNamefor latest 3.x version available in your machineFor Linux, macOS, etc:python3.3 -m pip install PackageNamefor python 3.3 versionpython3 -m pip install PackageNamefor latest 3.x version available in your machine