This commit is contained in:
madrocketsci committed 2026-11-07 20:19:25 -05:00
1 parent 88624bc20a
commit 81d46a7d32
24 files changed
+1335

No files matched your search

+170
View File
@@ -0,0 +1,170 @@
Python is an interpreted language that is used for a wide variety of things, and is free, open source, comes with a plotting library, and many math and statiscs tools.
Also it seems to have become the de-facto standard language for data analysis and machine learning.
## Things you need to use python:
(I'm assuming you're using a windows computer, correct me if I'm wrong)
### 1. Download the python environment
https://www.python.org/downloads/
Install the latest version of python (python 3.14)
This will install a bunch of stuff to your computer in a directory
(looks like the latest default location in C:\Users\<username>\AppData\Local\Programs\Python\Python314.) That's ... sort of awful. Set a different directory where you'll be able to find everything if you want. Make sure there are no spaces in the directory names in the path you install it to - that might not mess things up but it might require a lot of quotation marks when you later set up your system environment paths.
The installer might have an option to add python.exe to PATH. PATH is a system environment variable that tells the terminal where to look for executable programs in windows. You'll want python to be on the system path. If you ever wanted to edit it, type "system environment variables" into the search bar, and you should see a settings menu for "Edit the Systm Environment Variables". (Maybe, I'm still on Windows 10. Not sure about Win 11.)
System Properties >
Environment Variables >
Path under either the User variables or System Variables
Make sure your install dir is in there somewhere near the top, above whatever nerfed version microsoft may have automatically installed.
C:\Users\Aaron\AppData\Local\Programs\Python\Python314
C:\Users\Aaron\AppData\Local\Programs\Python\Python314\Scripts
Open up a command prompt (type "Command" into your search bar, and pin it to your taskbar.)
Type python and see if it opens up the python interpreter.
python - should open the interpreter
where python - should show you where the OS thinks python is installed
### 2. Download an IDE (integrated development environment)
This will be a text editor that is convenient to use to write python programs. I recommend vscode (Microsoft's IDE) or vscodium (the free software, less Microsoftish fork of vscode). Python files are just text files - any text editor will do. IDEs just make certain things simpler, like navigating the filesystem, and highlighting syntax.
https://code.visualstudio.com/
https://vscodium.com/
You may want to download the official python plugin to the IDE for syntax highlighting and other useful behavior.
### 3. Parts of python:
1. The interpreter: python.exe
The interpreter executes python commands in an interactive manner. It also runs python scripts when fed a script file
2. Pip: (python package index) - this is an installer for other widely used python libraries. There are quite a few it makes sense to install soon after installing python.
3. Pyenv: On linux this is almost essential. I'll see how strict windows is about it - you might be able to ignore it for now. It seems like windows will allow you to ignore all this for now, which saves a lot of mental overhead.
Using pip to install some libraries:
>python -m pip install numpy - installs the numpy library to whatever your active environment (the default in this case)
>python -m pip show numpy - shows where numpy ended up being installed (under C:\Users\Aaron\AppData\Local\Programs\Python\Python314\Lib\site-packages for me)
(you shouldn't need to know exactly where this is, just adding this in for completeness sake)
>python -m pip list - lists installed packages
>python -m pip install scipy matplotlib pandas opencv-python
numpy - a numerical library for operating on multidimensional numerical arrays and doing statistics, matrix math, and a lot of other things
This is basically matlab for python
scipy - contains more advanced matrix eigenvalue stuff, FFTs
matplotlib - the major plotting library used in python
pandas - might be used in data science
opencv - image processing - loading, saving, manipulating images
>python -m pip install jupyter - this installs the jupyter notebook environment. Jupyter is a sort of interactive mathworks like interface for python. You may end up using it a lot in your DASC course. I'd also install jupyter notebook extensions to vscode/vscodium.
### Finally: Your python scripts: python (mainly) executes python scripts
Create some script file: somescript.py
#!/usr/bin/env python
#this tells linux and mac operating systems that this file is a python file. Windows may use it as a hint as well
#everything after a pound sign is a comment
"""
Comments can go between triple quotation marks
"""
import math #imports the builtin math library
print("Hello world") #a builtin functio nto write to the terminal
print("The value of pi is " + str(math.pi))
#this is doing a few things
# "The value of pi is " - this is a string literal
# "The value of pi is " + (something else) - we are concatenating something else to this string
# math.pi - this is a floating point constant in the math library
# (it's cast to a string and the resulting concatenated string is something like "The value of pi is 3.141592653589793")
# print(the string) - prints that to the terminal
print("The value of pi is", math.pi) #another way to do it
You can execute somescript.py by calling
>python somescript.py
(more about the python language)
In the python language, whitespace is significant. It matters how much your code is indented syntactically. Python uses indentation the way other languages like C might use scope brackets. You'll get errors if your code is indented inconsistently. Typically tabs are used for indentation, though some number of spaces might also be able to be used. Use tabs, it'll save sanity.
import math
print("This code is not indented, and is assumed to be in the global scope")
def foo(a,b):
#the contents of the function are indented
print(a)
print(b)
c = 0
for I in range(0,5):
#the contents of the loop are indented relative to the loop statement
#this is a for loop that will increment the variable I until it reaches 5, (4 being the last time it executes the loop)
print("I",I,"c",c)
c = c + a - b
return c #the return value of the function
ret = foo(4,5) #calling the function we just defined
print("ret = ", ret)
In C this might look like this:
#include <stdio.h>
#include <stdlib.h>
float foo(float a, float b)
{
int I;
float c;
c = 0;
for(I=0;I<5;I++)
{
printf("I=%d, c=%1.3f\n",I,c);
c = c + a - b;
}
return c;
}
void main()
{
float ret;
ret = foo(4.0,5.0);
printf("ret=%1.3f\n",ret);
return;
}
In contrast to python, C doesn't care about whitespace - the compiler doesn't even see how you indented things. Instead, statements are terminated with semicolons, and scope is bounded by brackets { }.
### Jupyter