-
Notifications
You must be signed in to change notification settings - Fork 46
What is Conda Content #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
f7002dc
add how to run python content
jukent 6b710d5
add terminal installation instructions
jukent 0d8ca48
move jupyter sentence
jukent 9ec274f
add link to terminal document
jukent ee8aeda
spacing
jukent 61fb46f
add running python instructions
jukent ecb903c
how to run python in the terminal
jukent 0a9584a
add jupyter.md
jukent fad9f70
add aniconda image
jukent d418344
edit jupyter text
jukent ca10a3e
edited jupyter.md and added images
jukent e52aeee
rename environment
jukent 5d40380
HackmdBadge1
hackmd-deploy 923ec33
HackmdBadge1
hackmd-deploy 74dfbcb
add badge and imgur links
hackmd-deploy 9650ba2
imgur images
hackmd-deploy e5cb3eb
add info about conda
jukent 8c2af43
some text edits
hackmd-deploy d7be3c4
rm trailing white space
jukent 33e4c2e
Brian's comments #1
hackmd-deploy 1b88885
edits from Brian
hackmd-deploy f5cada7
linting
jukent 51db5d6
Brian's comments
hackmd-deploy 2f790bd
Brian's comments
hackmd-deploy 64b8c1e
simplify jupyter environment
jukent 4d04bd9
linting
jukent 2240de3
Updated screenshot
brian-rose 6d1a354
Replace jupyter screenshot again
brian-rose 8b9856a
Replace imgur links
brian-rose 916a65d
saving and exiting jupyter
jukent 89f6e44
add third heading to objectives
jukent 58edafc
Merge branch 'how2run' into conda
jukent 5d1d415
link how2run to conda material
jukent 259faa5
Light edits and typo fixes
brian-rose 12ac475
Clean up the markdown
brian-rose 8e04cad
Merge branch 'how2run' into conda
jukent 5684abe
add terminal and jupyter to toc
jukent 43f9836
change section titles and have consistent format
jukent f0d50e0
change topic link to match new sbj
jukent b8b0084
typo
jukent 2ebe66d
typo again
jukent ac4a10d
fix topic to match
jukent 121f3b5
remove "or on the cloud"
jukent fb8b3b1
suggestions from max
jukent e311175
capitalize i
jukent beb74b6
oneline
jukent 13ebf21
Fix link and avoid inline code
brian-rose File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,95 @@ | ||
# Using the conda package manager | ||
# Installing and Managing Python with Conda | ||
|
||
```{note} | ||
This content is under construction! | ||
Conda is an open-source, cross-platform, language-agnostic package manager and environment management system that allows you to quickly install, run, and update packages within your work environment(s). | ||
|
||
Here we will cover: | ||
|
||
- What are packages? | ||
- Installing Conda | ||
- Creating a Conda environment | ||
- Useful Conda commands | ||
|
||
## What are Packages? | ||
|
||
A Python package is a collection of modules, which in turn, are essentially Python scripts that contain published functionality. There are Python packages for data input, data analysis, data visualization, etc. Each package offers a unique toolset and may have its own unique syntax rules. | ||
|
||
Package management is useful because you may want to update a package for one of your projects, but keep it at the same version in other projects to ensure that they continue to run as expected. | ||
|
||
## Installing Conda | ||
|
||
We recommend you install Miniconda. You can do that by following the [instructions for you machine](https://docs.conda.io/en/latest/miniconda.html). | ||
|
||
Miniconda only comes with the `conda` package management system; it is a pared-down version of the full Anaconda Python distribution. | ||
|
||
[Installing Anaconda](https://docs.anaconda.com/anaconda/install/) takes longer and takes up more disk space, but provides you with more functionality: Jupyter, Spyder (a Python-specific integrated development platform or IDE), as well as other immediately installed packages. The interface of Anaconda is great if you are uncomfortable with the terminal. | ||
|
||
We recommend Miniconda for two reasons: | ||
|
||
1. It's quicker and takes up less disk space. | ||
2. It encourages you to install only the packages you need in reproducible isolated environments for specific projects. This is generally a more robust way to work with open source tools. | ||
|
||
Once you have `conda` via the Miniconda installer, the next step is to create an environment and install packages. | ||
|
||
## Creating a Conda Environment | ||
|
||
A conda environment is an interoperable collection of specific versions of packages or libraries that you install and use for a specific workflow. The conda package manager takes care of dependencies so everything works together in a predictable way. One huge advantage of using environments is that any changes you make to one environment will not affect your other environments at all, so you are much less likely to "break" something! | ||
jukent marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
To create a new Conda environment, type `conda create --name` and the name of your environment in your terminal, and then specify any packages that you would like to have installed. For example, to install a Jupyter-ready environment called `sample_environment`, type | ||
|
||
``` | ||
conda create --name sample_environment python jupyterlab | ||
``` | ||
|
||
Once the environment is created, you need to _activate_ it in the current terminal session (see below) | ||
|
||
It is a good idea to create new environments for different projects because since Python is open source, new versions of the tools are released very frequently. Isolated environments help guarantee that your script will use the same versions of packages and libraries and should run the same as you expect it to. Similarly, it is best practice to NOT modify your `base` environment. | ||
|
||
## Useful Conda commands | ||
|
||
Some other Conda commands that you will find useful include: | ||
|
||
- Activating a specific environment | ||
|
||
``` | ||
conda activate sample_environment | ||
``` | ||
|
||
- Deactivating the current environment | ||
|
||
``` | ||
conda deactivate | ||
``` | ||
|
||
- Checking what packages/versions are installed in the current environment | ||
|
||
``` | ||
conda list | ||
``` | ||
|
||
- Installing a new package into current environment | ||
|
||
``` | ||
conda install somepackage | ||
``` | ||
|
||
- Installing a specific version of a package | ||
|
||
``` | ||
conda install somepackage=0.17 | ||
``` | ||
|
||
- Checking what conda environments you have | ||
|
||
``` | ||
conda env list | ||
``` | ||
|
||
- Deleting an environment | ||
|
||
``` | ||
conda env remove --name sample_environment | ||
``` | ||
|
||
Lots more information is in the [conda documentation](https://docs.conda.io/) or this handy [conda cheat sheet](https://docs.conda.io/projects/conda/en/latest/_downloads/843d9e0198f2a193a3484886fa28163c/conda-cheatsheet.pdf) | ||
|
||
If you're not a command line user, the Anaconda navigator offers GUI functionality for selecting environments and installing packages. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
# How to run Python | ||
# Installing and Running Python | ||
|
||
```{note} | ||
This content is under construction! | ||
``` | ||
This section provides an overview of different ways to run Python code, and quickstart guides for | ||
|
||
This section will give an overview of different ways to run Python code, and quickstart guides for | ||
- Choosing a Python platform | ||
- Installing and running Python on various local platforms | ||
- Installing and managing Python with Conda | ||
|
||
- Installing Python on a laptop with the conda package manager | ||
- Running Python in the cloud | ||
## Choosing a Python Platform | ||
|
||
There is no single official platform for the Python language. Here we provide a brief rundown of 3 popular platforms: | ||
|
||
1. The terminal, | ||
2. Jupyter notebooks, and | ||
3. IDEs (integrated development environment). | ||
|
||
Here we hope to provide you with enough information to understand the differences and similarities between each platform so that you can make the best chose for your work environment and learn along effectively, regardless of your Python platform preference. | ||
|
||
In general, it is always best to test your programs in the same environment in which they will be run. The biggest factors to consider when choosing your platform are: | ||
|
||
- What are you already comfortable with? | ||
- What are the people around you using (peers, coworkers, instructors, etc)? | ||
|
||
### Terminal | ||
|
||
For learners who are familiar with basic [Linux commands](https://cheatography.com/davechild/cheat-sheets/linux-command-line/) and text editors (such as Vi/Cim or Nano), running Python in the terminal is the quickest route straight to learning Python syntax without the covering the bells and whistles of a new platform. If you are running Python on a super computer, through an HTTP request, or ssh tunneling you might want to consider learning in the terminal. | ||
|
||
[How to Run Python in the Terminal](terminal.md) | ||
|
||
### Jupyter Notebooks | ||
|
||
We highly encourage the use of Jupyter notebooks; a free, open-source, interactive tool running inside a web browser that allows you to run Python code in "cells." This means that your workflow can alternate between code, output, and even Markdown-formatted explanatory sections that create an easy to follow analysis or "computational narrative" from start to finish. Jupyter notebooks are a great option for presentations or learning tools. For these reasons Jupyter is very popular among scientists. Most lessons in this book will be taught via Jupyter notebooks. | ||
|
||
[How to Run Python in a Jupyter Session](jupyter.md) | ||
|
||
### Other IDEs | ||
|
||
If you code in other languages you might already have a favorite IDE that will work just as well in Python. [Spyder](https://www.spyder-ide.org) is a Python specific IDE that comes with the [Anaconda download](https://www.anaconda.com/products/individual). It is perhaps the most familiar IDE if you are coming from languages such as [Matlab](https://www.mathworks.com/products/matlab.html) that have a language specific platform and display a list of variables. [PyCharm](https://www.jetbrains.com/pycharm/) and [Visual Studio Code](https://code.visualstudio.com) are also popular IDEs. Many IDEs offer support for terminal execution, scripts, and Jupyter display. To learn about your specific IDE visit its official documentation. | ||
|
||
_We recommend eventually learning how to develop and run Python code in each of these platforms._ | ||
|
||
## Installing and managing Python with Conda | ||
|
||
Conda is an open-source, cross-platform, language-agnostic package manager and environment management system that allows you to quickly install, run, and update packages within your work environment(s). Conda is a vital component of the Python ecosystem, and understanding it is important regardless of the platform you chose to run your Python code. | ||
|
||
[Learn more about Conda here](conda.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Python in Jupyter | ||
|
||
You'd like to learn to run Python in a Jupyter session. Here we will cover: | ||
|
||
- Installing Python in Jupyter | ||
- Running Python code in Jupyter | ||
- Saving your notebook and exiting | ||
|
||
## Installing Python in Jupyter | ||
|
||
To run a Jupyter session you will need to install some necessary packages into your Conda environment. | ||
|
||
You can install `miniconda`. You can do that by following the [instructions for you machine](https://docs.conda.io/en/latest/miniconda.html). | ||
|
||
[Learn more about Conda here](conda.md) | ||
|
||
Then create a Conda environment with Jupyter Lab installed. In the terminal type: | ||
|
||
``` | ||
$ conda create --name pythia_foundations_env jupyterlab | ||
``` | ||
|
||
Test that you have installed everything correctly by first activating your environment and then launching a Jupyter Lab session: | ||
|
||
``` | ||
$ conda activate pythia_foundations_env | ||
$ jupyter lab | ||
``` | ||
|
||
Or you can install the full [Anaconda](https://www.anaconda.com/products/individual), and select **LAUNCH** under the Jupyter panel in the GUI. | ||
|
||
 | ||
|
||
In both methods, a new window should open automatically in your default browser. You can change the browser when launching from the terminal with (for example): | ||
|
||
``` | ||
jupyter lab —browser=chrome | ||
``` | ||
|
||
## Running Python in Jupyter | ||
|
||
1. With your Conda environment activated and Jupyter session launched (see above), create a directory to store our work. Let's call it `pythia-foundations`. | ||
|
||
 | ||
|
||
You can do this in the GUI left side bar by clicking the new-folder icon. If you prefer to use the command line you can access a terminal by clicking the icon under the "Other" heading in the Launcher. | ||
|
||
2. Create a new `mysci.ipynb` file within the `pythia-foundations` folder: | ||
|
||
Do this in the GUI on the left side bar by clicking the "+" icon. | ||
|
||
This will open a new launcher window where you can select a Python kernel under the "Notebooks" heading for your project. _You should see "Python 3" as in the screenshot above._ Depending on the details of your system, you might see some additional buttons with different kernels. | ||
|
||
Selecting a kernel will open a Jupyter notebook instance and add an untitled file to the left side bar navigator, which you can then rename to `mysci.ipynb`. | ||
|
||
Select "Python 3" to use the Python version you just installed in the `pythia_foundations_env` conda environment. | ||
|
||
3. Change the first notebook cell to include the classic first command - printing, "Hello, world!". | ||
|
||
```python | ||
print("Hello, world!") | ||
``` | ||
|
||
4. Run your cell with **SHIFT ENTER** and see that the results are printed below the cell. | ||
|
||
 | ||
|
||
**Congratulations!** You have just set up your first Python environment and run your first Python code in a Jupyter notebook. | ||
|
||
## Saving your notebook and exiting | ||
|
||
When you are done with your work, it is time to save and exit. | ||
|
||
To save your file, you can click the disc icon in the upper left Jupyter toolbar or use keyboard shortcuts. | ||
|
||
Jupyter allows you to close the browser tab without shutting down the server. When you're done working on your notebook, _it's important to **click the "Shutdown" button** on the dashboard_ to free up memory, especially on a shared system. | ||
|
||
Then you can quit Jupyter by: | ||
|
||
- clicking the "Quit" button on the top right, or | ||
- typing `exit` into the terminal | ||
mgrover1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Alternatively you can simultaneously shutdown and exit the Jupyter session by typing `Ctrl-C` in the terminal and confirming that you do want to "shutdown this notebook server." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Python in the Terminal | ||
|
||
You'd like to learn to run Python in the terminal. Here we will cover: | ||
|
||
- Installing Python in the terminal | ||
- Running Python code in the terminal | ||
|
||
## Installing Python in the Terminal | ||
|
||
If running Python in the terminal, it is best to install Miniconda. You can do that by following the [instructions for you machine](https://docs.conda.io/en/latest/miniconda.html). | ||
|
||
[Learn more about Conda here](conda.md) | ||
|
||
Then create a Conda environment with Python installed by typing the following into your terminal: | ||
|
||
``` | ||
$ conda create --name pythia_foundations_env python | ||
``` | ||
|
||
You can test this by running `python` in the command line. | ||
|
||
## Running Python in the Terminal | ||
|
||
On Windows, open **Anaconda Prompt**. On a Mac or Linux machine, simply open **Terminal**. | ||
|
||
1. Activate your Conda environment: | ||
|
||
``` | ||
$ conda activate pythia_foundations_env | ||
``` | ||
|
||
2. Create a directory to store our work. Let's call it `pythia-foundations`. | ||
|
||
``` | ||
$ mkdir pythia-foundations | ||
``` | ||
|
||
3. Go into the directory: | ||
|
||
``` | ||
$ cd pythia-foundations | ||
``` | ||
|
||
4. Create a new Python file: | ||
|
||
``` | ||
$ touch mysci.py | ||
``` | ||
|
||
5. And now that you've set up our workspace, edit the `mysci.py` script using your favorite text editor (nano, e.g.): | ||
|
||
``` | ||
$ nano mysci.py | ||
``` | ||
|
||
6. Change the script to include the classic first command - printing, "Hello, world!". | ||
|
||
```python | ||
print("Hello, world!") | ||
``` | ||
|
||
jukent marked this conversation as resolved.
Show resolved
Hide resolved
|
||
7. Save your file and exit the navigator. How to do this is dependent on your chosen text editor. | ||
|
||
- In Vim the command is `:wq`. | ||
- In Nano it is `Ctrl + O` to save and `Ctrl + X` to exit (where you will be prompted if you want to save it, if modified). | ||
|
||
8. In the terminal, execute your script: | ||
|
||
``` | ||
$ python mysci.py | ||
``` | ||
|
||
**Congratulations!** You have just set up your first Python environment and run your first Python script in the terminal. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.