Writing python code on your local system is fun....Until its time to deploy your project and you find yourself scratching your head wondering why your project contains too many dependancies.
In tutorial, we're going to setup Anaconda, a popular data science toolkit that contains a package manager (conda) and integrates with a lot of popular applications that many python developers use.
What is Anaconda?
Anaconda is a popular, open-source software toolkit that contains many of the tools for the modern day data scientist. Many data scientists consume and analyze data using Python and R programming languages. The purpose of the toolkit is to be the "batteries included" developer environment for data scientists.
On your PC, go to https://www.anaconda.com/products/individual and download the installer for your system. Go ahead and continue through the installer using the recommended choices.
Once installed, if you're on Mac, open terminal. If you're Windows, browse to your programs and open "Anaconda Prompt". You'll see the current environment opened in your new terminal session.
(base) MBP:~ lateefa$
Great, our new terminal session is using conda's base environment, lets check out the packages installed in the base environment. In your terminal session, run the following command:
A lot (almost overwhelming) amount of packages are in the base environment. That is a good thing though! For a lot of python scripting and other projects, you have a lot of the necessary packages needed to get to testing.
Using the base environment is fine for testing, but for most python projects (especially Django) you don't need those extra packages. So lets create another environment using the base package manager, conda! For many Python developers, we may just need to start out with Python (and its standard dependancies) for our new environment. Lets use the conda package manager to create new environment that contains the latest version of Python 3.9 and its standard packages.
In your terminal, run the following command:
conda create --name mynewpyenv python=3.9
The following output will appear, showing all the packages you''ll be installing into the new environment:
The following NEW packages will be INSTALLED:
Type "Y" and hit enter to accept and download the packages. Now, lets activate the environment. In the same terminal, enter the following command:
conda activate mynewpyenv
You should see the terminal session activate the new environment like so:
(mynewpyenv) MBP:~ lateefa$
Perfect, now we can use pip to install packages such as django, gunicorn, whitenoise, etc. Also, we can use pip to generate the requirements.txt for our project so we can keep up with the dependancies for our python projects! If you need to change environments, simply enter the following command:
Lastly, I'd recommend that you download the Conda Cheatsheet. It holds the most useful conda commands in a 2 page document. I personally find myself referring to it every time I want to start/manage a new environment.
So...Conda vs. Pipenv vs. Virtualenv
Honestly, I don't have anything against using Pipenv or Virtualenv, I just began using Conda/Anaconda in my early days of a developer and started to use it whenever I setup new PCs for development/deployment as a huge feature of Anaconda is it installs Python on the computer. Sure that only saves me about 5-10 minutes, but why not use the toolkit that installs it for me?
Overall, use whichever package manager you like, I simply just prefer Anaconda/Conda.
Like the content posted on this site? Need help with another web project? Want to give some feedback? Feel free to contact me via email or social media!Know more!