Setting up Python, Julia, and R in Visual Studio Code (VSCode) on an M1 Mac | by KahEm Chu | Towards Data Science

Python, Julia, and R are the 3 main programming languages used by data scientists, and I always have a thought to compare these 3 languages for different aspects.
I always wonder is R really the best for statistical analysis? Is Python really still slower than Julia after so many updates? Which of the 3 languages is the easiest language to apply in data science and data analysis projects? And who knows? Maybe combining all these 3 languages will create an art piece.
The easiest way to compare these 3 languages is to install all of them on VSCode, where it supports all of the 3 languages and I do not need to switch between different IDEs.
Setting up Python in VSCode is straightforward ☺️.
All you need is to download and install the Python interpreter and the Python Extension. VSCode is smart enough to detect Python on your Mac 😊, so there is no need to set up the path for Python.
You can install Python via Python.org or use the Python from Anaconda if you have Anaconda installed.
As you see, I have a few Python interpreters, the native Python, Python in the virtual environment, and the Anaconda Python. VSCode is able to detect all of them.
The next step is to install the two Python extension packs as follows. Again, VSCode is smart enough to suggest to you all the extension packs needed to run Python.
Python Extension from Microsoft (Extension ID: ms-python.python)Pylance Extension from Microsoft (Extension ID: ms-python.vscode-pylance)
Python Extension from Microsoft (Extension ID: ms-python.python)
Pylance Extension from Microsoft (Extension ID: ms-python.vscode-pylance)
You can run Jupyter Notebook file in VSCode as well, all you need to do is install the extension pack as follow.
Jupyter Extension by Microsoft (Extension ID: ms-toolsai.jupyter)
Jupyter Extension by Microsoft (Extension ID: ms-toolsai.jupyter)
This extension pack comes together with two extension packs.
Jupyter KeymapJupyter Notebook Renderers
Jupyter Keymap
Jupyter Notebook Renderers
With all these extension packs, you can now use Python and Data Scientists’ favourite, Jupyter Notebook on VSCode.
Sometimes, you may require some extra extension packs, VSCode will smartly suggest you ❤️.
For Julia, I have to set the path manually. So, there are 3 steps to set up Julia.
Install and Download JuliaInstall Julia Extension by julialang in VSCode (Extension ID: julialang.language-julia)Set up Julia Path
Install and Download Julia
Install Julia Extension by julialang in VSCode (Extension ID: julialang.language-julia)
Set up Julia Path
I am fresh to MacOS, so it takes me some time to locate where are the executable file of Julia. For the folks who are fresh to MacOS like me, I will hold your hand thru this ❤️.
For me, I found my Julia in the Application folder.
Right-click on the Julia icon, then select the “Show Package Contents”, it shall lead you to the window below.
In the Content file, there are a few folders. I found the Julia executable in the Resources folder, the complete path to the Julia executable is as follow:
/Applications/Julia-1.7.app/Contents/Resources/julia/bin
Your path might be different from mine, as some of the resources I discovered are different from mine.
You can copy the path to the Julia executable file by right click on it, and then selecting “Get Info”. Stating this because I am really fresh to my Mac yet 😂, everything takes time for me.
So now you get the Julia path. There are two ways to set up the path.
You can open “Settings” by clicking “Manage”, which is the ⚙️ icon at the very bottom of the left panel of VSCode as shown below.
Then, at “Extensions”, select “Julia” and scroll down until you see Julia: Executable Path, paste your path at the space provided.
At VSCode, press these 3 keys on your keyboard, then the command palette shall pop out as follow. You can also open the command palette by going to View on the function bar at the top.
Search and select the “Preferences: Open Setting (JSON)”
"julia.executablePath": "/Applications/Julia-1.7.app/Contents/Resources/julia/bin/julia"
Modify the path as the path you obtained earlier.
Now you are all set.
When I am setting up the R in VSCode, I refer to these two articles.
Setup Visual Studio Code to run R on VSCode 2021A fresh start for R in VSCode by Varun
Setup Visual Studio Code to run R on VSCode 2021
A fresh start for R in VSCode by Varun
Both articles are amazing, but maybe due to new updates of VSCode, there are some slight changes.
I refer to the first article for installation steps and refer to the second article for modifying lines in setting.json.
Download and Install RInstall R package “languageserver” via R console
Download and Install R
Install R package “languageserver” via R console
install.packages("languageserver")
3. Install R Extension pack
There are two R extension packs needed
R by Yuki Ueda (Extension ID: ikuyadeu.r)
R Extension Pack by Yuki Ueda (Extension ID: ikuyadeu.r-pack) — This extension pack include R-LSP extension pack which have been removed from the marketplace in VSCode.
4. Install “radian” via pip
Radian is a python package, hence, you should install Python first if you haven’t done so.
pip3 install -U radian
5. Enable r.bracketedPaste for using Radian
6. Set up executable path
For step 5 and step 6, you can complete them together by updating lines in setting.json as follow.
First, call out the command palette by using the shortcut key Cmd + Shift + P or by the View in Function Bar at the top of the VSCode. Then, search for “Preferences: Open Setting (JSON)” and modify the lines as follows.
{"r.bracketedPaste": true,"r.alwaysUseActiveTerminal": false,"r.rpath.mac": "<path for R executable file>","r.rpath.linux": "","r.rterm.mac": "<path of python packages radian>","r.lsp.path": "<path for R executable file>","r.lsp.debug": true,"r.lsp.diagnostics": true,"r.rterm.option": ["--no-save","--no-restore","--r-binary=<path for R executable file>"]}
Here’s how my setting.json looks like after setting up both Julia and R.
Now you are all set!
Surprisingly the executable file for Python and R is different from Julia. So when I set up the path for R, I had to use find.package(“languageserver”) to locate the path to the library installed, and then find the R executable file.
We have just finished setting up Python, Julia, and R in VSCode 😄. Now you can use all three languages in one single IDE.
Well done!
Subscribe on YouTube
Congrats and thanks for reading to the end. Hope you enjoy this article. 😁
Happy new year!