12
votes

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:

  1. Go to compute engine and create a virtual machine with 8cpus
  2. 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

2
Try python3, and use pip3 to install packages for Python3.Deqing
@Deqing : But how can I change to python3 ?user3177938
If there is no Python3 in your VM, install it. If you'd like the command python to use Python3, google virtualenvDeqing
I have python3 installed but its 3.5.3. I can't seem to get it to upgrade to 3.6. Tried sudo apt-get install python3.6 but didn't do anything.pldenc44
This link has an answer that worked for me: stackoverflow.com/questions/44399762/…Quintin Sheridan

2 Answers

16
votes

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:

  1. wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
  2. tar -xvf Python-3.6.3.tgz
  3. cd Python-3.6.3
  4. ./configure
  5. sudo apt-get install zlib1g-dev
  6. sudo make
  7. sudo make install
  8. 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!

-1
votes

You can install it by using:

sudo apt-get -y -qq install python3

Check this using:

python3 --version