Andromeda

This is a guide for Andromeda. Follow the bullet points.

Table of Contents

Setting Up Virtual Machine

When you have a Windows machine but want to run Linux, one of the ways to do it is use a virtual machine. For that, we have to set up a hypervisor. We are going to install Virtualbox by Oracle. Then we are going to install Fedora Python classroom which has Python, Git, Vim, and Jupyter Labs built in.

Installing Virtualbox

  • Hit start menu button and search for powershell
  • When it comes up in the menu, right click and run as administrator, the hit yes
  • Once you have powershell blue window up, type:
  • choco install virtualbox -y
  • Once installed, start it up.

Installing Python and Linux

Creating a Virtual Machine

After Virtualbox is downloaded and installed, the next step is creating a virtual machine.

A virtual machine is a separate area within your operating system.

This separate area can run any other operating system, its like a computer within a computer.

Our virtual machine will have Linux installed.

Open up Virtualbox, at menu at top center, click "New"

A small separate window will open up. Fill these details with:

  • Name: Linux or Fedora
  • Folder: Don't change it, leave as is
  • ISO Image: This is what we downloaded earlier, in your downloads folder
  • Edition, Type, and Version: Should automatically fill in, don't have to do anything
  • Click Next
  • You will see a Hardware window, with base memory and processors
  • Use slider to to increase memory to 8192, which is exactly 8gb
  • Use slider to increase cpu to 4
  • Click next
  • You will now see a Virtual Hard Disk window, type 20.00 gb in the box on top right
  • Click Next, then click Finish
  • Highlight the name you gave it eearlier, then click Start
  • Follow any directions it asks you

Linux Command Line

To do many of your required tasks, you will have to use the command line. The command line means a terminal application. It is similar to Powershell in Windows, you type commands here to the computer to do various tasks.

To open the terminal:

  • Hit search or the Windows button on keyboard
  • Type "t" and terminal will be the first thing that comes up, hit enter or click on it
  • This brings up a dark window with a blinking prompt
  • You should see "andromeda@fedora:~$" 
  • That is your username, system, and $ means you are a regular user and not root

Navigating

  • Some basic commands will be helpful, here are a few you should try:
  • Ls     enter that in your terminal. It lists the directory contents
  • Cd     This stands for change directory. Look at what Ls says, you can see subdirectories you can Cd into
  • Cd ..      That is a space and 2 dots, this command will move you up one directory
  • Cd /home    This command will just take you to your home directory

Creating Directories

The mkdir command is used to create directories.
mkdir directory-name

So, you will want somewhere to store Python things, do this sequence from home directory:

  • cd Documents
  • mkdir python

So, after you start your computer:

  • search T to bring up terminal
  • cd Documents/python

Notice you can combine the steps and just type one command. There is a backslash between directories.

Removing Files
The rm command is used to remove files and folders.

You have to be in the directory of the file you want to delete unless you supply a path in the command. Easier to just "cd" into the folder for now.
rm file1

I have a whole separate guide on Linux commands and syntax if you get stuck on something.

https://aindien.com/linux-essentials-.html

 

Vim: This Is Your Editor

Vi and its upgrade Vim were some of the first editors for computers. These were built into Unix and Linux systems. It is already in every Linux system I think so you will not have to install it. Vim is what you will be using and it is a modal editor. It only deals with text, so it is not like Word at all. Code and math are just text though, so this is what many people prefer to use. There are other options, though.

Starting Vim

You can start Vim  by just typing vim at the terminal. This just invokes the program.

vim

However, this is only good if you already have a file created and know its name.

A better way to start working in files is to give the file name with it.

vim my-new-file

The above command will open the vim program and create the file "my-new-file" at the same time. This is a better way.

There are several different modes. A couple that you will use are:

Vim Modes

  • Normal     >>     This is the first and top mode. you execute commands here 
  • Insert        >>     In Normal mode, hit "i". Now you can type text. 

There are other modes but I'm not going to mention them because I doubt you will use them. 

  • So, you will always start in Normal mode.
  • Hit i to enter insert mode
  • Type your text, code, or math
  • Hit escape to leave Insert mode and go back to Normal mode 

Btw, in the bottom left of your Vim editor, it will say whether you are in Normal or insert mode. It will take some getting used to but look there for clues.

 

Saving your Work

Once you have typed things, you will want to save your work.

  • Hit escape to leave Insert mode.
  • This puts you in Normal mode
  • Type:   :w
  • This saves your work.

