Install python 2.6 in a sandbox/virt-env - python

I have python 2.7 running on ubuntu 14.04. and, I need to set up py2.6 in a sandbox environment. I tried using the command, virtualenv as
virtualenv /path/to/sandbox --no-site-packages
But, it copies /usr/bin/python2.7 binary file into the sandbox's bin folder.
Using pythonbrew also didn't work, as it throws compilation errors almost always.
How to create a sandbox environment and install python2.6 binary in it?

Virtualenv won't really install a new python version from scratch, but rather copy one of the versions installed on your system. That's why you first need to get a python2.6 binary for Ubuntu 14.04. It seems they don't officially support python2.6 anymore, so either you manually download and install it from http://python.org or use a ppa like this:
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.6
afterwards you can tell virtualenv to use python2.6 like this:
virtualenv -p python2.6 --no-site-packages /path/to/sandbox

Related

After deleting python in ubuntu 18.04 terminal and some other functionalities does not work

I am using Ubuntu 18.04 in my work computer. I have never used Python2 versions before and it was annoying me to have in my computer because whenever I try to install something related Python I got issue even my default version Python3.6
I could not install pip, I could not install some packages so I wanted to delete Python completely from my computer. However now I can not install any python and getting lots of errors while trying several methods which are shared before on this platform and other websites.
Currently my terminal does not work so I use Xterm.
python --version
bash /usr/lib/command-not-found: /usr/bin/python3: bad interpreter: No such file or directory
whereis python
python: /usr/lib/python2.7 /usr/local/lib/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
sudo apt install python-minimal
sudo apt --fix-broken install
sudo apt update
I have tried many things I have seen on the web but could not fix. Also I am user in this computer so I do not have root access. Just wanted to know how to fix.

Change python version in google colab which is connected with google cloud

I am using python 3.7 in google colab, but for some reason when I am connected with a linux server in google cloud the python becomes 2.7. How can I change it? Note that python 3.7 is already installled in the server.
I tried these things but weren't helpful.
apt update
sudo apt install python3-pip
alias pip='pip3'
I checked also these sites https://cloud.google.com/python/docs/setup#linux_2, How do I install Python 3.7 in google cloud shell but didn't solve my problem.
Edit
By doing Runtime --> Change runtime I can see only this, which the options are 'non', 'gpu', 'tpu'.
You can check your Python version at the command line by running python --version. In Colab, we can enforce the Python version by clicking Runtime -> Change Runtime Type and selecting python3.
Python 2.7 is expected to be removed in Debian "testing", the basis of gLinux. This is expected to happen shortly after the next major version, Debian Bullseye, is released.
You need to migrate Python 2.7 code to Python 3 and remove python-is-python2 packages you might have installed.
When Python 2.7 is removed from gLinux, python-is-python2 will be uninstalled.
If you have software that requires /usr/bin/python to work, but can be used with Python 3, you should install python-is-python3.
You can change Python version by running the following commands in terminal:
pip install virtualenv
virtualenv venv --python=python3
This only works if you have Python2.7 installed at the system level (e.g. /usr/bin/python2.7).
You can find the path to your Python installation with
which python3
virtualenv venv --python=/usr/local/bin/python3
And check the version using python3 –version.
So actually the answer of my question comes from this post How to completely uninstall python 2.7.13 on Ubuntu 16.04.
Everyone who have a similar problem the first thing that he/she should do is to unistall python 2.7 by using either
sudo apt install --reinstall python python-apt python2.7-minimal
or
sudo apt purge python2.x-minimal
and then install python 3.7, by using
sudo ln -s /usr/bin/python3 /usr/bin/python
sudo apt install -y python3-pip
sudo ln -s /usr/bin/pip3 /usr/bin/pip
# Confirm the new version of Python: 3
python --version

How to downgrade ubuntu to python 3.6?

