How to build and install Python 3.7.x from source on Debian 9.8How to install PyGTK for Python 2.7 on CentOS...

Why couldn't the separatists legally leave the Republic?

Having the player face themselves after the mid-game

What do *foreign films* mean for an American?

What are some noteworthy "mic-drop" moments in math?

What will happen if my luggage gets delayed?

Rationale to prefer local variables over instance variables?

Source permutation

From an axiomatic set theoric approach why can we take uncountable unions?

Is it possible to avoid unpacking when merging Association?

Does Christianity allow for believing on someone else's behalf?

Can't make sense of a paragraph from Lovecraft

In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?

PTIJ: Why does only a Shor Tam ask at the Seder, and not a Shor Mu'ad?

Is it safe to abruptly remove Arduino power?

Is a piano played in the same way as a harmonium?

Professor forcing me to attend a conference, I can't afford even with 50% funding

What is better: yes / no radio, or simple checkbox?

Are there historical instances of the capital of a colonising country being temporarily or permanently shifted to one of its colonies?

Windows Server Datacenter Edition - Unlimited Virtual Machines

MySQL importing CSV files really slow

What is the generally accepted pronunciation of “topoi”?

Why do phishing e-mails use faked e-mail addresses instead of the real one?

Can I use a violin G string for D?

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?



How to build and install Python 3.7.x from source on Debian 9.8


How to install PyGTK for Python 2.7 on CentOS 6?Debian: Version number of installed package differ from those in repository causing dependency issuesHow do I install a package from a different source, and let it update all dependencies as well?Make a full deb package with dependenciesInstall unstable package dolphin-emu (Dolphin Emulator) on DebianCan't Install ia32-libs on Debian 8Not able to install VirtualBox guest addition in Debian 3.16.0-4 guestAptitude - choose resolution strategy (ie. upgrade-to-unstable before remove)How to manage multi-versions of Python in Linux Debian ? (Specific issues with: pip, pew, path)how to update one package from stretch-backports













0















I have a fresh install of Debian 9.8, the current stable release version.



$ lsb_release --description
Description: Debian GNU/Linux 9.8 (stretch)


This system includes Python 3.5.3:



$ python3 --version
Python 3.5.3


Unfortunately that version doesn't meet my needs. I want a more current version of Python. At the time of writing, the current version is 3.7.2.



Hopefully this will be helpful for a range of versions, but in the interest of limiting the scope to something we can be very precise about, this question is about the above combination of OS and python versions.



To further specify: I want to build from the python git source repository, using the default configuration: we'll run ./configure with no arguments except maybe --prefix to choose a custom install location. I want any needed dependencies to come from the standard Debian apt sources, if possible.



Finally and most important: For any additional software we install as a prerequisite, give some information about it. Don't just say “install this incomprehensible list of apt packages”.



