Installing Python 3

Start by opening a Terminal window and running the following commands, one at a time. You will be required to enter the administrative password for your system which, on a personal computer, is usually your own login password:

sudo apt-get install build-essential
sudo apt-get install sqlite3 libsqlite3-dev
sudo apt-get install bzip2 libbz2-dev
sudo apt-get install libreadline-dev libncurses5-dev
sudo apt-get install libssl-dev tcl-dev tk-dev python3-tk
sudo apt-get install zlib1g-dev liblzma-dev

Next, download a source distribution of Python from the site https://python.org.

Make a note of the file name, which will look like the following: Python-3.x.x.tar.xz, where x.x is a pair of numbers that specify the build for this distribution. You should download the highest version available, which should be above 3.6.0.

Now, go to the directory where the downloaded file was saved and run the following command, replacing x.x with the corresponding build number of your file:

tar xvf Python-3.x.x.tar.xz

To build the distribution, execute the following commands, again replacing x.x with the correct build number:

cd Python-3.x.x
./configure --prefix=$HOME/python3
make

The build process will take a while to finish, depending on the configuration and speed of your system.

The following step is optional. If you want to run the battery of tests included with the source distribution, run the following command from the Terminal window: 

make test

Depending on how fast your computer is, this may take a long time. At the end of the tests, a report of the build process will be generated. Do not worry if you get a few messages about skipped tests.

Next, install the code in its target directory, by running the following command:

make install

We now need to adjust the PATH environment variable. Start by making a backup copy of your shell configuration file by running the following commands:

cd
cp .bashrc .bashrc.python.bak

Start your text editor, open the .bashrc file, and add the following line at the end of the file:

export PATH=$HOME/python3/bin:$PATH

Save the file, close the editor and, back at the Terminal window, run the following command:

source ~/.bashrc

To test the installation, start Python from the command line by running the following command:

python3

If the installation is correct, Python will start and print information about the interpreter, as follows:

Python 3.x.x (default, Apr  4 2017, 09:40:21) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Check that the correct version of Python is being started by verifying that the version number 3.x.x coincides with that of the distribution you downloaded.

If you get an error when trying to start Python, or the wrong version of Python starts, the PATH variable was probably not set correctly in the .bash_rc file. You can check the current value of PATH by entering the echo $PATH command. If the path is not correct, edit .bashrc as indicated previously.

Exit Python by running the following command at the >>> Python prompt:

quit()

As a final test, run the following statement from the command line to check that Python's package manager was installed:

pip3 --version

This will print information about the version of pip3 that you are running. If no error message is issued, the setup was completed correctly and you can proceed to installing SciPy.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset