Pyomo 0: Installation & Conda Environment Setup

To begin your programming journey, we’ll install Python using Conda for seamless package management and effortless environment setup.

Using Anaconda/Miniconda as your Python distribution provides numerous benefits for working with Python. Firstly, Anaconda/Miniconda simplifies package management by providing a vast collection of pre-built packages and dependencies for scientific computing, data analysis, and machine learning. This saves you time and effort in setting up your Python environment and ensures compatibility between packages.

Additionally, Anaconda/Miniconda offers an isolated and reproducible environment through its powerful virtual environment management. You can create separate environments for different projects, each with its own set of dependencies, avoiding conflicts and maintaining project-specific configurations.

Now, let’s talk about Miniconda. As a lightweight version of Anaconda, Miniconda provides more flexibility in terms of package selection and avoids unnecessary installation of large packages. With Miniconda, you have the freedom to choose and install only the packages you need, resulting in a more streamlined and efficient development environment.

In summary, using Anaconda/Miniconda simplifies package management, offers isolated environments, and provides flexibility. Miniconda’s lightweight nature makes it an excellent choice for those who prefer a more customized setup tailored to their specific requirements.

We’re going to start using Miniconda moving forward for the reasons we listed in the accordion (which you may skip).

Step by step installing everything we need to start coding
  1. Download Miniconda:

    • Go to the Miniconda website: https://docs.conda.io/en/latest/miniconda.html
    • Choose the appropriate installer for your operating system (Windows, macOS, or Linux).
    • Download the installer and follow the installation instructions specific to your operating system.
  2. Update Miniconda:

    • Run Anaconda prompt as administrator
    • Run the following command to update Miniconda:
conda update conda

3. Create a New Environment:

  • Open a terminal or command prompt.
  • Run the following command to create a new environment named “optPyomo” with Python 3.9:
conda create --name optPyomo python=3.9

4. Activate the Environment:

  • To activate the “optPyomo” environment, run the appropriate command based on your operating system:
    • For Windows:
conda activate optPyomo
    • For macOS and Linux:
source activate optPyomo

Now that we’ve set up our environment, it’s time to select an IDE (integrated development environment). While there are many IDE options available, I personally recommend Jupyter Notebook for teaching purposes. If you’re interested in learning more about it, you can check out a brief one-minute introduction below. However, feel free to skip it if you prefer.

What is jupyter notebook?
First and foremost, Jupyter Notebook provides an interactive and visual coding experience. Its cell-based structure allows you to write and execute code in chunks, making it ideal for teaching concepts step by step. You can easily showcase the output, making your explanations more engaging and understandable.

Secondly, Jupyter Notebook supports multiple programming languages, including Python, R, Julia, and more. This versatility enables you to explore different languages within a single environment, making it convenient for teaching diverse topics or comparing language features.

Moreover, Jupyter Notebook fosters collaboration and knowledge sharing. You can create interactive documents containing code, visualizations, and explanations, making it perfect for tutorials, assignments, and sharing code with colleagues or students.

In conclusion, Jupyter Notebook’s interactivity, multi-language support, collaboration features, and powerful extensions make it an excellent choice for teaching programming. Whether you’re an educator or a student, Jupyter Notebook empowers you to learn, experiment, and share your knowledge effectively.

After activating your new environment, whatever package you install from this point forward will only be installed inside your environment.

5. Install Jupyter Notebook:

    • While the “optPyomo” environment is active, run the following command to install Jupyter Notebook:
conda install jupyter

6. Install Required Packages:

    • While the “optPyomo” environment is still active, run the following commands to install the required packages one by one:
conda install -c conda-forge pyomo
conda install -c conda-forge ipopt
conda install -c conda-forge glpk
conda install -c plotly plotly
conda install -c conda-forge matplotlib
conda install -c conda-forge scipy
conda install -c conda-forge numpy

7. Open Jupyter Notebook:

    • In the terminal or command prompt, run the following command:
jupyter notebook

This will open the Jupyter Notebook interface in your web browser.

That’s it! You’ve now downloaded Miniconda, created a new environment named “optPyomo,” activated the environment, installed Jupyter Notebook, and installed the required packages. You can start using Jupyter Notebook within the “optPyomo” environment to work with Pyomo and other packages.

Leave a Reply

Your email address will not be published. Required fields are marked *