12

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

6
  • Try python3, and use pip3 to install packages for Python3. Commented Nov 14, 2017 at 11:31
  • @Deqing : But how can I change to python3 ? Commented Nov 15, 2017 at 11:28
  • If there is no Python3 in your VM, install it. If you'd like the command python to use Python3, google virtualenv Commented Nov 15, 2017 at 11:35
  • 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. Commented Sep 11, 2018 at 7:48
  • This link has an answer that worked for me: stackoverflow.com/questions/44399762/… Commented Oct 18, 2018 at 1:08

2 Answers 2

19

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!

Sign up to request clarification or add additional context in comments.

3 Comments

I had to install a C compiler and make also: apt install gcc make
this installation works well for python3.6 install but fails while installation of packages in pip3.6 with SSL error
@BrB You have to make sure SSL libraries are installed (sudo apt-get install libssl-dev) prior to compiling python3.6 (also see stackoverflow.com/a/54250324/1134841)
-1

You can install it by using:

sudo apt-get -y -qq install python3 

Check this using:

python3 --version 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.