Get a site running Python 3.5 with Django on Debian

October 21, 2016 212 views
Python Django Apache Debian

Does anyone know how to do this? Debian ships with 3.4 and I need 3.5 to run the website.

1 Answer

You can install it from source.
Installing from source have one drawback though. It is being called python3.5 instead of python3. So when you call from terminal python3 it will still open 3.4.2 one. But if you call python3.5 it will open Python 3.5.

python3 --version
Python 3.4.2
python3.5 --version
Python 3.5.2

python3.5 could be linked (changed) to python3 but it can break system as it's not know does all Debian packages works with 3.5.

First thing you need to do is to make sure you have C compiler. It's called gcc and when you type

  • gcc --version

you should see something like:

Sample Output - gcc --version
gcc (Debian 4.9.2-10) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If you don't have installed make sure you have build-essential package:

  • sudo apt-get install -y build-essential

Now download python3.5 source using cURL.

  • curl -O https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz

This is link for Linux source of Python3.5.2. It is latest version in time of typing this answer and it can be changed over time, but you can check for latest version on Python Downloads page.

Unpack it after download and go to unpacked directory:

  • tar xvf Python-3.5.2.tar.xz
  • cd Python-3.5.2

Now, we can compile/install it by running following commands:

  • ./configure
  • make
  • make install

In short lines ./configure will make sure you have all dependencies and create Makefile so it can be compiled. make will compile it and make install will install compiled version of it.
It will take some time to finish (for me it was about 10 minutes).

When you run python3.5 you will see:

Sample Output
  • Python 3.5.2 (default, Oct 21 2016, 14:45:38)
  • [GCC 4.9.2] on linux
  • Type "help", "copyright", "credits" or "license" for more information.

This should be it. If you really want to link python3.5 over python3, we can try to find solution for it, but this is something I would NOT recommend.

  • Thank you for the detailed reply!

    How would I install Django then using pip and a virtual environment if its under python3.5
    And wouldn't this make it difficult to update Python to future versions?

    • Yes it will be hard upgrading as you would have to recompile from source every time you want to upgrade.
      Problem is that there is no Debian repo which has Python 3.5.x or any latest version.

      You can research about virtualenv and pyenv. There are tools made for environments using multiple python versions. It could be very useful for you.

      I found two tutorials from DigitalOcean which can give some insight on it:
      Common Python Tools: Using virtualenv, Installing with Pip, and Managing Packages
      How to Run Django with mod_wsgi and Apache with a virtualenv Python environment on a Debian VPS

      by O.S Tezer
      In this DigitalOcean article, we aim to fill you in on not only the basics, but also the logic behind popular Python tools and items as we dive into using them in real life scenarios. We will begin with downloading and installing some common libraries, setting and working with virtual environments (using virtualenv) and managing packages for development and production of your own applications.
      • I meant more so, if I did this install would I reference pip with pip3.5 command or pip3 or just pip?

        • This will basically install only Python 3.5. pip would still be missing. This could be mine bad as I forgot it in initial.
          First install required dependencies:

          • apt-get install libssl-dev zlib1g-dev libbz2-dev libsqlite3-dev

          Red ones are not so required but recommended.

          Now go to directory where you downloaded source - e.g. cd ~/Python3.5.2.
          Execute following set of commands:

          • ./configure --with-ensurepip=install
          • make
          • make install

          When you execute pip3.5 version:

          pip3.5 -V
          pip 8.1.1 from /usr/local/lib/python3.5/site-packages (python 3.5)
          

          Also same output for pip3:

          pip3 -V
          pip 8.1.1 from /usr/local/lib/python3.5/site-packages (python 3.5)
          

          But for your purpose, I would really recommend you to learn more about virtualenv or pyenv as I think it would be much better to use it.

Have another answer? Share your knowledge.