Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Building and Installing?

This is probably a question that has a very easy and straightforward answer, however, despite having a few years programming experience, for some reason I still don't quite get the exact concepts of what it means to "build" and then to "install". I know how to use them and have used them a lot, but have no idea about the exact processes which happen in the background...

I have looked across the web, wikipedia, etc... but there is no one simple answer to it, neither can I find one here.

A good example, which I tried to understand, is adding new modules to python: http://docs.python.org/2/install/index.html#how-installation-works

It says that "the build command is responsible for putting the files to install into a build directory"

And then for the install command: "After the build command runs (whether you run it explicitly, or the install command does it for you), the work of the install command is relatively simple: all it has to do is copy everything under build/lib (or build/lib.plat) to your chosen installation directory."

So essentially what this is saying is: 1. Copy everything to the build directory and then... 2. Copy everything to the installation directory

There must be a process missing somewhere in the explanation...complilation?

Would appreciate some straightforward not too techy answer but in as much detail as possible :)

Hopefully I am not the only one who doesn't know the detailed answer to this...

Thanks!

Aivoric

like image 555
Aivoric Avatar asked Nov 03 '13 12:11

Aivoric


People also ask

What is difference between build and install?

Build = Compile the code into a binary file. Install = Move that binary into your binary path so that it may be used anywhere.

What is installing in construction?

In general, installation is the act of installing something in a fixed, semi-fixed or temporary location. It can also refer to a complete unit which has been installed. In terms of construction, it often refers to machinery, plant, apparatus, etc., being placed in position or connected for use.

What does building mean in Python?

Usually, a build command does all the compiling and linking needed, but Python is an interpreted language, so if there are only pure Python files in the library, there's no compiling step in the build. Indeed, everything is copied to a build directory, and then copied again to a final location.

What is building from source?

Installing a program "from source" means installing a program without using a package manager. You compile the source code and copy the binaries to your computer instead. Most of the time, you can download a project's source code from hosting services such as GitHub, GitLab, or Bitbucket.


3 Answers

Building means compiling the source code to binary in a sandbox location where it won't affect your system if something goes wrong, like a build subdirectory inside the source code directory.

Install means copying the built binaries from the build subdirectory to a place in your system path, where they become easily accessible. This is rarely done by a straight copy command, and it's often done by some package manager that can track the files created and easily uninstall them later.

Usually, a build command does all the compiling and linking needed, but Python is an interpreted language, so if there are only pure Python files in the library, there's no compiling step in the build. Indeed, everything is copied to a build directory, and then copied again to a final location. Only if the library depends on code written in other languages that needs to be compiled you'll have a compiling step.

like image 139
Pedro Werneck Avatar answered Oct 06 '22 19:10

Pedro Werneck


You want a new chair for your living-room and you want to make it yourself. You browse through a catalog and order a pile of parts. When they arrives at your door, you can't immediately use them. You have to build the chair at your workshop. After a bit of elbow-grease, you can sit down in it. Afterwards, you install the chair in your living-room, in a convenient place to sit down.

The chair is a program you want to use. It arrives at your house as source code. You build it by compiling it into a runnable program. You install it by making it easier to use.

like image 45
Joshua Avatar answered Oct 06 '22 20:10

Joshua


The build and install commands you are refering to come from setup.py file right?

Setup.py (http://docs.python.org/2/distutils/setupscript.html)

This file is created by 3rd party applications / extensions of Python. They are not part of:

  1. Python source code (bunch of c files, etc)
  2. Python libraries that come bundled with Python

When a developer makes a library for python that he wants to share to the world he creates a setup.py file so the library can be installed on any computer that has python. Maybe this is the MISSING STEP

Setup.py sdist

This creates a python module (the tar.gz files). What this does is copy all the files used by the python library into a folder. Creates a setup.py file for the module and archives everything so the library can be built somewhere else.

Setup.py build

This builds the python module back into a library (SPECIFICALLY FOR THIS OS).

As you may know, the computer that the python library originally came from will be different from the library that you are installing on.

  1. It might have a different version of python
  2. It might have a different operating system
  3. It might have a different processor / motherboard / etc

For all the reasons listed above the code will not work on another computer. So setup.py sdist creates a module with only the source files needed to rebuild the library on another computer.

What setup.py does exactly is similar to what a makefile would do. It compiles sources / creates libraries all that stuff.

Now we have a copy of all the files we need in the library and they will work on our computer / operating system.

Setup.py install

Great we have all the files needed. But they won't work. Why? Well they have to be added to Python that's why. This is where install comes in. Now that we have a local copy of the library we need to install it into python so you can use it like so:

import mycustomlibrary

In order to do this we need to do several things including:

  1. Copy files to their library folders in our version of python.
  2. Make sure library can be imported using import command
  3. Run any special install instructions for this library. (seting up paths, etc)

This is the most complicated part of the task. What if our library uses BeautifulSoup? This is not a part of Python Library. We'd have to install it in a way such that our library and any others can use BeautifulSoup without interfering with each other.

Also what if python was installed someplace else? What if it was installed on a server with many users?

Install handles all these problems transparently. What is does is make the library that we just built able to run. All you have to do is use the import command, install handles the rest.

like image 36
mAsT3RpEE Avatar answered Oct 06 '22 21:10

mAsT3RpEE