Skip to content

Latest commit

 

History

History
51 lines (31 loc) · 4.13 KB

File metadata and controls

51 lines (31 loc) · 4.13 KB

Configure Python environment through Anaconda

Python is an increasingly popular high-level programming language. It emphasizes legibility over highly complex structure. Python innately provides simple data structures allowing for easy data manipulation. Python provides a simple approach to object-oriented programming, which in turn allows for intuitive programming, and has resulted in a large user community that has created numerous libraries that extend the basic capacities of the language.

The Anaconda makes configuring Python programing environment super easy. The Anaconda is cross-platform and it is very easy to install different libraries in the virtual environment. The following tutorial will walk you through the tutorial for installing Anaconda and required Python modules.

1. Install Anaconda

  1. Download the Anaconda. Go to the website to download Anaconda for different OSs.

Select the right Anaconda for your computer. In this tutorial, we are going to use Python 3.8.

  1. Locate you installer and install. Locate you downloaded Anaconda installer and then double click it to install. For Windows and MacOS, the installing is the same, just keep following the instructions by default.

  1. Check your installation. When you installation is done, you can then check if you have the Anaconda installed successfully. For Windows, press windows button and see if you have Anaconda Prompt. For Mac, go to your terminal and type in conda.

2.Be familiar with Anaconda

When you have the Anaconda installed successfully, then you can open your Anaconda terminal (command line) and create virtual environment for Python programming.

  1. Open the Anaconda. For Windows, open the Anaconda Prompt .

For Mac, go to the terminal,

  1. Type in conda info -e in your terminal, you should see the base environment. The base is the default Python environment. We usually don't install Python modules in the base.
  2. Create a customized virutal environment called geoviz, conda create --name geoviz. You can use other names as you like. Let
  3. Install the required modules. Before you get started to install Python modules, we need to first activate the virtual environment we just created. Just type in conda activate geoviz in the terminal.
    • install geopandas, type in conda install -c conda-forge geopandas in the terminal.
    • install jupyter, type in pip install jupyter in the terminal.
    • install cartopy, type in pip install cartopy in the terminal.

It is pretty straightforward to install the modules you need in Anaconda. In most cases just type in conda install name_module, or pip install name_module.

3. Start Jupyter Notebook and write Python code

Now we have the required environment ready. Let's start the Jupyter Notebook and then write your Python code.

  1. Go to your terminal. Make sure the geoviz is activated. Note: If you still see the base, you need to activate it first by typing conda activate geoviz in the terminal. If you want to go back to base, you can also deactivate it, conda deactivate. In this way, you can swich between different virtual environment, which can be created for different purposes.

  2. Start the Jupyter Notebook by typing jupyter notebook in the terminal. Then you web browser will start automatically and guide you to the notebook. You can then write Python code over there.

What Next

Go to open the test Jupyter Notebook file link. You can open the ipynb file directly or copy the statment to you newly created notebook.

Reference

  1. Jupyter notebook for beginners, https://realpython.com/jupyter-notebook-introduction/
  2. Notebook Basics, https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Notebook%20Basics.html