Configuring Python Virtual Environment to use Pyth

2019-02-21 06:54发布

问题:

I am learning the Python Django framework. 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.

Then I installed the Django and Python Virtual Environment following this link, https://djangobook.com/installing-django/. 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.

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?

回答1:

Virtualenv with python 2

virtualenv myEnv

Virtualenv with python 3

virtualenv -p python3 myEnv


回答2:

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



回答3:

Execute below command line:->

For Python3 :->

virtualenv --python = $(which python3) EnvironmentName

For Python2 :->

virtualenv --python = $(which python) EnvironmentName