I'm trying to install an older version of tensorflow and it needs python3.6 to support the whl file of installation.
I'm now running Ubuntu 20.04 with python 3.8.5, I've already done this :
sudo add-apt-repository ppa:deadsnakes/ppa
followed by :
sudo apt-get update
sudo apt-get install python3.6
By doing that it installs python 3.6 but when I see the version of python installed it's still 3.8.5. Should I do something to remove python3.8.5 ? maybe apt-get purge ?
P.S: I'm installing the wheel file through pip3 should I downgrade it too ?
You shouldn't hack the system installation of Python I'd say.
Instead you should use something that let's you manage multiple versions of it, something like pyenv.
It is a well-known and widely accepted utility and according to its readme:
pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.
You can find the installation instructions here: https://github.com/pyenv/pyenv#basic-github-checkout.
Once you installed it you can install your preferred Python distribution which will live besides your system one and all the others you want later.
E.g. if you want to install 3.6.7 and then use it globally you can do:
pyenv install 3.6.7
pyenv global 3.6.7
Then test it like:
python -V
And that's only to scratch the surface, you can do many more things with it, check out the documentation for more.
after the commands you've run, you should have a python3.6 binary installed on the path
that said, I'd recommend using virtualenvs instead of system installations
for deadsnakes, you can install the venv module by (sudo) apt install python3.6-venv (debian decided to split venv into a separate module, so the deadsnakes packaging follows that)
from there you can create and activate a virtualenv:
python3.6 -m venv venv # create the environment
. venv/bin/activate # activate the environment
pip install ... # install things to your isolated environment
inside this virtualenv the python command will refer to your own isolated python installation
disclaimer: I'm the maintainer of deadsnakes

Installing Python 2.x and python 3.x on the same computer

There are python 2.7 and python 3.2 on my computer. The default version is 2.7 because using python -V gives 2.7 as the version.
But when I use apt-get install numpy, scipy,pip why it install them into the python3.2 folder. After that I used pip to install the module into the 3.2 folder.
I also installed Theano this way but in the end it showed a message saying that there is no module named Theano installed although it is in the python 3.2 folder.
You haven't told on which OS you're running this, but it look likes a debian base linux, maybe ubuntu?
If so, I'd try with:
sudo apt-get install python3-numpy or
sudo apt-get install python2-numpy.
This would also work with python-pip2 and python-pip3.
After this, you could effectively use "pip2" or "pip3" to install your packages without having to go through the OS "prebuild" modules (but the os version of the packages are usually my prefered way to install them, if the exists in the repo)
Depending on what you're doing with python, it's often a good idea to run in a virtual environment, this lets you have several different versions of python with several different sets of installed packages on the same system. . .
See http://docs.python-guide.org/en/latest/dev/virtualenvs/ for the details.
You can also use Anaconda for maintaining two versions of Python. Anaconda consists of various libraries so you don't have to install them and after switching it to the different version of Python you can easily install them :
Download Anaconda for both Python versions
Open .bashrc
Add the path to new Anaconda you have installed for, e.g.:
export PATH="/home/paras/anaconda3/bin:$PATH"
Now there will be 2 export paths: one for Python 2 and one for Python 3. Comment the one which you don't want.
First install different versions of python or whichever python version you would like to use
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 10
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 20
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.3 30
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 40
Now create virtualenv like this and give the path of python version you want to use inside the virtualenv.
virtualenv -p /usr/bin/python3.6 <foldername>
virtualenv -p /usr/bin/python3.4 <foldername>

apt-get install for different python versions

