close

How to specify python version used to create Virtual Environment?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to specify python version used to create Virtual Environment in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to specify python version used to create Virtual Environment?

  1. How to specify python version used to create Virtual Environment?

    Assuming that you have installed python3 or any desired version of Python (2.6, 2.7, 3.5, 3.6), Now while creating the virtual environment directly pass the python executable path.

  2. specify python version used to create Virtual Environment

    Assuming that you have installed python3 or any desired version of Python (2.6, 2.7, 3.5, 3.6), Now while creating the virtual environment directly pass the python executable path.

Method 1

Assuming that you have installed python3 or any desired version of Python (2.6, 2.7, 3.5, 3.6), Now while creating the virtual environment directly pass the python executable path. Hence here are few valid example

$ virtualenv new_p2_env # Creates a new default python environment (usually python 2)

$ virtualenv -p python3 new_p3_env # Creates a new default python3 (python3 must be a valid command i.e found in the PATH) 

And last

# Directly point to any version of python binary, this can be even another virtualenv's bin/python. 
$ virtualenv -p /path/to/any/bin/python new_env 

Method 2

Alternatively, I think you could use the specific version of Python itself to create the virtual environment. That way, you’ll know for sure it’s the correct version:

$ python3.5 -m venv test35
$ ./test35/bin/python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25)
[GCC 4.2.1 (Apple Inc. build ) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read