You can save and quit at the same time

  • :wq
  • That is write and quit and takes you back to the terminal

When you want to work in the same file again, do these steps:

  • cd into your directory you want to work in:
  • cd Documents/python
  • Use vim with the file name to open and edit a file:
  • vim your-new-file
  • hit "i" to enter Insert mode, then type away, then escape to go back to Normal mode
  • Then:   :wq
  • This saves and quits the file and vim
  • I have repeated a few things here but that is on purpose, so hopefully easier to remember.

Here is my Vim guide that tells a lot more:

https://aindien.com/vim-basics.html

Git

Git is a version control system. It is mostly used for code but you can use it with many things if you want. For example, I use it for code and articles. Basically, it tracks and backs up your files. This way you will always have the latest version. It is the ideal way to collaborate with others to work on the same file but in remote locaitons.

Git thinks of its data like a snapshot. Everey time you commit, or save a state of your project in Git, it basically takes a picture of what all your files look like at that moment and it stores a reference to this snapshot.

Getting Started

To have Git work correctly, you need to do some configurations, so type:

  • git config --global user.name "Andromeda"
  • git config --global user.email "your email you want to use"
  • git config --global core.editor "vim"

You can see your settings at any time by typing:

  • git config --list

The workflow of Git is based upon 3 stages:

  • Create or modify files in your working directory
  • Stage them - which means the file has been marked to go in your next commit
  • Committed the files - means it is stored in your local database

Repositories

You can get repositories in two main ways, make a new one or download an existing one. Repositories are just projects, usually in a single folder.

If you are going to submit your project online, such as to Github, then:

  • Login to Github, Click Create Proejct and name it something like python or comp-physics, you get the idea
  • It is important to create the folder/project in Github first
  • Then go back to your command line, and clone it to your computer
  • git clone [email protected]:Andromeda/python
  • This will create the folder and any files in it in whatever folder you are in on your computer

If you want to clone another projecty from Github, this is very easy:

Files

At this point you will probably have an empty directory. It is time to do some work now.

Your workflow should be like this:

  • Create a file using Vim, your text editor, type stuff, then save it
  • vim new-file, hit "i" to go into insert mode then start typing
  • Once done typing, hit "Escape" to go to Normal mode
  • Then type: ":wq" --That will save and exit vim and take you back to command line
  • git pull     -- this makes sure your online repo is synced to your computer
  • git add .   --This stages your file so it can be committed to the database
  • git commit -m "commit message, soemthing like I started this file"
  • git push   --This uploads your file to Github in the directory you created
  • git status   --This tells you what you just did and the status of your project

Commits History

The nice about Git as that it tracks every stage of everything you do.

Each time you make a change, add to a file, or create a new file and then commit, Git can go back and recall each of those. We can do this by the "log" command.

This command will show all of your commits in reverse order:

  • git log

This command will show you the last 3 commits:

  • git log -3

Another helpful command, to format is nicer is:

  • git log --pretty=oneline -3

Ok, I am going to stop here. You should not need to do more than this. There is a lot more you can do with every command I have already listed plus several more subjects. However, I don't want to overwhelm you. If you have questions or problems, you know you can ask.

Here is my official Git tutorial for more information, if needed:

https://aindien.com/getting-started-with-git.html

Jupyter Notebooks

Jupyter is a notebook system that has nice integrations for code, especially python, and other things. 

It is a blending of command-line and a word processor. You can write prose, math, or code here. 

Installing Jupyter

Install Jupyter by typing:

  • pip3 install jupyter
  • In your software menu, click Jupyter Notebook to get started

Jupyter is browser based and you can only interact with it through a browser.

In the future, after you have a notebook created and named, you can open it with:

  • jupyter notebook example.ipynb   "do this from command line"

Creating A Notebook

Once this is open you should see a directory tree on your left. We want to create a new folder to hold your notebooks.

  • On menu at the right, not the top left, click New and then Folder
  • Name this folder "Jupyter Notebooks"

This folder is for storing Notebook files which have an .pynb extension and any data files you have to download. It is best to keep them in the same folder. 

Now, to create your first Notebook, do this:

  • Click New again, at the menu on the right
  • Click the first option, it will say "Python 3 (ipykernel)
  • This will open up your noteboon in another browser tab

Working in a Notebook

A notebook is made up of boxes than contain code, mardown formatting, or plain text.

Each box can be a different type.

At the top is a menu that will adjust settings and adjust the type of box it will be.

