I'm working in a shared machine with no root privileges, but Python 2.y installed, but I would like to have both flavors of Python, also I would like to call Python 2.y just typing python (as usual) and for calling Python 3.x, type python3. I understand that this is possible because in my main equipment (whit root access, and the magic of sudo) I can "select" which one to use.
Asked
Active
Viewed 1.2k times
3
-
I don't know about automatically installing it but if building it from sources you could pass `--prefix` and `--exec-prefix` to `configure`, pointing to a folder where you have r/w/e perms, and then instead of `make install`, `make altinstall`. – CristiFati Nov 24 '17 at 05:00
-
One way is to use virtual environments. Now that python 2 is already there all you need is create a virtual Environment in python 2 and install python 3 inside that. Other way is to use like you said in the question call python 3 as "python3" and "python" or "python2" for python 2. – WaterRocket8236 Nov 24 '17 at 05:49
3 Answers
8
You can install pyenv with the pyenv installer script and then run pyenv install 2.7.14
and pyenv install 3.6.3
.
Some more documentation is here

Imran
- 12,950
- 8
- 64
- 79
-
3If you are following the `Basic GitHub Checkout`, then on Step 4 restarting the shell with `exec "$SHELL"` may not work depending on how the machine you are connected to is setup. Simply disconnecting from the ssh session and connecting back makes it work, and then you can use `pyenv install`. For example, `pyenv install 3.6.6` installs python3.6.6, then you can do `pyenv global 3.6.6` and now calling `python` or `python3` will take you to python3.6.6. – Guilherme Salomé Oct 20 '18 at 12:57
0
You can safely install Python as a Local / Non-root user by executing the below code with the required Python Version defined in the variable "PYTHON_VER"
# Install Python3 and Libraries as a local user.
python_config() {
export PYTHON_VER="3.10.5"
export PYTHON_VER_SHORT="$(echo ${PYTHON_VER} | cut -d '.' -f1,2)"
cd ~
rm -rf ~/python && mkdir -p ~/python
echo "" >> ~/.bashrc
echo "export PATH=~/python/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
wget --quiet --no-check-certificate "https://www.python.org/ftp/python/${PYTHON_VER}/Python-${PYTHON_VER}.tgz"
tar -zxvf ~/Python-${PYTHON_VER}.tgz 1>/dev/null
cd ~/Python-${PYTHON_VER}/
echo "Python ${PYTHON_VER} - Installing in current logged-in user - $(whoami)"
echo "Python ${PYTHON_VER} - Installation in-progress. Please wait..."
./configure --enable-optimizations --prefix=$HOME/python > /dev/null 2>&1;
echo "Python ${PYTHON_VER} - ETA: upto 5mins. Please wait..."
make altinstall > /dev/null 2>&1;
ln -s ~/python/bin/python${PYTHON_VER_SHORT} ~/python/bin/python3
ln -s ~/python/bin/pip${PYTHON_VER_SHORT} ~/python/bin/pip3
wget --quiet --no-check-certificate https://bootstrap.pypa.io/get-pip.py -O - | python3 - --prefix=$HOME/python
source ~/.bashrc
~/python/bin/pip3 install --upgrade pip
~/python/bin/pip3 install --upgrade pygithub
~/python/bin/pip3 install --upgrade --no-cache-dir -r /tmp/requirements.txt --use-pep517
cd ~ && rm -rf ~/Python-${PYTHON_VER}*
~/python/bin/python3 --version
~/python/bin/pip3 --version
echo "Python ${PYTHON_VER} - Setup Completed!"
}
# Function Call
python_config

M.S. Arun
- 1,053
- 13
- 22
-2
One can install Anaconda for python3 locally, but it seems to be a little bit overkill :)

andywiecko
- 306
- 3
- 16