1. What is Anaconda?
Anaconda is a free and open-source distribution of the Python and R programming languages for scientific computing. It simplifies package management and deployment by providing a unified environment and a collection of over 1,500+ open-source packages suitable for various tasks such as data analysis, machine learning, and scientific computing.
2. Installing Anaconda:
Windows/Mac/Linux:
Visit the Anaconda Downloads page.
Download the appropriate installer for your operating system.
Follow the installation instructions on the download page or in the installer.
A virtual environment is an isolated environment in which you can install Python packages without affecting the main (or system-wide) Python setup. It essentially provides a sandbox to work in, separating different projects' dependencies and avoiding potential conflicts between package versions.
Isolation: Different projects might require different versions of packages or even Python itself. With virtual environments, each project can have its own dependencies without interference.
Avoiding Conflicts: As you work on more Python projects, you might encounter situations where two projects require different versions of a package. Virtual environments help you sidestep this issue.
Simplified Dependency Management: When working in a team, using a virtual environment allows you to export the exact package configurations, making it easier for others to set up their development environments.
Protection: If anything goes wrong in a virtual environment, your main Python setup remains untouched. You can easily delete and recreate the environment.
Install Conda (see above)
Open the Terminal or Command Prompt:
On Windows, you can use the Anaconda Prompt, which comes with the Anaconda distribution.
On macOS and Linux, you can just use the terminal.
conda create --name your_env_name python=3.11
Replace your_env_name with a name for your environment.
The python=3.11 part specifies the Python version you want to install in the environment. You can adjust this based on your needs.
Activate the Environment:
conda activate your_env_name
Once activated, any Python packages you install will be specific to this environment. When you're done working in this environment, you can deactivate it with:
conda deactivate
You should always work withing a venv. Note that it is possible to duplicate and export venv configuration files. This will automate future instalations (see yml files below)
Installing usefull packages:
After activating your environment:
conda install spyder numpy pandas matplotlib
conda install -c conda-forge pydicom
conda install -c anaconda pyqt
conda install -c conda-forge qdarkstyle
conda install -c conda-forge vtk
conda install -c anaconda pandas
The .yml file captures all the details about the environment, such as the Python version and the list of installed packages. This allows for easy sharing and replication of environments.
Reproducibility: If you're collaborating with others or moving between machines, using a .yml file ensures everyone can set up the exact same environment with the same versions of packages, leading to consistent results.
Version Control: By committing your .yml file to version control (e.g., git), you have a history of the environment changes, making it easier to trace back issues or understand the evolution of the environment.
Documentation: The .yml file serves as a clear document of the required dependencies for your project.
Exporting an Existing Environment: If you have a conda environment (let's call it myenv), you can export its configuration to a .yml file as follows:
conda activate myenv
conda env export > myenv.yml
This will generate a file named myenv.yml with details about the Python version and all the packages (and their versions) installed in the myenv environment.
Using a conda .yml File to Create a New Environment:
Creating an Environment from the .yml File:
If you have a .yml file and want to create a conda environment from it, use the following command:
conda env create -f myenv.yml
This will create a new conda environment named myenv (or whatever name is specified in the .yml file) with all the specified packages.