Managing your packages in Python can be a cumbersome task. This article discusses useful commands and provides resources to help manage your packages using pip and the difference between pipenv and virtualenv. We will also cover a powerful framework named Django.
What is pip? Pip is a useful package manager. Pip is a recursive acronym that can stand for “Pip Installs Packages” or “Pip Installs Python”. Alternatively, pip stands for “preferred installer program”.
How to Update a Package
In the following paragraphs, the focus will be on how to update existing packages in Python using the package manager pip.
First, make sure you have pip installed by running pip –version in your terminal. If you installed Python using Homebrew or with an installer from python.org, you should have pip. If you are on Linux, you may have to install pip separately. Take a look at our article. It guides you on how to install pip on your machine.
To update an existing package in your pipfile, use pip install –upgrade PackageName to install the latest version of your package. If there is a specific version of the package you want installed then type the version after the package name. Refer to the following example on how to include the exact version needed for your project/application (eg. pip install –upgrade PackageName==1.4).
How to Install Dependencies from Your Pipfile
Pipenv is a dependency manager for Python projects. It’s similar to Node.js npm and Ruby’s bundler. While pip can install Python packages, pipenv is a preferred tool used for managing dependencies because it is easier. Install pipenv using this pip command in your terminal by inputting: pip install –user pipenv. This command does a user installation to prevent damaging any system-wide packages. If pipenv is not available in your terminal/shell after installation, then you need to add the user base’s binary directory to your PATH. To install dependencies from a pipfile, use the command pipenv sync.
Pipenv vs a Virtual Environment
A virtual environment (Virtualenv) is used to create remote Python environments. Virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project might need. It can be used as a standalone instead of pipenv. Use the command pip install virtualenv in your terminal to install the virtual environment.
Test it’s installation by running the command Virtualenv –version in your terminal. A virtual environment is used so that you don’t change the versions of other projects that may be incompatible with the existing packages in other projects system wide. On the other hand, pipenv is used to manage your dependencies according to the requirements on a project by project basis.
Django and Python
Django and Python go hand in hand in backend development. Python is powerful and concise, while Django is a web framework with a lot of useful tools like the command line tool Django-admin.
If you don’t have Django installed already, install it using the command, pip install Django. When creating your project using the Django web framework, a command line tool named django-admin will be installed. Utilize the command Django-admin startproject project_name to start the project. Find useful tips and resources by reading our article.
In this article, we’ve discussed how to update a package using pip and how to install dependencies from a pipfile in an existing project, the differences between pipenv and virtualenv and their uses, and Django, a powerful framework that complements Python.
There are also a few resources available to take a deeper dive into relevant topics. You are well on your way to mastering managing your Python packages!
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.