RMD python

library(reticulate)

Here I will describe what are the first step to perform to have a running version on Python on your PC.

The version you need depends on what you want to do in Python. Some older projects are coded in Python version 2.xx (REF). Then, since there is no backward compatibility between 2.xx and 3.xx versions, if you want to work with older projects you probably need that version. If you are starting a project from scratch, you have the freedom to choose. Nowadays the Python 3.xx is the most COMMON version and, even if Python 4.xx will be out soon, it will be completely backward compatible.

Windows

The installation procedure involves downloading the official Python .exe installer and running it on your system.

  1. Download Python Executable Installer from … . Open your web browser and navigate to the Downloads for Windows section of the official Python website.

Stormtroopocat

Search for your desired version of Python. At the time of publishing this article, the latest Python 3 release is version zzzz, while the latest Python 2 release is version yyyyyy.

  1. Download Python Executable Installer. Select a link to download either the Windows x86-64 executable installer or Windows x86 executable installer (for older 32-bit systems).

  2. Run Executable Installer once downloaded. (In this example, we have downloaded Python 3.7.3.)

    • Make sure you select the Install launcher for all users
    • and Add Python 3.7 to PATH checkboxes.

The latter places the interpreter in the execution path. For older versions of Python that do not support the Add Python to Path checkbox, see Step 6. The next dialog will prompt you to select whether to Disable path length limit, allowing Python to use path names longer than 260-characters.

SE NON SI E’ VERIFICATO NESSUN PROBLEMA, now Python and pip are installed on your PC! Pip is a package management system for Python software packages, thus, make sure that you have it installed. Note that if you installed an older version of Python, it is possible that it did not come with pip preinstalled (SEGUI QUESTA GUIDA PER INSTALLARLO MAUNALMENTE).

It is possible to verify if Python and pip are correctly installed on Windows from the Command Prompt application:

  1. Open the Start menu (windows icon/button) and type cmd
  2. click on the Command Prompt application.
  3. Type python in the console and press enter
  4. Then enter pip -V in the console and press enter again.

If everything goes smoothly, you should see an output similar to the following:

Stormtroopocat

Mac OS

In general, MacOS comes with Python pre-installed, but it’s Python Version 2.xx. Then, until Apple decides to set Python 3.xx as default, you need to install it yourself.

For some of you reading this, running the python3 command from your MacOS terminal may be enough.

  1. Open spotlight (command+space)
  2. Type “terminal”
  3. Type python3 in the console

Installation check can be performed by typing python3 --version and pip --version into the terminal.

Stormtroopocat

SE TUTTO E’ STATO INSTALLATO CORRETTAMENTE, you should now have a working Python and Pip installations on your Mac.

Linux

sudo apt update sudo apt upgrade

sudo apt install python3 sudo apt install python3-pip

python –version python-pip –version

Hello World!

Once python is installed in your PC you are ready to program. You can compile the script directly from terminal (or command prompt in windows) by calling the built-in interpreter:

print("Hello world!")
## Hello world!
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()

plot(rnorm(100),rnorm(100,2,4))

Alternatively, you can consider using an Integrated Development Environment (IDE). IDEs are software programs dedicated to programming, integrating several tools specifically designed for software development. The web is full of IDEs with a smart Python editor, also providing useful additional features (code navigation, code completion, refactoring, debugging and so on). Check the wiki for a not-exhaustive list of the most popular.

import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()

git clone https://github.com/blog-neas/blog-neas.github.io.git

comments powered by Disqus