-1

I am learning Django. I installed two different versions of python on my laptop, 2 and 3. I configured my Laptop to use Python 3, so when I check version using the command line, I got this output.

enter image description here

Then, I installed the Django and Python Virtual Environment following this link. I could install the Django and Virtual Environment successfully. But my virtual environment is using the python 2. When I check the version in the virtual environment, I got this output.

enter image description here

So, how can I configure that virtual environment to use python 3 instead of 2? Or how can I set the Python version to be used when I set up the Environment for the Django?

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372

4 Answers4

1

Virtualenv with python 2

virtualenv myEnv

Virtualenv with python 3

virtualenv -p python3 myEnv
Ali
  • 2,541
  • 2
  • 17
  • 31
0

If you are on Linux just use the command python3 -m venv myvenv in the directory of your project and you're done!

flpn
  • 1,868
  • 2
  • 19
  • 31
0

Execute below command line:->

For Python3 :->

virtualenv --python = $(which python3) EnvironmentName

For Python2 :->

virtualenv --python = $(which python) EnvironmentName
0

If you want to use Python 3, the recommended way to create a virtual environment is using python3 -m venv as follows:

python3 -m venv venv # this will create a virtual environment called venv

In your case, you can directly use python instead of python3 since you have already configured your laptop to use Python 3 when running python (this is shown in your question).

In Windows, to activate this virtual environment run the following:

venv\Scripts\activate.bat

That's it!

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228