Reputation: 23
I use debian and I have python 3.5.3 installed. I am going to work on a project which requires python 3.6, but the last time I installed python 3.6 on my computer it broke a lot of things, so I would like to avoid that. What I want is to create a virtual environment which runs python 3.6, but without affecting my python 3.5 installation.
I know that the virtualenv command has an option to specify which python to use, but this would only work if I have a python 3.6 executable on my computer. Is there a way to install the virtualenv without having the python 3.6 executable installed ? If not, is it possible to install python 3.6 without getting rid of python 3.5 ?
In case you're wondering, this is the procedure I followed to install python 3.6, which broke a bunch of stuff. Since then I've re-installed my OS for other reasons, and now I'm back on python 3.5.
Upvotes: 2
Views: 2289
Reputation: 23
Install supporting softwares
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
Download required python version in the /tmp
directory
I'm assuming you are going to install Python 3.6.12
cd /tmp
wget https://www.python.org/ftp/python/3.7.5/Python-3.6.12.tgz
tar -xf Python-3.6.12.tgz
cd Python-3.6.12.tgz
Install python version
./configure --enable-optimizations --enable-loadable-sqlite-extensions
sudo make altinstall
Note
There are two ways to install python one is altinstall
and the other one is install
altinstall
is the preferred method since it will not overwrite the existing default python version
Now since you followed altinstall
method, In the terminal, you can see multiple python versions
>> python --version
Python 2.7.18
>> python3.5 --version
Python 3.5.10
>> python3.6 --version
Python 3.6.12
Now to create virtual environment of version 3.6
cd ~/home/location/
python3.6 -m venv <virtual_environment_name>
source virtual_environment_name/bin/activate
Upvotes: 0
Reputation: 1873
I'm interested in knowing how else to do this. But I personally use conda
.
You can create other Python environments without having to installing it first because it's included in the anaconda
metapackage.
If you look at my default system you see that it's only Python 2 available.
$ cd /usr/bin/ | ls | grep python
-rwxr-xr-x 1 root root 11224 Sep 1 2016 abrt-action-analyze-python
-rwxr-xr-x 1 root root 7136 May 3 2017 python2.7
lrwxrwxrwx 1 root root 9 Dec 9 13:27 python2 -> python2.7
lrwxrwxrwx 1 root root 7 Dec 9 13:27 python -> python2
If you have conda installed then you can use the below to create a venv, activate it, and then you see you're using a different Python that's not installed on your file system.
conda create -n py35 python=3.5 anaconda
$ source activate py35
py35 $ python --version
Python 3.5.3 :: Anaconda 4.4.0 (64-bit)
Upvotes: 1
Reputation: 131
Check out pyenv (https://github.com/pyenv/pyenv). After you install pyenv, you can use something like the following to install a specific python version:
pyenv install 3.6.4
Then you can use this python version with pyenv global
, pyenv local
, or pyenv virtualenv
commands.
Upvotes: 3