
Virtualenv 20.0.30 from /home/ec2-user/.local/lib/python3.7/site-packages/virtualenv/_init_.py The following command confirms that virtualenv is installed successfully: ~]$ virtualenv -version This command would fail if we don’t pass the –user flag because ec2-user doesn’t have access to install packages in the system Python library. The –user flag tells pip to install the virtualenv package in a local directory inside the home directory of the current user (ec2-user). Successfully installed virtualenv-20.0.30 Installing collected packages: virtualenv Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/site-packages (from importlib-metadata=0.12 python_version virtualenv) Requirement already satisfied: importlib-metadata=0.12 python_version =3.0.0 in /usr/local/lib/python3.7/site-packages (from virtualenv) Requirement already satisfied: distlib=0.3.1 in /usr/local/lib/python3.7/site-packages (from virtualenv) Requirement already satisfied: six=1.9.0 in /usr/local/lib/python3.7/site-packages (from virtualenv) Requirement already satisfied: appdirs=1.4.3 in /usr/local/lib/python3.7/site-packages (from virtualenv) The first step to create a virtual environment is to install the virtualenv package using pip: ~]$ pip install virtualenv -user The versions on your system might differ from those depending on your Linux distribution and version.

Pip 9.0.3 from /usr/lib/python3.7/site-packages (python 3.7)Īs you can see I have Python 3.7.8 and PIP 9.0.3 on my system. bashrc for the ec2-user to refer to python3 and pip3 simply as python and pip: alias python=python3įirst of all, I will confirm that Python and PIP are installed: ~]$ python -version The concepts are very similar for Mac and Windows, certain commands are slightly different on Windows.įirstly, I have created two aliases inside. The examples I will be showing here are based on Linux. How Do You Create a Virtual Environment in Python? Running both projects using the system Python environment would not be possible and that’s where virtualenv can help.

Using virtual environments allows you to manage multiple projects without risking Python dependencies of one project to break another project.Ī simple example is the scenario in which ProjectA requires version 1.0.0 of a package and ProjectB only works with version 1.1.0 of the same package. Virtualenv…here we go! Why Would You Use a Virtual Environment in PythonĪs explained in the previous section Python virtualenv allows you to create an environment that contains all the dependencies (packages) needed by Python to execute projects.Ī virtual environment is a single directory that can be created as I explain in the next section.
