Skip to content

Commit

Permalink
vitrual env
Browse files Browse the repository at this point in the history
  • Loading branch information
Asabeneh committed Jul 8, 2021
1 parent be71350 commit ec2a79e
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions 23_Day_Virtual_environment/23_virtual_environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

<sub>Author:
<a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br>
<small> First Edition: Nov 22 - Dec 22, 2019</small>
<small> Second Edition: July, 2021</small>
</sub>

</div>
</div>

[<< Day 22](../22_Day_Web_scraping/22_web_scraping.md) | [Day 24 >>](../24_Day_Statistics/24_statistics.md)
Expand All @@ -30,9 +28,11 @@
To start with project, it would be better to have a virtual environment. Virtual environment can help us to create an isolated or separate environment. This will help us to avoid conflicts in dependencies across projects. If you write pip freeze on your terminal you will see all the installed packages on your computer. If we use virtualenv, we will access only packages which are specific for that project. Open your terminal and install virtualenv

```sh
asabeneh@Asabeneh:~/Desktop/30DaysOfPython/flask_project$ pip install virtualenv
asabeneh@Asabeneh:~$ pip install virtualenv
```

Inside the 30DaysOfPython folder create a flask_project folder.

After installing the virtualenv package go to your project folder and create a virtual env by writing:

For Mac/Linux:
Expand All @@ -43,27 +43,33 @@ asabeneh@Asabeneh:~/Desktop/30DaysOfPython/flask_project\$ virtualenv venv

For Windows:
```sh
C:\Users\User\Documents\30DaysOfPython\flask_project>python3 -m venv venv
C:\Users\User\Documents\30DaysOfPython\flask_project>python -m venv venv
```

I prefer to call the new project venv, but feel free to name it differently. Let's check if the the venv was created by using ls (or dir for windows command prompt) command.
I prefer to call the new project venv, but feel free to name it differently. Let us check if the the venv was created by using ls (or dir for windows command prompt) command.

```sh
asabeneh@Asabeneh:~/Desktop/30DaysOfPython/flask_project$ ls
venv/
```

Let's activate the virtual environment by writing the following command at our project folder.
Let us activate the virtual environment by writing the following command at our project folder.

For Mac/Linux:
```sh
asabeneh@Asabeneh:~/Desktop/30DaysOfPython/flask_project$ source venv/bin/activate
```
For Windows:
Activation of the virtual environment in Windows may very on Windows Power shell and git bash.

For Windows Power Shell:
```sh
C:\Users\User\Documents\30DaysOfPython\flask_project> venv\Scripts\activate
```

For Windows Git bash:
```sh
C:\Users\User\Documents\30DaysOfPython\flask_project> venv\Scripts\. activate
```

After you write the activation command, your project directory will start with venv. See the example below.

Expand All @@ -73,13 +79,13 @@ After you write the activation command, your project directory will start with v

Now, lets check the available packages in this project by writing pip freeze. You will not see any packages.

We are going to do a small flask project so let's install flask to this project.
We are going to do a small flask project so let us install flask package to this project.

```sh
(venv) asabeneh@Asabeneh:~/Desktop/30DaysOfPython/flask_project$ pip install Flask
```

Now, let's write pip freeze to see a list of installed packages in the project:
Now, let us write pip freeze to see a list of installed packages in the project:

```sh
(venv) asabeneh@Asabeneh:~/Desktop/30DaysOfPython/flask_project$ pip freeze
Expand All @@ -104,4 +110,5 @@ The necessary modules to work with flask are installed. Now, your project direct
1. Create a project directory with a virtual environment based on the example given above.

🎉 CONGRATULATIONS ! 🎉

[<< Day 22](../22_Day_Web_scraping/22_web_scraping.md) | [Day 24 >>](../24_Day_Statistics/24_statistics.md)

0 comments on commit ec2a79e

Please sign in to comment.