How to uninstall python in ubuntu completely and reinstalling it? - python-2.7

The default python version was 2.7.12 in ubuntu.
I installed python2.7.13 using the below commands.
Then download using the following command:
version=2.7.13
cd ~/Downloads/
wget https://www.python.org/ftp/python/$version/Python-$version.tgz
Extract and go to the directory:
tar -xvf Python-$version.tgz
cd Python-$version
Now, install using the command you just tried, using checkinstall instead to make it easier to uninstall if needed:
./configure
sudo make install
Now there is some issue in pandas(giving no module named pandas when I try to import but if we try to install it shows required already satisfied) so I want to completely remove python 2.7.13 and reinstall python 2.7.12. How can I achieve this?

My python was corrupted due to some module. So I planned to re-installed or remove the python completely from my Ubuntu 16.04 machine. But sudo apt-get install --reinstall python2.7 command was also failing and was throwing same error. So I finally Did few hacks and cracks. Here are the steps -
Removing all python version manually
- sudo rm -rf /usr/bin/python2.x as well as python3.x
- sudo rm -rf /usr/lib/python2.x as well as python3.x
- sudo rm -rf /usr/local/lib/python2.x as well as python 3.x
Updating Ubuntu
- sudo apt-get update
In Between if you get this error The package needs to be reinstalled ubuntu Then Run following command
sudo vi /var/lib/dpkg/status
And delete all the lines from above file for the package which was expecting re-install and run sudo apt-get update again.
Now download a python tgz file from https://www.python.org/downloads/ and unzip it and CD into it
./configure
make test
sudo make install
Python should be installed now. Check by running python

Related

Error installing/initiating pgadmin4 SQLAlchemy 1.1.0 or greater is required

i'm installing pgadmin4 in Mint 19, following this instructions:
https://linuxhint.com/install-pgadmin4-ubuntu/
When i come to run:
https://linuxhint.com/install-pgadmin4-ubuntu/
I have an error:
File "/home/nico/pgadamin4/pgAdmin4/local/lib/python2.7/site-packages/alembic/util/__init__.py", line 31, in <module>
raise CommandError("SQLAlchemy 1.1.0 or greater is required. ")
alembic.util.exc.CommandError: SQLAlchemy 1.1.0 or greater is required
at this point, i don't know how to proceed. I don't really understand the whole installing process, using the virtual environment, so i can't add more information. Anyone can help? Thanks!
Why are you doing it manually?
pgAdmin4 now comes as native linux package.
Goto postgres site, Select your Ubuntu version as "Ubuntu Bionic" (which your Linux mint is based on).
https://www.postgresql.org/download/linux/ubuntu/
Add postgres repo as show on above link, and then do
sudo apt-get update && sudo apt-get install pgadmin4
For pgAdmin 4 v4.21 on Ubuntu, according to the download page:
Install dependencies, create a virtual environment, download, install & configure
Using Python2.x
sudo apt-get install virtualenv python-pip libpq-dev python-dev
cd
virtualenv pgadmin4
cd pgadmin4
source bin/activate
pip install https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v4.21/pip/pgadmin4-4.21-py2.py3-none-any.whl
Using Python3.6 (Preferred to avoid encoding related issues)
sudo apt-get install virtualenv python3-pip libpq-dev python3-dev
cd
virtualenv -p python3 pgadmin4
cd pgadmin4
source bin/activate
pip3 install https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v4.21/pip/pgadmin4-4.21-py2.py3-none-any.whl
Configure
Override default paths and set it to single-user mode in the local configuration file:
nano lib/python2.7/site-packages/pgadmin4/config_local.py
For Python3.x:
nano lib/python3.6/site-packages/pgadmin4/config_local.py
Write:
import os
DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/'))
LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log')
SQLITE_PATH = os.path.join(DATA_DIR, 'pgadmin4.db')
SESSION_DB_PATH = os.path.join(DATA_DIR, 'sessions')
STORAGE_DIR = os.path.join(DATA_DIR, 'storage')
SERVER_MODE = False
Run
python lib/python2.7/site-packages/pgadmin4/pgAdmin4.py
For Python3.x:
python3 lib/python3.6/site-packages/pgadmin4/pgAdmin4.py
Access
Access at http://localhost:5050
Exit
Exit with Ctrl-C
Run again
cd ~/pgadmin4
source bin/activate
python lib/python2.7/site-packages/pgadmin4/pgAdmin4.py
For Python3.6
#!/bin/bash
cd ~/pgadmin4
source bin/activate
python3 lib/python3.6/site-packages/pgadmin4/pgAdmin4.py
Make a shortcut
touch ~/pgadmin4/pgadmin4
chmod +x ~/pgadmin4/pgadmin4
nano ~/pgadmin4/pgadmin4
Write:
#!/bin/bash
cd ~/pgadmin4
source bin/activate
python lib/python2.7/site-packages/pgadmin4/pgAdmin4.py
For Python3.6
#!/bin/bash
cd ~/pgadmin4
source bin/activate
python3 lib/python3.6/site-packages/pgadmin4/pgAdmin4.py
Now you can just run it with a simpler command:
~/pgadmin4/pgadmin4
Python3 users
Replace [x] in Python3.6 with your respective version.
Conflict with pgAdmin 3 configuration
pgAdmin 4 will not start in the environment where pgAdmin 3 was previously installed and used because of incompatible configuration in the .pgadmin directory. The simplest solution is to either clear that directory or tweak config_local.py to point to a clean new .pgadmin4 directory.