For any dependency available from Debian's stretch repositories, I want the following info:




  • Whether the dependency can be considered optional or must be treated as required in order to successfully complete python's build/install steps.


  • A link to the project homepage (or next next best thing if there isn't a suitable homepage, e.g. a repo url) that apt package came from.


  • What feature/module in the resulting installation does the dependency map to? Sometimes this will be obvious because the names will be similar or identical between project name, package name, and the module it is used to build, but sometimes it won't.



With that kind of information, anyone reading this can have some understanding of what they are installing and why. The task of determining which dependencies their project will need will hopefully be made significantly easier.









share



























    0















    I have a fresh install of Debian 9.8, the current stable release version.



    $ lsb_release --description
    Description: Debian GNU/Linux 9.8 (stretch)


    This system includes Python 3.5.3:



    $ python3 --version
    Python 3.5.3


    Unfortunately that version doesn't meet my needs. I want a more current version of Python. At the time of writing, the current version is 3.7.2.



    Hopefully this will be helpful for a range of versions, but in the interest of limiting the scope to something we can be very precise about, this question is about the above combination of OS and python versions.



    To further specify: I want to build from the python git source repository, using the default configuration: we'll run ./configure with no arguments except maybe --prefix to choose a custom install location. I want any needed dependencies to come from the standard Debian apt sources, if possible.



    Finally and most important: For any additional software we install as a prerequisite, give some information about it. Don't just say “install this incomprehensible list of apt packages”.



    For any dependency available from Debian's stretch repositories, I want the following info:




    • Whether the dependency can be considered optional or must be treated as required in order to successfully complete python's build/install steps.


    • A link to the project homepage (or next next best thing if there isn't a suitable homepage, e.g. a repo url) that apt package came from.


    • What feature/module in the resulting installation does the dependency map to? Sometimes this will be obvious because the names will be similar or identical between project name, package name, and the module it is used to build, but sometimes it won't.



    With that kind of information, anyone reading this can have some understanding of what they are installing and why. The task of determining which dependencies their project will need will hopefully be made significantly easier.









    share

























      0












      0








      0








      I have a fresh install of Debian 9.8, the current stable release version.



      $ lsb_release --description
      Description: Debian GNU/Linux 9.8 (stretch)


      This system includes Python 3.5.3:



      $ python3 --version
      Python 3.5.3


      Unfortunately that version doesn't meet my needs. I want a more current version of Python. At the time of writing, the current version is 3.7.2.



      Hopefully this will be helpful for a range of versions, but in the interest of limiting the scope to something we can be very precise about, this question is about the above combination of OS and python versions.



      To further specify: I want to build from the python git source repository, using the default configuration: we'll run ./configure with no arguments except maybe --prefix to choose a custom install location. I want any needed dependencies to come from the standard Debian apt sources, if possible.



      Finally and most important: For any additional software we install as a prerequisite, give some information about it. Don't just say “install this incomprehensible list of apt packages”.



      For any dependency available from Debian's stretch repositories, I want the following info:




      • Whether the dependency can be considered optional or must be treated as required in order to successfully complete python's build/install steps.


      • A link to the project homepage (or next next best thing if there isn't a suitable homepage, e.g. a repo url) that apt package came from.


      • What feature/module in the resulting installation does the dependency map to? Sometimes this will be obvious because the names will be similar or identical between project name, package name, and the module it is used to build, but sometimes it won't.



      With that kind of information, anyone reading this can have some understanding of what they are installing and why. The task of determining which dependencies their project will need will hopefully be made significantly easier.









      share














      I have a fresh install of Debian 9.8, the current stable release version.



      $ lsb_release --description
      Description: Debian GNU/Linux 9.8 (stretch)


      This system includes Python 3.5.3:



      $ python3 --version
      Python 3.5.3


      Unfortunately that version doesn't meet my needs. I want a more current version of Python. At the time of writing, the current version is 3.7.2.



      Hopefully this will be helpful for a range of versions, but in the interest of limiting the scope to something we can be very precise about, this question is about the above combination of OS and python versions.



      To further specify: I want to build from the python git source repository, using the default configuration: we'll run ./configure with no arguments except maybe --prefix to choose a custom install location. I want any needed dependencies to come from the standard Debian apt sources, if possible.



      Finally and most important: For any additional software we install as a prerequisite, give some information about it. Don't just say “install this incomprehensible list of apt packages”.



      For any dependency available from Debian's stretch repositories, I want the following info:




      • Whether the dependency can be considered optional or must be treated as required in order to successfully complete python's build/install steps.


      • A link to the project homepage (or next next best thing if there isn't a suitable homepage, e.g. a repo url) that apt package came from.


      • What feature/module in the resulting installation does the dependency map to? Sometimes this will be obvious because the names will be similar or identical between project name, package name, and the module it is used to build, but sometimes it won't.



      With that kind of information, anyone reading this can have some understanding of what they are installing and why. The task of determining which dependencies their project will need will hopefully be made significantly easier.







      debian python





      share












      share










      share



      share










      asked 9 mins ago









      CharlieCharlie

      1064




      1064






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Install git



          $ sudo apt install git


          Install Python build dependencies



          Python includes a set of modules that it builds by linking to other popular open source projects. Many of those projects are included in Debian by default as executable programs, but the development files (headers, libraries) necessary to link them into Python are packaged separately and not included in a default Debian install.



          Some of these libraries are actually required for the python build/install steps to complete successfully:



          | Library                            | Python Module | Dev Package  |
          | ---------------------------------- | ------------- | ------------ |
          | https://www.zlib.net/ | `zlib` | `zlib1g-dev` |
          | https://www.sourceware.org/libffi/ | `_ctypes` | `libffi-dev` |


          The entries in the 'Dev Package' column are the names of packages containing the development files our python build needs.



          Each of these 'dev' packages has a corresponding binary package that is probably already installed. So you're likely not going to be adding new pieces of software to your system by installing these. You're just installing the files necessary to compile new pieces of software (in our case a newer python) so that it can use them. (Also note that these 'dev' packages all have their corresponding binary packages as
          dependencies, so installing a dev package will ensure that its binary package is also installed.)



          So let's install them:



          sudo apt install zlib1g-dev libffi-dev


          Next we have the OpenSSL library. Python considers OpenSSL optional, but you probably want it. For example, even using Python's package installation
          tools can run into trouble when fetching https urls if SSL/TLS support is missing.



          | Library                  | Python Module | Dev Package |
          | ------------------------ | ------------- | ----------- |
          | https://www.openssl.org/ | `_ssl` | `libssl-dev |


          Let's install it:



          sudo apt install libssl-dev


          The next set of packages fall more in the 'optional' category:



          | Library                                              | Python Module(s)              | Dev Package        |
          | ---------------------------------------------------- | ----------------------------- | ------------------ |
          | http://www.bzip.org/ | `_bz2` | `libbz2-dev` |
          | https://www.gnu.org/software/ncurses/ | `_curses` and `_curses_panel` | `libncursesw5-dev` |
          | https://www.gnu.org.ua/software/gdbm/ | `_dbm` and `_gdbm` | `libgdbm-dev` |
          | https://tukaani.org/xz/ | `_lzma` | `liblzma-dev` |
          | https://www.sqlite.org/ | `_sqlite3` | `libsqlite3-dev` |
          | https://www.tcl.tk/software/tcltk/ | `_tkinter` | `tk-dev` |
          | https://github.com/karelzak/util-linux | `_uuid` | `uuid-dev` |
          | https://tiswww.case.edu/php/chet/readline/rltop.html | `readline` | `libreadline-dev` |


          Python can build and install without these, and your applications might not need them. On the other hand, if you install them, the 'make' step shouldn't report any modules it was unable to build, and the binaries are already included in a default Debian install.



          The command to copy-paste if you'd like to go ahead and install all of the above 'optional' packages is:



          sudo apt install libbz2-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev uuid-dev libreadline-dev


          Build and install python from source




          1. clone the python git repository.


          $ git clone git@github.com:python/cpython.git
          Cloning into 'cpython'...
          [...]
          Resolving deltas: 100% (592215/592215), done.



          1. Checkout the version you want to install (in this case, 3.7.2) using the git tag name.


          $ cd cpython/
          cpython$ git checkout v3.7.2
          Note: checking out 'v3.7.2'.
          [...]
          HEAD is now at 9a3ffc0492... 3.7.2final
          cpython$



          1. Choose an install prefix. That is, the path the compiled and linked project will be installed into. In this case I'll use $HOME/python/v3.7.2. I'm including the version number since I'll want to install other versions in the future, and keep them separate. Run the configure script with this path as the --prefix argument. (If you don't provide a --prefix argument, it will default to /usr/local).


          cpython$ ./configure --prefix=$HOME/python/v3.7.2
          [...]
          checking for inflateCopy in -lz... yes
          [...]
          checking for openssl/ssl.h in /usr... yes
          [...]


          The configure script will check a bunch of things, many of which are unnecessary. The ones shown in the above output, though, can be considered necessary.




          1. Build python by running make. If we included the minimum set of dependencies necessary to build and install python, the output will include something like this:


          cpython$ make
          [...]
          Python build finished successfully!
          The necessary bits to build these optional modules were not found:
          _bz2 _curses _curses_panel
          _dbm _gdbm _lzma
          _sqlite3 _tkinter _uuid
          readline
          To find the necessary bits, look in setup.py in detect_modules() for the module's name.


          Some output toward the end will tell you what modules were not built. The make output describes this as a list of 'optional' modules but again, at least for this particular version of python, it probably won't build and install successfully without the zlib, and _ctypes modules.




          1. Install python by running make install. We've already provided the install location back in the configure step. If your install location is a root-owned directory (e.g. /usr/local), prefix this command with sudo. Since in this case I'm installing to a user-owned directory, I don't want to do that.


          cpython$ make install
          Creating directory /home/python/v3.7.2/bin
          Creating directory /home/python/v3.7.2/lib
          [...]




          1. You should now have an executable you can run from the bin directory underneath the install prefix named python3. (Note that this installer doesn't put anything at bin/python; just bin/python3.)


          $ $HOME/python/v3.7.2/bin/python3
          Python 3.7.2 (v3.7.2:9a3ffc0492, Mar 10 2019, 19:35:56)
          [GCC 6.3.0 20170516] on linux
          Type "help", "copyright", "credits" or "license" for more information.
          >>> quit()
          $




          share























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1412975%2fhow-to-build-and-install-python-3-7-x-from-source-on-debian-9-8%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Install git



            $ sudo apt install git


            Install Python build dependencies



            Python includes a set of modules that it builds by linking to other popular open source projects. Many of those projects are included in Debian by default as executable programs, but the development files (headers, libraries) necessary to link them into Python are packaged separately and not included in a default Debian install.



            Some of these libraries are actually required for the python build/install steps to complete successfully:



            | Library                            | Python Module | Dev Package  |
            | ---------------------------------- | ------------- | ------------ |
            | https://www.zlib.net/ | `zlib` | `zlib1g-dev` |
            | https://www.sourceware.org/libffi/ | `_ctypes` | `libffi-dev` |


            The entries in the 'Dev Package' column are the names of packages containing the development files our python build needs.



            Each of these 'dev' packages has a corresponding binary package that is probably already installed. So you're likely not going to be adding new pieces of software to your system by installing these. You're just installing the files necessary to compile new pieces of software (in our case a newer python) so that it can use them. (Also note that these 'dev' packages all have their corresponding binary packages as
            dependencies, so installing a dev package will ensure that its binary package is also installed.)



            So let's install them:



            sudo apt install zlib1g-dev libffi-dev


            Next we have the OpenSSL library. Python considers OpenSSL optional, but you probably want it. For example, even using Python's package installation
            tools can run into trouble when fetching https urls if SSL/TLS support is missing.



            | Library                  | Python Module | Dev Package |
            | ------------------------ | ------------- | ----------- |
            | https://www.openssl.org/ | `_ssl` | `libssl-dev |


            Let's install it:



            sudo apt install libssl-dev


            The next set of packages fall more in the 'optional' category:



            | Library                                              | Python Module(s)              | Dev Package        |
            | ---------------------------------------------------- | ----------------------------- | ------------------ |
            | http://www.bzip.org/ | `_bz2` | `libbz2-dev` |
            | https://www.gnu.org/software/ncurses/ | `_curses` and `_curses_panel` | `libncursesw5-dev` |
            | https://www.gnu.org.ua/software/gdbm/ | `_dbm` and `_gdbm` | `libgdbm-dev` |
            | https://tukaani.org/xz/ | `_lzma` | `liblzma-dev` |
            | https://www.sqlite.org/ | `_sqlite3` | `libsqlite3-dev` |
            | https://www.tcl.tk/software/tcltk/ | `_tkinter` | `tk-dev` |
            | https://github.com/karelzak/util-linux | `_uuid` | `uuid-dev` |
            | https://tiswww.case.edu/php/chet/readline/rltop.html | `readline` | `libreadline-dev` |


            Python can build and install without these, and your applications might not need them. On the other hand, if you install them, the 'make' step shouldn't report any modules it was unable to build, and the binaries are already included in a default Debian install.



            The command to copy-paste if you'd like to go ahead and install all of the above 'optional' packages is:



            sudo apt install libbz2-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev uuid-dev libreadline-dev


            Build and install python from source




            1. clone the python git repository.


            $ git clone git@github.com:python/cpython.git
            Cloning into 'cpython'...
            [...]
            Resolving deltas: 100% (592215/592215), done.



            1. Checkout the version you want to install (in this case, 3.7.2) using the git tag name.


            $ cd cpython/
            cpython$ git checkout v3.7.2
            Note: checking out 'v3.7.2'.
            [...]
            HEAD is now at 9a3ffc0492... 3.7.2final
            cpython$



            1. Choose an install prefix. That is, the path the compiled and linked project will be installed into. In this case I'll use $HOME/python/v3.7.2. I'm including the version number since I'll want to install other versions in the future, and keep them separate. Run the configure script with this path as the --prefix argument. (If you don't provide a --prefix argument, it will default to /usr/local).


            cpython$ ./configure --prefix=$HOME/python/v3.7.2
            [...]
            checking for inflateCopy in -lz... yes
            [...]
            checking for openssl/ssl.h in /usr... yes
            [...]


            The configure script will check a bunch of things, many of which are unnecessary. The ones shown in the above output, though, can be considered necessary.




            1. Build python by running make. If we included the minimum set of dependencies necessary to build and install python, the output will include something like this:


            cpython$ make
            [...]
            Python build finished successfully!
            The necessary bits to build these optional modules were not found:
            _bz2 _curses _curses_panel
            _dbm _gdbm _lzma
            _sqlite3 _tkinter _uuid
            readline
            To find the necessary bits, look in setup.py in detect_modules() for the module's name.


            Some output toward the end will tell you what modules were not built. The make output describes this as a list of 'optional' modules but again, at least for this particular version of python, it probably won't build and install successfully without the zlib, and _ctypes modules.




            1. Install python by running make install. We've already provided the install location back in the configure step. If your install location is a root-owned directory (e.g. /usr/local), prefix this command with sudo. Since in this case I'm installing to a user-owned directory, I don't want to do that.


            cpython$ make install
            Creating directory /home/python/v3.7.2/bin
            Creating directory /home/python/v3.7.2/lib
            [...]




            1. You should now have an executable you can run from the bin directory underneath the install prefix named python3. (Note that this installer doesn't put anything at bin/python; just bin/python3.)


            $ $HOME/python/v3.7.2/bin/python3
            Python 3.7.2 (v3.7.2:9a3ffc0492, Mar 10 2019, 19:35:56)
            [GCC 6.3.0 20170516] on linux
            Type "help", "copyright", "credits" or "license" for more information.
            >>> quit()
            $




            share




























              0














              Install git



              $ sudo apt install git


              Install Python build dependencies



              Python includes a set of modules that it builds by linking to other popular open source projects. Many of those projects are included in Debian by default as executable programs, but the development files (headers, libraries) necessary to link them into Python are packaged separately and not included in a default Debian install.



              Some of these libraries are actually required for the python build/install steps to complete successfully:



              | Library                            | Python Module | Dev Package  |
              | ---------------------------------- | ------------- | ------------ |
              | https://www.zlib.net/ | `zlib` | `zlib1g-dev` |
              | https://www.sourceware.org/libffi/ | `_ctypes` | `libffi-dev` |


              The entries in the 'Dev Package' column are the names of packages containing the development files our python build needs.



              Each of these 'dev' packages has a corresponding binary package that is probably already installed. So you're likely not going to be adding new pieces of software to your system by installing these. You're just installing the files necessary to compile new pieces of software (in our case a newer python) so that it can use them. (Also note that these 'dev' packages all have their corresponding binary packages as
              dependencies, so installing a dev package will ensure that its binary package is also installed.)



              So let's install them:



              sudo apt install zlib1g-dev libffi-dev


              Next we have the OpenSSL library. Python considers OpenSSL optional, but you probably want it. For example, even using Python's package installation
              tools can run into trouble when fetching https urls if SSL/TLS support is missing.



              | Library                  | Python Module | Dev Package |
              | ------------------------ | ------------- | ----------- |
              | https://www.openssl.org/ | `_ssl` | `libssl-dev |


              Let's install it:



              sudo apt install libssl-dev


              The next set of packages fall more in the 'optional' category:



              | Library                                              | Python Module(s)              | Dev Package        |
              | ---------------------------------------------------- | ----------------------------- | ------------------ |
              | http://www.bzip.org/ | `_bz2` | `libbz2-dev` |
              | https://www.gnu.org/software/ncurses/ | `_curses` and `_curses_panel` | `libncursesw5-dev` |
              | https://www.gnu.org.ua/software/gdbm/ | `_dbm` and `_gdbm` | `libgdbm-dev` |
              | https://tukaani.org/xz/ | `_lzma` | `liblzma-dev` |
              | https://www.sqlite.org/ | `_sqlite3` | `libsqlite3-dev` |
              | https://www.tcl.tk/software/tcltk/ | `_tkinter` | `tk-dev` |
              | https://github.com/karelzak/util-linux | `_uuid` | `uuid-dev` |
              | https://tiswww.case.edu/php/chet/readline/rltop.html | `readline` | `libreadline-dev` |


              Python can build and install without these, and your applications might not need them. On the other hand, if you install them, the 'make' step shouldn't report any modules it was unable to build, and the binaries are already included in a default Debian install.



              The command to copy-paste if you'd like to go ahead and install all of the above 'optional' packages is:



              sudo apt install libbz2-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev uuid-dev libreadline-dev


              Build and install python from source




              1. clone the python git repository.


              $ git clone git@github.com:python/cpython.git
              Cloning into 'cpython'...
              [...]
              Resolving deltas: 100% (592215/592215), done.



              1. Checkout the version you want to install (in this case, 3.7.2) using the git tag name.


              $ cd cpython/
              cpython$ git checkout v3.7.2
              Note: checking out 'v3.7.2'.
              [...]
              HEAD is now at 9a3ffc0492... 3.7.2final
              cpython$



              1. Choose an install prefix. That is, the path the compiled and linked project will be installed into. In this case I'll use $HOME/python/v3.7.2. I'm including the version number since I'll want to install other versions in the future, and keep them separate. Run the configure script with this path as the --prefix argument. (If you don't provide a --prefix argument, it will default to /usr/local).


              cpython$ ./configure --prefix=$HOME/python/v3.7.2
              [...]
              checking for inflateCopy in -lz... yes
              [...]
              checking for openssl/ssl.h in /usr... yes
              [...]


              The configure script will check a bunch of things, many of which are unnecessary. The ones shown in the above output, though, can be considered necessary.




              1. Build python by running make. If we included the minimum set of dependencies necessary to build and install python, the output will include something like this:


              cpython$ make
              [...]
              Python build finished successfully!
              The necessary bits to build these optional modules were not found:
              _bz2 _curses _curses_panel
              _dbm _gdbm _lzma
              _sqlite3 _tkinter _uuid
              readline
              To find the necessary bits, look in setup.py in detect_modules() for the module's name.


              Some output toward the end will tell you what modules were not built. The make output describes this as a list of 'optional' modules but again, at least for this particular version of python, it probably won't build and install successfully without the zlib, and _ctypes modules.




              1. Install python by running make install. We've already provided the install location back in the configure step. If your install location is a root-owned directory (e.g. /usr/local), prefix this command with sudo. Since in this case I'm installing to a user-owned directory, I don't want to do that.


              cpython$ make install
              Creating directory /home/python/v3.7.2/bin
              Creating directory /home/python/v3.7.2/lib
              [...]




              1. You should now have an executable you can run from the bin directory underneath the install prefix named python3. (Note that this installer doesn't put anything at bin/python; just bin/python3.)


              $ $HOME/python/v3.7.2/bin/python3
              Python 3.7.2 (v3.7.2:9a3ffc0492, Mar 10 2019, 19:35:56)
              [GCC 6.3.0 20170516] on linux
              Type "help", "copyright", "credits" or "license" for more information.
              >>> quit()
              $




              share


























                0












                0








                0







                Install git



                $ sudo apt install git


                Install Python build dependencies



                Python includes a set of modules that it builds by linking to other popular open source projects. Many of those projects are included in Debian by default as executable programs, but the development files (headers, libraries) necessary to link them into Python are packaged separately and not included in a default Debian install.



                Some of these libraries are actually required for the python build/install steps to complete successfully:



                | Library                            | Python Module | Dev Package  |
                | ---------------------------------- | ------------- | ------------ |
                | https://www.zlib.net/ | `zlib` | `zlib1g-dev` |
                | https://www.sourceware.org/libffi/ | `_ctypes` | `libffi-dev` |


                The entries in the 'Dev Package' column are the names of packages containing the development files our python build needs.



                Each of these 'dev' packages has a corresponding binary package that is probably already installed. So you're likely not going to be adding new pieces of software to your system by installing these. You're just installing the files necessary to compile new pieces of software (in our case a newer python) so that it can use them. (Also note that these 'dev' packages all have their corresponding binary packages as
                dependencies, so installing a dev package will ensure that its binary package is also installed.)



                So let's install them:



                sudo apt install zlib1g-dev libffi-dev


                Next we have the OpenSSL library. Python considers OpenSSL optional, but you probably want it. For example, even using Python's package installation
                tools can run into trouble when fetching https urls if SSL/TLS support is missing.



                | Library                  | Python Module | Dev Package |
                | ------------------------ | ------------- | ----------- |
                | https://www.openssl.org/ | `_ssl` | `libssl-dev |


                Let's install it:



                sudo apt install libssl-dev


                The next set of packages fall more in the 'optional' category:



                | Library                                              | Python Module(s)              | Dev Package        |
                | ---------------------------------------------------- | ----------------------------- | ------------------ |
                | http://www.bzip.org/ | `_bz2` | `libbz2-dev` |
                | https://www.gnu.org/software/ncurses/ | `_curses` and `_curses_panel` | `libncursesw5-dev` |
                | https://www.gnu.org.ua/software/gdbm/ | `_dbm` and `_gdbm` | `libgdbm-dev` |
                | https://tukaani.org/xz/ | `_lzma` | `liblzma-dev` |
                | https://www.sqlite.org/ | `_sqlite3` | `libsqlite3-dev` |
                | https://www.tcl.tk/software/tcltk/ | `_tkinter` | `tk-dev` |
                | https://github.com/karelzak/util-linux | `_uuid` | `uuid-dev` |
                | https://tiswww.case.edu/php/chet/readline/rltop.html | `readline` | `libreadline-dev` |


                Python can build and install without these, and your applications might not need them. On the other hand, if you install them, the 'make' step shouldn't report any modules it was unable to build, and the binaries are already included in a default Debian install.



                The command to copy-paste if you'd like to go ahead and install all of the above 'optional' packages is:



                sudo apt install libbz2-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev uuid-dev libreadline-dev


                Build and install python from source




                1. clone the python git repository.


                $ git clone git@github.com:python/cpython.git
                Cloning into 'cpython'...
                [...]
                Resolving deltas: 100% (592215/592215), done.



                1. Checkout the version you want to install (in this case, 3.7.2) using the git tag name.


                $ cd cpython/
                cpython$ git checkout v3.7.2
                Note: checking out 'v3.7.2'.
                [...]
                HEAD is now at 9a3ffc0492... 3.7.2final
                cpython$



                1. Choose an install prefix. That is, the path the compiled and linked project will be installed into. In this case I'll use $HOME/python/v3.7.2. I'm including the version number since I'll want to install other versions in the future, and keep them separate. Run the configure script with this path as the --prefix argument. (If you don't provide a --prefix argument, it will default to /usr/local).


                cpython$ ./configure --prefix=$HOME/python/v3.7.2
                [...]
                checking for inflateCopy in -lz... yes
                [...]
                checking for openssl/ssl.h in /usr... yes
                [...]


                The configure script will check a bunch of things, many of which are unnecessary. The ones shown in the above output, though, can be considered necessary.




                1. Build python by running make. If we included the minimum set of dependencies necessary to build and install python, the output will include something like this:


                cpython$ make
                [...]
                Python build finished successfully!
                The necessary bits to build these optional modules were not found:
                _bz2 _curses _curses_panel
                _dbm _gdbm _lzma
                _sqlite3 _tkinter _uuid
                readline
                To find the necessary bits, look in setup.py in detect_modules() for the module's name.


                Some output toward the end will tell you what modules were not built. The make output describes this as a list of 'optional' modules but again, at least for this particular version of python, it probably won't build and install successfully without the zlib, and _ctypes modules.




                1. Install python by running make install. We've already provided the install location back in the configure step. If your install location is a root-owned directory (e.g. /usr/local), prefix this command with sudo. Since in this case I'm installing to a user-owned directory, I don't want to do that.


                cpython$ make install
                Creating directory /home/python/v3.7.2/bin
                Creating directory /home/python/v3.7.2/lib
                [...]




                1. You should now have an executable you can run from the bin directory underneath the install prefix named python3. (Note that this installer doesn't put anything at bin/python; just bin/python3.)


                $ $HOME/python/v3.7.2/bin/python3
                Python 3.7.2 (v3.7.2:9a3ffc0492, Mar 10 2019, 19:35:56)
                [GCC 6.3.0 20170516] on linux
                Type "help", "copyright", "credits" or "license" for more information.
                >>> quit()
                $




                share













                Install git



                $ sudo apt install git


                Install Python build dependencies



                Python includes a set of modules that it builds by linking to other popular open source projects. Many of those projects are included in Debian by default as executable programs, but the development files (headers, libraries) necessary to link them into Python are packaged separately and not included in a default Debian install.



                Some of these libraries are actually required for the python build/install steps to complete successfully:



                | Library                            | Python Module | Dev Package  |
                | ---------------------------------- | ------------- | ------------ |
                | https://www.zlib.net/ | `zlib` | `zlib1g-dev` |
                | https://www.sourceware.org/libffi/ | `_ctypes` | `libffi-dev` |


                The entries in the 'Dev Package' column are the names of packages containing the development files our python build needs.



                Each of these 'dev' packages has a corresponding binary package that is probably already installed. So you're likely not going to be adding new pieces of software to your system by installing these. You're just installing the files necessary to compile new pieces of software (in our case a newer python) so that it can use them. (Also note that these 'dev' packages all have their corresponding binary packages as
                dependencies, so installing a dev package will ensure that its binary package is also installed.)



                So let's install them:



                sudo apt install zlib1g-dev libffi-dev


                Next we have the OpenSSL library. Python considers OpenSSL optional, but you probably want it. For example, even using Python's package installation
                tools can run into trouble when fetching https urls if SSL/TLS support is missing.



                | Library                  | Python Module | Dev Package |
                | ------------------------ | ------------- | ----------- |
                | https://www.openssl.org/ | `_ssl` | `libssl-dev |


                Let's install it:



                sudo apt install libssl-dev


                The next set of packages fall more in the 'optional' category:



                | Library                                              | Python Module(s)              | Dev Package        |
                | ---------------------------------------------------- | ----------------------------- | ------------------ |
                | http://www.bzip.org/ | `_bz2` | `libbz2-dev` |
                | https://www.gnu.org/software/ncurses/ | `_curses` and `_curses_panel` | `libncursesw5-dev` |
                | https://www.gnu.org.ua/software/gdbm/ | `_dbm` and `_gdbm` | `libgdbm-dev` |
                | https://tukaani.org/xz/ | `_lzma` | `liblzma-dev` |
                | https://www.sqlite.org/ | `_sqlite3` | `libsqlite3-dev` |
                | https://www.tcl.tk/software/tcltk/ | `_tkinter` | `tk-dev` |
                | https://github.com/karelzak/util-linux | `_uuid` | `uuid-dev` |
                | https://tiswww.case.edu/php/chet/readline/rltop.html | `readline` | `libreadline-dev` |


                Python can build and install without these, and your applications might not need them. On the other hand, if you install them, the 'make' step shouldn't report any modules it was unable to build, and the binaries are already included in a default Debian install.



                The command to copy-paste if you'd like to go ahead and install all of the above 'optional' packages is:



                sudo apt install libbz2-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev uuid-dev libreadline-dev


                Build and install python from source




                1. clone the python git repository.


                $ git clone git@github.com:python/cpython.git
                Cloning into 'cpython'...
                [...]
                Resolving deltas: 100% (592215/592215), done.



                1. Checkout the version you want to install (in this case, 3.7.2) using the git tag name.


                $ cd cpython/
                cpython$ git checkout v3.7.2
                Note: checking out 'v3.7.2'.
                [...]
                HEAD is now at 9a3ffc0492... 3.7.2final
                cpython$



                1. Choose an install prefix. That is, the path the compiled and linked project will be installed into. In this case I'll use $HOME/python/v3.7.2. I'm including the version number since I'll want to install other versions in the future, and keep them separate. Run the configure script with this path as the --prefix argument. (If you don't provide a --prefix argument, it will default to /usr/local).


                cpython$ ./configure --prefix=$HOME/python/v3.7.2
                [...]
                checking for inflateCopy in -lz... yes
                [...]
                checking for openssl/ssl.h in /usr... yes
                [...]


                The configure script will check a bunch of things, many of which are unnecessary. The ones shown in the above output, though, can be considered necessary.




                1. Build python by running make. If we included the minimum set of dependencies necessary to build and install python, the output will include something like this:


                cpython$ make
                [...]
                Python build finished successfully!
                The necessary bits to build these optional modules were not found:
                _bz2 _curses _curses_panel
                _dbm _gdbm _lzma
                _sqlite3 _tkinter _uuid
                readline
                To find the necessary bits, look in setup.py in detect_modules() for the module's name.


                Some output toward the end will tell you what modules were not built. The make output describes this as a list of 'optional' modules but again, at least for this particular version of python, it probably won't build and install successfully without the zlib, and _ctypes modules.




                1. Install python by running make install. We've already provided the install location back in the configure step. If your install location is a root-owned directory (e.g. /usr/local), prefix this command with sudo. Since in this case I'm installing to a user-owned directory, I don't want to do that.


                cpython$ make install
                Creating directory /home/python/v3.7.2/bin
                Creating directory /home/python/v3.7.2/lib
                [...]




                1. You should now have an executable you can run from the bin directory underneath the install prefix named python3. (Note that this installer doesn't put anything at bin/python; just bin/python3.)


                $ $HOME/python/v3.7.2/bin/python3
                Python 3.7.2 (v3.7.2:9a3ffc0492, Mar 10 2019, 19:35:56)
                [GCC 6.3.0 20170516] on linux
                Type "help", "copyright", "credits" or "license" for more information.
                >>> quit()
                $





                share











                share


                share










                answered 9 mins ago









                CharlieCharlie

                1064




                1064






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1412975%2fhow-to-build-and-install-python-3-7-x-from-source-on-debian-9-8%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

                    Tribunal Administrativo e Fiscal de Mirandela Referências Menu de...

                    looking for continuous Screen Capture for retroactivly reproducing errors, timeback machineRolling desktop...