1

I have a droplet on DigitalOcean that I am working on:

It is CentOS7 x64

I want to install python v 3.5.3 and have that run when I type 'python'

I used this page as a reference:

https://www.digitalocean.com/community/tutorials/how-to-set-up-python-2-7-6-and-3-3-3-on-centos-6-4

I did the following to download and compile python:

sudo yum group install "development tools"

As a local user joe:

cd ~
wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tgz
tar zxfv Python-3.5.3.tgz
find ~/python -type d | xargs chmod 0755
cd Python-3.5.3
./configure --prefix=/usr/local
make
sudo make altinstall

The /usr/local/bin looks like this:

-rwxr-xr-x 1 root root      101 Mar 26 21:20 /usr/local/bin/2to3-3.5
-rwxr-xr-x 1 root root      242 Mar 26 21:20 /usr/local/bin/easy_install-3.5
-rwxr-xr-x 1 root root       99 Mar 26 21:20 /usr/local/bin/idle3.5
-rwxr-xr-x 1 root root      214 Mar 26 21:20 /usr/local/bin/pip3.5
-rwxr-xr-x 1 root root       84 Mar 26 21:20 /usr/local/bin/pydoc3.5
-rwxr-xr-x 2 root root 12309712 Mar 26 21:19 /usr/local/bin/python3.5
-rwxr-xr-x 2 root root 12309712 Mar 26 21:19 /usr/local/bin/python3.5m
-rwxr-xr-x 1 root root     3080 Mar 26 21:20 /usr/local/bin/python3.5m-config
-rwxr-xr-x 1 root root      236 Mar 26 21:20 /usr/local/bin/pyvenv-3.5

There is no 'python' executable only 'python3.5' The only 'python' executable is located at

/home/joe/Python-3.5.3

-rwxrwxr-x  1 bucket bucket 12309712 Mar 26 21:16 python

It is the same size, so it is probably the same file. Should I just create a symbolic link in /usr/local/bin called python pointing to python3.5? I think that is kind of a hack but I cannot see what I did wrong.

Additional, I cannot call pip.

I attempted to install it:

wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py -O - | python3.5 - --user
--2017-03-26 21:47:19--  https://bootstrap.pypa.io/get-pip.py
Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.0.175, 151.101.192.175, 151.101.64.175, ...
Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|151.101.0.175|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1595408 (1.5M) [text/x-python]
Saving to: ‘STDOUT’

100%[=======================================================================================================>] 1,595,408   --.-K/s   in 0.08s   

2017-03-26 21:47:19 (19.6 MB/s) - written to stdout [1595408/1595408]

Requirement already up-to-date: pip in /usr/local/lib/python3.5/site-packages
[bucket ~]$ pip
-bash: pip: command not found

Thanks.

Dan S.
  • 162
  • 2
  • 13
  • 2
    why do you want to call it as `python`, everyone else using debian call python 3 `python3`... – Taku Mar 26 '17 at 23:20

2 Answers2

0

It is not a good idea to replace/override the python binary (which I believe is Python 2.7) with Python 3.5 binary. This in turn will mean everything on the system will now use your new interpreter - and probably break. In fact Debian has taken the point of view that "python" will always refer to Python 2.7.

Far better - and safer - idea to update your programs to use python3.5 binary.

Or use a virtualenv.

Penguin Brian
  • 1,991
  • 14
  • 25
  • It's not going to break my system. It is a DigitalOcean droplet where only I am running anything. I am setting up an environment for running django. – Dan S. Mar 27 '17 at 00:02
0

I want to thank Penguin Brian and abccd for their suggestions on virtualenv. It allows me to set a local 'python' executable. I got it installed and set up a virtualenv that works.

sudo yum groupinstall "Development tools"
sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

cd /usr/local/src
sudo wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz --no-check-certificate
sudo tar xf Python-3.5.3.tar.xz
cd Python-3.5.3
sudo ./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
sudo make
sudo make altinstall

sudo pip3.5 install virtualenv
sudo pip3.5 install virtualenvwrapper

As the local user:

mkdir ~/Envs

Add the following lines to .bashrc

export WORKON_HOME=$HOME/Envs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.5
source /usr/local/bin/virtualenvwrapper.sh

Save the file and then:

source ~/.bashrc

mkvirtualenv <yourname>

When you log back in to access the virtualenv:

$workon <yourname>
(yourname)$ python --version
Python 3.5.3
Dan S.
  • 162
  • 2
  • 13