Install and create virtualenv via terminal
Published: 2022-03-12 19:33:30

What virtual environment is? Let's jump into this topic. I'll try to explain it as simplistic as possible with some comparison and plain explanatory style.

Imagine your system is some sort of space you are executing your programs. It's a space where you run some sort of other stuff you would like to work with. There are plenty of other things you can run from a developer's perspective. Each of these things can be installed on your system. But what will happen when you'll install each of this dev stuff on your system. Yes, that can be a quite big mass I would say. And in some cases, there can happen even version conflict someday.

So to avoid this there is a simple solution. That's why the virtual environment comes to play. As naming sayin' it will create some sort of virtual box for dev stuff you would like to install. It can be anything, python3, Django or your next flask project with a specific setup.

Note: If you have already installed some dev tools you can simply skip the "Install Xcode with Homebrew" section for sure cos there is a high probability you have it on your system.

##Install Xcode with Homebrew
This step is just easy simple copy-paste work. Simply paste this "looong" command from [brew.sh](https://brew.sh/) website and hit enter to execute.

```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

Some stuff will flick in front of you in the terminal and then you'll be asked for the next step.

```
Press RETURN to continue or any other key to abort
```

After this, you'll be asked for a system password to enter into the terminal to continue. At this stage be patient. There will be a quite long time to download all stuff and you'll be notified about it with this simple info text.

```
Downloading Command Line Tools for Xcode
```

Then you'll be notified with this pop-up tiny window to install some other Command-Line for Xcode.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/nyxzgm6esepblvdd47jz.png)


```
Installing Command Line Tools for Xcode
```
And then after all process when it's done you'll see this.

```
Done with Command Line Tools for Xcode
Done.
```
And be asked for the password again. Then after waiting please for Homebrew's instalment of its core stuff.

The last thing you'll be notified of is this terminal output. And it's all done. I hardly recommend restarting the whole system cos I have recognized virtual environment installation issues without having passed such.

```
==> Next steps:
- Run `brew help` to get started
- Further documentation: 
    https://docs.brew.sh
```


##Install Virtual Environtment
This is simple straight forward. Just execute <code>pip3 install virtualenv</code> with <code>sudo</code> command.

```
sudo pip3 install virtualenv
```

##Create First Environment
Let's start to create the first general main directory with the name "virtualenvs" and enter it in the directory. 

```
mkdir virtualenvs
cd virtualenvs
```

In this example, I'll create a virtual environment for Flask which is simply a Python-based system for quick web app development. But it can be anything else you would like to have in a separate work environment and you can name it whatever you want to.

Because of this purpose, we going to install the Flask directory name will be the same.

```
virtualenv flask
```
This will create <code>flask</code> directory as space for virtual environment. We are going to activate this virtual environment for the further installation process. In other words, we will activate this environment to be able to install inside directory other python dependencies and libraries for further steps. 

In this case for activation of the environment just type this command.

```
source flask/bin/activate
```

You'll recognize your command prompt starting with <code>(flask)</code> it means your virtual environment has been activated.

To deactivate virtual environment just type <code>deactivate</code>.

```
deactivate
```

At this point, tut could end. Activated <code>flask</code> environment is at its final. And now in the next step, you can install Flask, Python, Scrapy or whatever you would like to into your separated virtual environment.

Thanks to [Michał Parzuchowski](https://unsplash.com/photos/ChqyREhd6aE?utm_source=unsplash&utm_medium=referral&utm_content=CreditCopyTextGratitude) for the cover image from Unsplash.