T00 - Python intro
T00 - Python intro
• There are various ways to write and run Python code, but one of the most useful
for scientific purposes is to use an interface called “JupyterLab” that runs straight
out of your web browser.
• Managing, installing and constantly updating all the tools and packages
associated with your Python setup can be tricky. That’s why there is a software
called “Anaconda” that does it all for you in a very easy user-friendly way.
Installing Anaconda
• Anaconda is a package manager (a program that helps you install all the things you need, and that keeps it organized)
which is made for Python. To install Anaconda, do the following:
• https://www.anaconda.com/download and then scroll down the page to “Download” the installer (it should recognize
your operating system). This is a large file, so make sure you have a fast and stable internet connection.
• For MacBook users, you might be prompted to choose between the Intel or M1/M2 chip version (on top left of your screen click on > “About
this Mac” and double-check what chip you have on your laptop)
• If Anaconda starts asking for donations, stop and back up! Anaconda is available for free!
• Ignore links prompting you to “run cloud notebooks” or “code in the cloud”.
• Run the installer. This may take a while depending on your machine (last year a student reported it took several hours
to install on an old MacBook Air!). Make sure you have enough space on your hard drive (it will take 4-5 GB).
Run the “Anaconda Navigator”
application
• After installation “Anaconda Navigator” might start automatically. If not, run the application.
• When Anaconda is starting, you might see a black terminal window flash briefly (this is normal)
• Ignore prompts to sign in to an Anaconda cloud account. In Science One, you will be running Python on your own
machine, not on the cloud (i.e. someone else’s computer).
• Stay in “base (root)” and use the search box on the top right to check you have “matplotlib” and “scipy” libraries
installed (they will have a small green checkbox if installed)
• You will get a Terminal/Command Line window, which is referencing the Conda environment you launched it from.
• Type pip install arduino-python3 followed by return (note that case matters, this is all in small caps!)
• Look for a message indicating if the installation was successful.
• Close the Terminal/Command Line window, return to Anaconda.
• After having installed the package, you should get the message:
“Successfully installed Arduino-python3-0.6 pyserial-3.5”
After having installed the package, a terminal window on a Windows machine looks like the image above.
Note: you might launch Jupyter Notebook by
accident (they are right next to another). Both
JupyterLab and Jupyter Notebook do the same
Getting Started with JupyterLab thing but have slightly different user
interfaces. Just close the Notebook browser
tab that opened and launch JupyterLab
instead.
• To start working with JupyterLab, do the following:
• In Anaconda Navigator, go to “Home”
• Hit “Launch” on JupyterLab.