Anaconda has been adopted as data scientists’ go-to environment and package manager. Therefore, it is considered one of the critical first steps in setting up a functional data science working environment. The problem is that setting up Anaconda can be difficult at times and frustrating to understand for first-timers. In this article, we will explore a full installation and environment setup.
This powerful tool comes in two distributions, “full Anaconda” and “Miniconda.” The differences between the two are very straightforward — most beginners tend to install the “full Anaconda” distribution because it comes with a friendly UI and thousands of pre-installed scientific packages and IDEs. On the contrary, many experienced developers recognize that the full anaconda distribution is quite bloated, and it’s more practical to install packages as the need arises. This is where miniconda comes into the picture; miniconda comes with the bare minimum package and environment management functionality — letting more experienced developers take complete control through the command line or terminal.
- You can find the latest version of miniconda here.
- Conda usually gets installed in your user profile folder within your C: drive.
- *Warning* If your destination folder contains spaces, this can cause issues with environments and specific packages. If this is the case, we recommend that you install conda in a folder without spaces.
- Advanced Options: This is a critical step in your installation. If you are new to Python and don’t have a preexisting installation of conda (or other IDEs), we recommend you check both boxes.
- Once you hit “Install,” the installation will begin.
After completing the miniconda installation, open up a command prompt (cmd.exe), type
conda and press enter. If your miniconda PATH was set correctly during installation, you should get a printout highlighting basic conda commands.
If you receive a printout that says “ conda is not recognized as an internal or external command, operable program or batch file, ” you will need to continue to step 3, otherwise, proceed to step 4.
- Search “system environment variables” in the windows search bar.
- Under “Advanced,” select the “Environment Variables..” option at the bottom right.
- From the “user variables for ___” section, select the “path” variable from the left column and click “edit.”
- Add the path to the miniconda3, Scripts, and bin folders.
- The location of these folders will vary depending on where you installed anaconda3 or miniconda3.
- For example: if you installed Miniconda in “C:UsersRobert” then you should add the following paths to your environment variable:
- The example above says “anaconda3,” but remember that we installed miniconda, not full anaconda.
- Make sure you hit “ok” and close and reopen your command line window.
- After performing the previous steps and restarting your machine, you should be able to access your conda installation from the windows command prompt. Test this by:
– Opening your command prompt
– Typing in conda and hitting enter. You should see a help statement from conda indicating the usage of the “conda” command.
When you start developing a project from scratch, it’s recommended that you use the latest versions of the libraries you need. However, when working with someone else’s project, such as running an example from Kaggle or Github, you may need to install specific packages or even another version of Python due to compatibility issues. Virtual environments are a solution to this kind of problem. Using them makes it possible to create multiple environments, each with different versions of packages.
- Use the following command to create a new conda environment
conda create --nameI recommend that you always specify your python version when creating a new conda environment; not doing so can cause all sorts of issues down the line with package and dependency conflicts.
- Conda will request your permission before creating the environment. Type in “y” to approve or “n” to prevent conda from creating the new environment.
- Use the
conda info --envscommand to access a list of all available conda environments for your user profile
if this is your first time creating a conda environment, you will only see two environments available base and your new environment.
- To modify anything within your environment, you must first activate it using the activate command
This is where the power of conda environments truly shines; by installing packages and dependencies directly into a siloed conda environment, you can effectively preserve other environments that pertain to other projects. For example, a particular project might require a specific version of NumPy, while your new project requires an older version of NumPy due to a dependency conflict. Let’s explore how you would install packages into your conda environment.
- First activate your conda environment using
activate. You should now see your environment name in parentheses to the left of your path.
- Let’s test the installation workflow by installing jupyter lab into our conda environment.
- Use the
conda install -c conda-forge jupyterlabto install the jupyter lab package.
- You can also use pip install to add packages to your conda environment. It is recommended that you avoid using conda and pip interchangeably within the same conda environment because some of the package versions that reside within each one of those “channels” can contain minor differences. This doesn’t mean you can’t install a few packages from pip, but you should exercise caution.
This is an optional 5th step but an absolute requirement if you plan on using your conda environment inside a jupyter notebook.
We can accomplish this by following the following steps:
- Activate your conda environment
- Use the command conda install ipykernel to install the ipykernel library.
- Use the ipython kernel install — user — name= to create your jupyter kernel.
Now you can launch jupyter lab from the command line. You should now see your notebook kernel available in the launcher window.
Anaconda is a critical component of most data science workflows today. Building your anaconda environments diligently can minimize dependency conflicts across different data science projects. I hope this has been a helpful overview of how to get started with anaconda!