Activate and Deactivate Your Virtual Environment

All commands you need to remember for the creation, activation, and deactivation of Virtual Environment on mac

Open your terminal:

pip3 install virtualenv

If you already have, it will give you this:

If you don't have, get it by:

pip3 install virtualenv

2. Create a folder for your virtual environments, where you want on your machine:

cd /Users/maryammehboob/VirtualEnv

3. Make directory for the current project there, which you gonna start:

mkdir dir_name

4. Start virtual environment, it will generate some files in your folder.

virtualenv  dir_name

If it says:

command not found: virtualenv

Then you have to execute virtualenv package from its location. You can get your virtualenv location from running pip3 show virtualenv.

Now, you have to run this command by giving your virtualenv package location.

python3 /Users/maryammehboob/Library/Python/3.8/lib/python/site-packages/virtualenv dir_name

5. Move into the project directory, that you created above.

cd dir_name

6. Activate your VE by:

source bin/activate

8. You can confirm which python your VE is using by:

which python

9. After working, deactivate using:

deactivate

Create requirenment.txt file in your VE:

To create requirenment.txt file in your VE.

pip freeze > requirements.txt

To install all dependencies present in requirnment.txt file.

pip install -r requirements.txt

Create your new python file in VE folder:

touch file_name.py

And run it by:

python file_name.py

Thats all you need.

Happy Coding!

Learner.