How to set python version to 2.7 for Yocto project work in Ubuntu 18.04?

I am new to the Yocto project on Ubuntu. It requires that python version 2.7 and not 3.X be used. I need to set the default version of Python to 2.7. How do I do this?
write on your Terminal
cd /usr/src
then Install Python from python.org
sudo wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz
then Unzip The tgz file by writing
sudo tar xzf Python-2.7.14.tgz
then Goto The Directory Python-2.7.14
cd Python-2.7.14
then Configure The Language
sudo ./configure --enable-optimizations
then add Python to your Path
sudo make altinstall
And Done Python 2.7.14(True version and original) installed

How to upgrade python 2.7.12 to python 2.7.14 in Ubuntu?

I am not able to upgrade the python version in Ubuntu. What is the command used for this? Can anyone help me out?
Then download using the following command:
version=2.7.13
cd ~/Downloads/
wget https://www.python.org/ftp/python/$version/Python-$version.tgz
Extract and go to the directory:
tar -xvf Python-$version.tgz
cd Python-$version
Now, install using the command you just tried, using checkinstall instead to make it easier to uninstall if needed:
./configure
sudo make install
This worked for me..

google cloud compute engine change to python 3.6

I am a running a python script where I train CNN on my laptop and now want to run it on google cloud. The script imports tensorflow and keras, for which I need Python 3.6
The steps I followed were:
Go to compute engine and create a virtual machine with 8cpus
I ssh into the virtual machine, and I see that the python version is 2.7
How can I change the python version to 3.6 so I can install keras, and then to be able to run my python script?
Many thanks for your help
I had the same problem. By preference, I cd'ed into /tmp: cd /tmp, but from there, I followed these steps in the VM terminal:
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
tar -xvf Python-3.6.3.tgz
cd Python-3.6.3
./configure
sudo apt-get install zlib1g-dev
sudo make
sudo make install
python3 -V
If it works, the last one should print out:
Python 3.6.3
If it doesn't work, then you have something different about your environment that is preventing it. This is starting from a clean VM environment. But hopefully this works out for you!
You can install it by using:
sudo apt-get -y -qq install python3
Check this using:
python3 --version

How do you install Docutils from the Terminal so that Django admindocs will work?

Docutils is a great package. If you are using Django the admindocs package needs docutils. Instructions are available for installing with a web browser, but what if you are remote and logging in with a terminal over SSH? How to install in that case? What if you just want a quick recipe to do the job with the terminal?
I know I'm rather late to this question, but the accepted answer doesn't really reflect the common best practices from Python community members (and even less so from the Django community members.) While the outlined manual installation process does work, is is far more pains taking and error prone than the following:
You really should be using Pip. With Pip installing docutils system wide is as simple as:
$ sudo pip install docutils
This not only works for docutils but nearly any package on the 'Cheese Shop' as well as many other code repositories (Github, Bitbucket, etc.)
You may also want to look into other common Python best practice tools like virtualenv and virtualenvwrapper so that you can avoid global package installation.
To install Pip on Ubuntu/Debain I generally do the following:
$ sudo apt-get install python-pip
BTW: for virtualenv 'sudo apt-get install python-virtualenv' and for virtualenvwrapper 'sudo apt-get install virtualenvwrapper'.
The key to the install is to use the curl utility. The following will install docutils:
mkdir docutilsetup
cd docutilsetup
curl -o docutils-docutils.tar.gz http://docutils.svn.sourceforge.net/viewvc/docutils/trunk/docutils/?view=tar
gunzip docutils-docutils.tar.gz
tar -xf docutils-docutils.tar
cd docutils
sudo python setup.py install
This performs the following steps: Create a directory to download docutils into. cd into the directory just made, and use curl to download the zipped version of docutils. Unzip the file which creates a subdirectory docutils. cd into that directory and install with root permissions.
If you are using Django you will have to restart Django for admindocs to start working.
Although it is an old thread, I want to share the answer I found. To install type command
sudo apt install python-docutils
or
sudo apt install python3-docutils
This will install the dependencies too. Yesterday, I installed docutils using this command for Geany editor and it is working fine.