Use the menu at the right to create more boxes, for exmaple, you can have a code box for your python code, markdown for things that need formatting, or just plain text. You can just click back and forth to each box and add information as you want to.

You can run your python code at any time. Make sure the box with code only has code in it. Then hit the play button in the menu button above the boxes. So, to clarify, the play button just exceutes the code within the box.

You can have multiple code boxes but make sure and run them sequentially, or in order according to python rules.

Jupyter autosaves your notebooks and keeps these save point. So, you can go back to any of these points. Just use the menu, under "File".

In the menu, there are options for downloading and sharing as well, if needed. 

Packages

Packages can get confusing. The reason why is that Jupyter Notebook is separate from your Linux system. So, there are many ways to install packages but only one good way to make sure they work all the time.

In a code box, usually at the beginning of a code block, you want to install and load your packages. For any particular package we need to install, do like this. For the package "numpy", which is a popular package that does computations, type this:

  • python -m pip install numpy

 

Markdown

Markdown is a light markup language. It uses plain text and is meant to format
documents quickly. Readability is its main tenet. It does a little of what HTML
does but it is not a replacement. It has much fewer tags for formatting. In
fact, if markdown lacks anything you need, you can just use HTML for it. 

Headings
You create different headings by prefacing them with hashes.
# header 1
## header 2
### header 3
and so on

Bold Text
Surround text you want bold with two asterisks.
**bold text**

Italics
To make certain text italic, surround it with one asterisk.
*italic text*

Bold and Italic
To make somethign bold and italic at the same time, use 3 asterisks.
bold and italic text

Here is my full guide on Markdown:

https://aindien.com/markdown-introduction.html

Python

Using The Interpreter

The Python interpreter processes text. You type this text in the shell of your operating system or in a text editor.  

You can interact with the Python interpreter a few different ways.

  • In Windows, open CMD and type python
  • In Linux, open a terminal window and type python
  • From the start menu, you can choose Python
  • From the start menu, you can choose the IDLE program 

You can use the interpreter as a calculator with parentheses as needed. 

 

Your First Program

You can type commands and write your first program from this window. A Python program is just a text file with commands in it and saved with the .py extension. It is also a good idea to create a python folder somewhere to save your programs. 

In your interpreter window, we can print some text. That is technically a program but it is what most languages start with. Type:

print(‘I am learning Python’)

Use the menu to save this to your computer. Call it something like ‘learn.py’. Name it whatever you want though, it does not matter. 

You can navigate to the file through your gui and double click it.

You can also navigate to it through your command line. If you do it this way, once you are in the directory where the file is located, just type ‘python learn.py’ to run it.

 

Using Variables

All programming languages have variables. Python is no exception. Variables let you store data. You can then run operations on the variables as needed. Name your variables something meaningful.

life_counter=0

temperature=55

The first part is the variable name followed by an equals sign. After that contains the value of the variable. All variables must be initialized when created. This means they must be assigned a value when they are first created. 

You do not have to specify a data type when creating variables. This is called dynamic typing.

 

Comments

Comments are a universal way for programming languages to document code. They are meant to explain the thoughts behind a statement, the purpose of a block of code, and to make it easier on anyone reading the code at a later date.

You use the # symbol in front of a line of text to make it a comment. 

# The purpose of this variable is to be a counter and keep track of the iterations in a loop

You can do multi-line comments by enclosing text within triple quote marks(“””).

 

User Input

To capture user input, we use the input() function. It will accept a string inside its parentheses. Afterwards, it will prompt the user for input. User input is read as a text string. The text string is then assigned to a variable. 

fav_team=input(‘What is your favorite baseball team? : ‘)

print(fav_team)

 

Errors

There are three types of errors that can occur. They are:

  • Syntax
  • Runtime
  • Semantic

Syntax errors are when you use the Python language incorrectly. An example of this is misspelling a keyword. Runtime errors can happen when you run a program. This can be a lot of different things but generally means something was misused. Semantic errors are not technically errors. The program can still run but you get unexpected results.

 

Overview

The Python language is processed by the interpreter. It is a high level language because it uses English wording. Indentation is used to group statements into blocks. A Python program is just a text file that uses the .py file extension. The print() function outputs the string enclosed within its parentheses. String values are enclosed within quote marks. 

A variable is a container with a name. It stores values and can be used by referencing that variable’s name. Variables can be any data type but they all have to be initialized first with some value. The input() function accepts user input. You can assign this input to a variable to increase your program usefulness. 

Here is my full Python guide:

https://aindien.com/python-basics.html