0

I have read this post but I think it is about using python2 or python3 inside virtual environment. My problem is bit different, I want to different version of python 3 itself inside virtual environment.

I am using Ubuntu 18.04. I have three different versions of python 3 in my system and all of them seem to work.

They can be started by mentioning specific python version. eg: python3.6, python3.7, python3.8.

But simply typing python3 will load python 3.7 because it is Anaconda's python version.

sankethbk7777@Lenovo-ideapad:/$ which python3
/home/sankethbk7777/anaconda3/bin/python3

However I want to create a virtual environment with python 3.8 as python version inside it. (I mean inside my virtual env if I type python3 - python3.8 should boot up).

I tried using this command.

sankethbk7777@Lenovo-ideapad:/$ sudo python3.6 -m venv myproject
sankethbk7777@Lenovo-ideapad:/$ source myproject/bin/activate
(myproject) sankethbk7777@Lenovo-ideapad:/$ python3
Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Above we can see that it boots python 3.6 when I type python3.

But when I tried the same for python3.8 this error shows up.

sankethbk7777@Lenovo-ideapad:/$ sudo python3.8 -m venv myproject3
Error: Command '['/myproject3/bin/python3.8', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

However, I have a working python3.8.

sankethbk7777@Lenovo-ideapad:/$ python3.8
Python 3.8.7 (default, Dec 21 2020, 20:10:35) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
sankethbk7777@Lenovo-ideapad:/$ which python3.8
/usr/bin/python3.8

I will provide any further information please help me with this.

Sanketh B. K
  • 759
  • 8
  • 22

1 Answers1

0

Looks like you have Anaconda distribution of Python. I'd simply create a conda virtual environment with the version of Python you need -

conda create -n py38 python=3.8

That should create a conda virtual environment named py38 with Python version 3.8 To activate it,

conda activate py38

And that should give you Python version 3.8

Heapify
  • 2,581
  • 17
  • 17
  • I am working on django project, so i want to use python's virtual environment. Anaconda's virtual environment are more suitable for data science projects. – Sanketh B. K Jan 11 '21 at 05:56
  • It doesn't look like it's possible to get a different version of Python from the base Python version with venv. But, you'll be able to do that with conda. Both are Python virtual environments regardless of if they are created from venv or conda, and can be used in anyway users want (datascience or non datascience, doesn't matter). – Heapify Jan 13 '21 at 21:45