I have ubuntu 10.04 with python2.6 by default. I have installed python2.7.
When I want to install python packages with
apt-get python-<package>
it gets installed to python2.6. How can I make it to install the package to python2.7? Is there any option?
I have looked at this, but I could not find such directories in my OS. I have considered using easy_install-2.7, but not all packages are supported. For example python-torctl.
I am more interested in binding python2.7 with apt-get install.
Python has got its own package managing facilities, in parallel to the one sets by the Linux distributions (including Ubuntu). The repository is the Pypi - Python Package Index, and packages are installed with pip or the easy_install script, which is part of Python's setuptools package.
As a rule of thumb, you should not use both the packages installed via pip/setuptools, and packages available to your distro (via apt-get, yum, urpmi, etc...) as they might conflict.
So, one of the less error prone way to deal with it is to have separate Python installs in your system - leave the python that came with the system for system scripts and such - on this python, make use of packages installed by your package manager only. And install other versions of Python (or even the same), to be run with "virtualenv"s - on these other install you install things with pip/setuptools only.
(And even if one opt to live boldly and not use virtualenvs, installing another python version on the same prefix (/usr, and even /usr/local) than your system's Python is a source to confusing errors and conflicts).
Note that the Debian - and Ubuntu - systems devised a way to run parallel official Python's in /usr, and to have apt-get to install Python packages to both Python versions at once. This mostly works, but they mess with Python's default directory hierarchy, and some applications fail to use Python in this way. (It is also a mess to find the module files themselves in a Debian or Ubuntu). So the above method apply as a recommendation even if your system do have more than one version of Python available on apt-get.
In short, once you have compiled your desired version of Python, do this:
use your system's package manager to install "python-setuptools" and "python-virtualenv" (not sure if these are the actual package names).
Use virtualenv to create an environment from which you will use your different Python version
Activate your virtualenv, and install Python packages using pip on it.
Virtualenv does feature a "--help" switch to help you, but you basically do:
$ virtualenv -p <path-to-python-interpreter> <environment-dir>
$ source <environment-dir>/bin/activate
And there you are - all things using Python will "see" the interpreter in the virtualenv, due to environment variables set.
ubuntu 10.04 doesn't have a python2.7 package. You have to build 2.7 yourself. I did read an article about ubuntu releasing a python2.7 package when 12.04 came out but i'm not sure what the repository location is.
http://eli.thegreenplace.net/2011/10/10/installing-python-2-7-on-ubuntu/
or:
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.7
https://askubuntu.com/questions/101591/install-python-2-7-2-on-ubuntu-10-04-64-bit
this question has lots of answers online.
pyenv
https://github.com/pyenv/pyenv
Pyenv allows you to manage multiple Python versions without sudo for a single user, much like Node.js NVM and Ruby RVM.
Install Pyenv:
curl https://pyenv.run | bash
Then add to your .bashrc:
export PATH="${HOME}/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Find Python version to install:
pyenv install --list
Install the python version you want:
# Increase the chances that the build will have all dependencies.
# https://github.com/pyenv/pyenv/wiki/Common-build-problems
sudo apt build-dep python3
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
# Build and install a Python version from source.
pyenv install 3.8.0
List available Python versions:
pyenv versions
We now have:
* system (set by /home/cirsan01/.pyenv/version)
3.8.0
Select a different python version:
pyenv global 3.8.0
python --version
python3 --version
Both output:
Python 3.8.0
We can now proceed to install and use packages normally:
pip install cowsay
python -c 'import cowsay; cowsay.tux("Python is fun")'
cowsay 'hello'
We can confirm that everything is locally installed in our clean environemnt with:
python -c 'import cowsay; print(cowsay.__file__)'
gives:
/home/ciro/.pyenv/versions/3.8.0/lib/python3.8/site-packages/cowsay/__init__.py
and:
which cowsay
gives:
/home/ciro/.pyenv/shims/cowsay
and:
which python
gives:
/home/ciro/.pyenv/shims/python
Per project usage
In the previous section, we saw how to use pyenv in a global setup.
However, what you usually want is to set a specific python and package version on a per-project basis. This is how to do it.
First install your desired Python version as before.
Then, from inside your project directory, set the desired python version with:
pyenv local 3.8.0
which creates a file .python-version containing the version string.
And now let's install a package locally just for our project: TODO: there is no nice way it seems: Pyenv choose virtualenv directory
Now, when someone wants to use your project, they will do:
pyenv local
which sets the Python version to the correct one.
Related threads:
https://askubuntu.com/questions/682869/how-do-i-install-a-different-python-version-using-apt-get
https://unix.stackexchange.com/questions/9711/what-is-the-proper-way-to-manage-multiple-python-versions
apt-get install for different python versions
Tested on Ubuntu 18.04, pyenv 1.2.15.

Categories