google cloud compute engine change to python 3.6 - google-cloud-platform

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

Related

How to install apache superset in the secured servers(Without internet)

What is the best way of installing the apache superset in the secured server?
I haven't found any answer for it i figured it out with so many trial and error method, So its my small contribution to the community who are facing same issue
Below are the commands to install apache superset in production/Development
sudo yum install gcc gcc-c++ libffi-devel python-devel python-pip python-wheel openssl-devel cyrus-sasl-devel openldap-devel
sudo yum install python3
sudo yum install python3-devel
Since server has no internet you need to download it from below python community in your local system and transfer it to the server
Download all dependencies from :- https://pypi.org/simple/
To untar :- tar -xvf package.tar
Go to untared folder and run below command
sudo python3.x setup.py install x=your python version
If the package is of wheel extension i.e .whl run below command
sudo python3.6 -m pip install packagename.whl
After installing all the dependencies run below command
fabmanager create-admin --app superset
superset db upgrade
superset init
superset run -p port --with-threads --reload --debugger - For development
gunicorn -b IP:port superset:app --For production use
Hope this will help someone who is facing issue,
If there is any changes or i missed please add

How to uninstall python in ubuntu completely and reinstalling it?

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

Why does apt-get install django 1.6.1 on Ubuntu 14.04?

I just set up a new Ubuntu 14.04 and installed django using apt-get. Now django is installed in version 1.6.1 which is an insecure and unsupported version. The end of the extended support was April 2015 (https://www.djangoproject.com/download/) so I don't see why there is such an old version in the official apt-get.
Is there a good reason for this behaviour?
I think apt-get repository is not updated for django
Instead of using apt-get use pip to install Django(sudo pip install django). You shoud use virtualenv to run more than one python apps. Suppose you want to run more one applications,(hosting more than one django websites of different version or requirements.), run you applications in different virtualenv. Different applications may have different reuirements or version.
It's easy to install:
Install Virtualenv
$ pip install virtualenv
$ pip install virtualenvwrapper
$ source virtualenvwrapper.sh
$ mkvirtualenv virtualenv_name // create virtualenv
$ workon virtualenv_name
To restart virtalenv later
Run:
$ source virtualenvwrapper.sh
$ lsvirtualenv // list all virtual env
$ workon virtualenv_name // start working on virtual env
Now install you requirements on virtualenv.
$ pip install django==1.8
Try to learn here
http://www.tangowithdjango.com/book17/chapters/requirements.html#virtual-environments

Installing numpy on Amazon EC2 virtualenv

I'm trying to build a virtualenv that uses python27 in a virtualenv on an Amazon EC2. Research on the web indicated messing with the preinstalled Python26 is a bad idea so I wanted to work in a safe virtual env. Here are all of my commands starting from a fresh instance on EC2
sudo easy_install python27
sudo easy_install virtualenv
yum groupinstall "Development Tools"
mkdir virt_env
virtualenv -p python27 virt_env/py27
And this all seems to work great. When I activate my virtualenv Python27 is the default, and outside of it Python26 is the default. So far so good. Next I tried iPython in the virtualenv
source virt_env/py27/bin/activate
pip install ipython
This works great, again ipython is available in the virtualenv and not available outside of it. However when I go to install numpy in the virtualenv I get the follwing:
pip install numpy
// Lots of output that I won't paste all of it, main error below
SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
Not sure what I'm doing wrong because I've always installed numpy on virtualenv this way. Any help would be greatly appreciated thanks
EDIT: I've also tried using:
sudo yum install python-devel
in the virtualenv. Still no help
Was able to answer my own question. To install the python dev correctly I needed:
sudo yum install python27-devel

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.