Learn how to version packages for greater stability while working and deploying. You can use the conda package manager to create an environment and install packages with specific versions in it.
- [Instructor] So what are those environments? We can only have one version of a package for a given Python installation, but what's wrong with having the latest version? Well in most cases it will work, but in some cases bugs are introduced and APIs can change. As a joke says, "We don't care if it works on "your computer, we're not selling your computer "to customers." Meaning you need to be able to reproduce the running environment in production. Environment is an installation of Python, and we want to create an environment with known versions of each package.
This way our deployments are much more stable and predictable. In the Pip world, we use a tool called virtualenv to create virtual environments and in Anaconda we use well, Conda. It's highly recommended to work in an environment per project and not in the root environment. It gives the flexibility of working with different versions of packages per project and we'll be able to provide the operations team an environment to replicate. So let's create an environment. Go to Environments and click on the Create button.
Let's call this Track. And note that Conda can install R packages as well. Click on the New Track environment. If you look at the installed packages we see that there's not much there. So far we've used Pandas and matplotlib, so let's install them. Switch to Not Installed, find Pandas and click Apply and OK.
Now matplotlib, click Apply and now matplotlib, so we'll write matplot, select matplotlib, click Apply and OK. Much like these, like Pytron, PyDev, and friends know about virtual environments. And you can tell them per project which Python interpretor to use. Check the commentation for your id. In our case, when we create a new notebook, we should do it from the right environment.
Let's switch the environment in the menu I have to navigate. Click on Home. And then select Track. Note that we need to install the notebook since it's not installed already. So click on Install. And now we have the notebook installed as well. So far this has been part of the story. What's missing? We started all this to get the package we want which is Folium. However, we won't be able to find it by searching.
This is due to the fact that Continuum, the company who creates and updates Anaconda can only approve so many packages. There are two options. First, we can install Folium with Pip which is install when you create an environment. The other option, and my preference is to use Conda channels. These channels let people organizations to publish their own Conda packages. Of these channels, one of them known as Conda Forge, is an effort by the community to provide more packages.
Click on Channels, and then click on Add, and write Conda Forge and hit Enter. Now click on Update Channels. So after Update Channels, make sure that you're on the Track environment by clicking on it. And now, search for Folium. Select it, click Apply and OK. Let's switch back to the main Navigator UI, switch to the Track environment and launch your notebook.
Note that the new notebook started on a different port, 8889. We'll go to the old notebook and shut it down since two processes working on the same notebook is not a good idea. Both will write to the same notebook file and the file might get corrupted. Okay, so this is our old notebook. We're going to go close this one and we also go to look. Click on Track and shut down. We can also close this one if you want. And now, we need to open Track in the new notebook server for the Track environment.
First we need to run the code. So select Cell and Run All. If you remember we deliberately created an error, so now we need to do Cell and Run All Below. And again, we deliberately made an error in the previous script. So again, Cell and Run All Below. And again. Cell and Run on Below and we are going to clean this notebook once it's done, so these errors will not be there.
Cell, and Run All Below. And now we see that we manage to input Folium but Pymongo which we installed on the root environment is not available. And that is exactly what we want. There are many additional things you can do with Conda and Conda environment. Check out the commendation at conda.io.
- Working with Jupyter notebooks
- Using code cells
- Extensions to the Python language
- Markdown cells
- Editing notebooks
- NumPy basics
- Broadcasting, array operations, and ufuncs
- Folium and Geo
- Machine learning with scikit-learn
- Plotting with matplotlib and bokeh
- Branching into Numba, Cython, deep learning, and NLP