Create Python3 virtual environment in Ubuntu and Mac

Ubuntu:

To install python3.6 in Ubuntu, follow this link

Now to create virtual environment first we need to install virtualenv using pip, run below command to do the same:

pip install virtualenv

Run the below command to create virtual environment in the folder venv:

virtualenv -p python3.6 venv

You can activate the virtual environment and check the python version by running below commands:

source venv/bin/activate
python --version

Deactivate virtual env by:

deactivate

Mac

To install python3 on mac follow this link

In mac it’s very easy to create the virtual environment, just run below command to create it in the folder venv:

python3 -m venv venv

You can activate the virtual environment and check the python version by running below commands:

source venv/bin/activate
python --version

Deactivate virtual env by:

deactivate

P.S.

fish

If you are using fish instead of bash, then to activate virtual environment run the below command:

source venv/bin/activate.fish

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.