Visual Studio Code Anaconda



Anaconda Distribution works with Visual Studio Code (VS Code), Microsoft’s lightweight and fast open-source code editor. Anaconda is great for academic and private organizations that cannot afford more expensive Python/R package managers. Also, it is more appropriate for intermediate to advanced Python users-Anaconda can be somewhat frustrating for beginners, as it takes some practice to. An environment consists of an interpreter and any number of installed packages. The Python extension for VS Code provides helpful integration features for working with different environments. Note: If you're looking to get started with Python in Visual Studio Code, refer to the tutorial Getting Started with Python in VS Code. Consider Visual Studio if you need to work with multiple languages and want the flexibility to customize your IDE. PyCharm vs Visual Studio PyCharm vs Anaconda. Anaconda is a Python distribution (set of libraries) focussed on data-driven projects while PyCharm is an IDE that also includes built-in support for Anaconda.

Over the last several years I have made a transition from developing in R to developing in Python for my data science projects. At first I would use Jupyter Notebooks to develop my solutions, however, I missed R Studio. While I am still a huge fan of the notebooks, especially Databricks Notebooks, I primarily use Visual Studio Code (VS Code). The Python distribution of choice for me is Anaconda, and I really love being able to have different conda environments for my different solutions so that I can avoid dependency conflicts and start fresh with new predictive solutions. The conda environments also make it extremely easy to track your dependencies since you are starting fresh with a new Python interpreter.

One thing that I initially found difficult with VS Code is the ability to create a conda environment and use it as my python interpreter. There is plenty of documentation available but it took me a little while to figure it out since I had to piece together a few different sources. As a reference I am using a Windows 10 Microsoft Surface Laptop for my local development, and I have Anaconda 4.5.12 installed.

Development Environment

Code

To set up your development environment please make sure that you have both Anaconda and Visual Studio Code installed on your machine (links above).Once installed, please open an “Anaconda Command Prompt”.

The following command creates a new conda environment with python 3.7.

To activate the new environment run:

You have now created and activated an anaconda environment. This means that you have two Python interpreters available on your machine: “base” and “myenv”. To run Python in the “myenv” environment run the code snippet below. Note, to pip or conda install python libraries I will typically just use the Anaconda Command Prompt with my desired environment activated.

Please make note where your python environment is located on your computer. For example, mine are located at “C:Users<username>Anaconda3envsmyenvpython.exe”.

So far we have only worked with the Anaconda command prompt, lets open up VS Code. There are two VS Code extensions that you will want installed: “Python” and “Anaconda Extension Pack”. Please note that they are both developed by Microsoft.

Code

To install an extension in VS Code navigate to the extension, search for “Python” and “Anaconda Extension Pack”, and install. See below.

We would like to use this new conda environment as our python interpreter in VS Code. Next use the command “CTRL + Shift + P” to open the command palette. Then type “>Python: Select Interpreter”. You will want to paste the file path of the python interpreter we created previously i.e. step 4.

Create a new python script called python_script.py, and paste the following code:

To execute this code highlight it or put your cursor on the line, and press “Shift + Enter”.

You are now using a new Anaconda Environment in VS Code!

From Dev to Prod

Visual Studio Code Anaconda Prompt

One advantage of using Anaconda Environments to create solutions is it allows developers to use various versions of python and install packages without conflicting dependencies. It also allows you to easily track what was installed from the base python installation making it easier to go from development to production.

One of my favorite ways of deploying python code is using Docker. In order to deploy a Docker container you will need two files. A requirements.txt file that contains dependencies you wish to pip install, and a Dockerfile that is executed to actually create a container image. I will touch on the requirements.txt file here, but to learn more about deploying python code using docker check out my blog post showing how to deploy data pipelines using containers.

A requirements.txt file is of the format:

The best way to managed this file is to simply track manually what you installed since creating your virtual environment. However, if you lost track and simply do not know what libraries you need, open an Anaconda Command Prompt, activate your environment, and run pip freeze. This will list all the libraries and versions that you have installed in your environment. Note that this includes dependency installation, meaning if you installed a library that install dependent libraries it will list those as well. That is not ideal but it will be fine.

Overall, Anaconda environments make python development much easier and allows me to quickly prepare my solution to be deployed to test and production environments.

PyCharm vs Spyder

Visual Studio Code Anaconda

PyCharm and Spyder are both cross-platform IDEs (Integrated Development Environments) featuring many helpful and intelligent features such as code completion, syntax highlighting and style analysis. However, Spyder is a lightweight IDE specifically designed for scientific Python development while PyCharm is more resource-intensive and much more powerful for programming.

Consider PyCharm if you plan to build large, complex applications where you’ll have a need for features like version control, code snippets, safe refactoring and an integrated project browser.

Consider Spyder if you want a lightweight developer environment specifically for scientific Python applications.

PyCharm vs Jupyter

Jupyter is an IPython notebook that allows you to combine code, text and visualizations in one document while PyCharm is a featureful IDE for Python applications.

Anaconda

Consider Jupyter if you want to easily present and share data visualizations along with code and text.

Consider PyCharm if you want to work on complex projects which contain multiple scripts that interface with each other.

PyCharm vs Visual Studio

PyCharm and Visual Studio Code (VS Code) are both very popular and featureful IDEs. However, PyCharm is tailored for Python and you’ll have to install other IDEs for other languages. Visual Studio is more modular, it only needs to know what type of project you are working in and it will automatically enable the required plugins.

Visual Studio Code Anaconda

It’s worth noting that PyCharm is very resource-intensive and performs much slower than Visual Studio.

Consider PyCharm if you’ll be working mainly with Python.

Consider Visual Studio if you need to work with multiple languages and want the flexibility to customize your IDE.

Visual Studio Conda

PyCharm vs Anaconda

Anaconda is a Python distribution (set of libraries) focussed on data-driven projects while PyCharm is an IDE that also includes built-in support for Anaconda.

Consider Anaconda if you want to perform only data science tasks with access to many data science packages.

Consider PyCharm if you require flexibility to work on different types of projects but still have the need to use Anaconda for data-driven projects.

PyCharm vs IntelliJ

IntelliJ and PyCharm are both IDEs built by JetBrains. However, IntelliJ is tailored for Java while PyCharm is tailored for Python.

Consider IntelliJ if you’ll be coding mainly in Java.

Consider PyCharm if you’ll be coding mainly in Python.

Jupyter vs Spyder

Jupyter is an interactive Python notebook where you can run code, visualize data and include text all in one document, while Spyder is an IDE specifically for scientific programming in Python.

Consider Jupyter if you work on data-driven projects where you need to easily present data to a non-technical audience.

Consider Spyder for building data science applications with multiple scripts that reference each other.

Intellij vs Visual Studio

Intellij is an IDE built for Java while Visual Studio is a fully customizable IDE that supports almost any programming language.

Consider IntelliJ if you code mainly in Java

Consider Visual Studio if you need the flexibility to customize your IDE based on the language and frameworks required by a certain project.