Slider Revolution Plugin For WordPressOctober 22, 2021
Studies And Online Courses To Better YourselfNovember 30, 2021
pip --version. If you get an error it is highly advisable that you update your Python version, as opposed to installing pip separately.
To install packages using pip you simply type
pip install [packageName] into your command line and pip will install your package for you. This package will now be available in any of your Python projects as long as you import it. Unlike npm which installs its dependencies locally pip will install its packages globally by default. When you have multiple projects that you’re working on, or collaborative projects it is better to keep the packages within their projects and not all global on your system. This is where and why we use virtual environments.
The virtual environment is a package that is installed through pip using the command
pip install virtualenv. Pip will install the virtualenv package, which you will then use to create local environments for each of your projects. The local environments mean that you limit the number of times you hear things like ‘but it worked on my machine’. Once we have virtualenv installed we must create a virtual environment for our project. We’ll setup a new project from scratch to illustrate this.
Firstly, we’ll create a new folder on our filesystem to house the new project. Once we have our project folder, we need to create our virtual environment within the project folder. To do this we type
virtualenv [environmentName]. The standard is to just call your virtual environment “venv”. Once virtualenv has setup our virtual environment we need to activate it. This will differ depending on your operating system. In Powershell you would activate the venv by typing
.\[environmentName]\Scripts\activate.ps1, in cmd you would replace “.ps1” with “.bat”. In Linux you activate the environment by typing
source ./venv/bin/activate. To leave your virtual environment you simply type
In my next blog post I’ll talk about git, security, and dotenv files. Check out https://pypi.org/ to have a look at all the packages available for installation through pip.