Write Python programs in VS Code and Codium | Linux China

thumbnail

Guide: If you are looking for an excellent, general-purpose, open-source code editor with Python integration, then you can try Codium.

Number of words in this article: 2560, reading time: 3 minutes

> > If you're looking for a good, general-purpose, open-source code editor with Python integration, then you can give Codium a try. > > >

If you're looking for a good, general-purpose, open-source code editor with Python integration, then you can give Codium a try.

Over the past few years, I have had the pleasure of working with middle school students and introducing them to Python development πŸ”— opensource.com and the Raspberry Pi 400. It's all a lot of fun, and the Raspberry Pi is a great platform for both students and me. We used Code with Mu πŸ”— codewith.mu and everything was successful. Our Python skills grow with experience, so recently I've started looking for ways to give these students something more.

I took a Python course and was exposed to Microsoft's Visual Studio Code in the course. I learned a lot in the course about how to set up a virtual environment for Python, and how to configure VS Code for Python programming. During my studies, I also came across Codium πŸ”— opensource.com, which is basically VS Code without the Microsoft branding and telemetry.

If you're looking for a good, general-purpose, open-source code editor with Python integration, then you can give Codium a try. Here's how I set up Codium for Python on a Linux system.

Install or update Python on Linux

First, make sure you're running the latest version of Python. You can use your package manager to do this. On Debian and Debian-based systems:

$ sudoapt install python3-pip

On Fedora, CentOS, Mageia, OpenMandriva and similar systems:

$ sudodnf update python3

On some systems, you may also need to install software that creates Python virtual environments:

$ sudoapt install python3.10-venv

Install Codium

Next, install Codium πŸ”— github.com on your computer. On Linux, you can download a package and install it using your package manager, or use Flatpak πŸ”— flathub.org.

After installing Codium, open your application or activity menu and enter the code to launch it.

Install the VS Code Python extension

Code isn't really anything special. It's just plain text interpreted by some other application (compiler or runtime). You can write Python code in Codium without special extensions. However, there is a Python extension that brings you some handy features.

Click the "File" menu, select "Preferences", then select "Extensions". In the Extensions panel, search for the Python IntelliSense extension.

Both VS Code and Codium have an extension manager that opens on the left side of the page and allows you to install add-ons

You have set up Python in Codium. All that's left is to put it to use.

Set up a virtual environment for VS Code or Codium

We can create a project directory and add it to Codium so that as you work, files you create and save will default to the active project directory. It's a quick way to manage things without having to constantly click through file save and open dialogs.

When you create a virtual Python environment as a working directory, Codium will detect it (because you have installed the Python extension). When you activate a virtual environment folder as the active project directory, Codium will automatically run the activation code required to use the virtual environment.

To create a virtual environment for Python, open a terminal and type:

$ python3 -m venv ~/PythonCoding

Add project directory

In Codium, click on the "File" menu and select "Add Folder to Workspace". Open the virtual environment you just set up (for me, it was /home/don/PythonCoding).

Now you're ready to write some Python code! Create a new Python file in your workspace and insert some basic code. As you type, you may notice that Codium provides autocompletion suggestions for Python modules included in the environment.

importsys

print("Codium running Python "+sys.version)

Now click the "Run" button in the upper right corner of the Codium window. This will open a console panel at the bottom of the window showing the output of your code:

( PythonCode ) sh - 5.1 $ / home / bogus / PythonCode / bin / python

/home/bogus/PythonCode/app.py

Codiumrunning Python3.10.6(main…)[GCC 12.1.0]

( PythonCode ) sh - 5.1 $

As you can see from the output, Codium was running in the PythonCode environment and successfully ran your Python code.

Codium and Python

Writing Python code with Codium is easier than ever, but Python isn't the only language Codium supports. You can easily find and install additional extensions from the Open VSX Registry πŸ”— open-vsx.org, a neutral open source VS Code extension "marketplace".

Codium's interface is more complex than some basic editors, but it has what I need in my learning process. If you need a more professional editor, or you want to switch from your current editor to a new one, give Codium a try.

via: https://opensource.com/article/22/11/python-vs-code-codium

Author: Don Watkins Topic: lkxed Translator: Cubik65536 Proofreading: wxy

This article was originally compiled by LCTT and released by Linux China Honor

LCTT Translator: Cubik

🌟🌟

Translation: 5.0 articles

|

Contribute: 44 days

2022-10-04

β†’

2022-11-16

https://linux.cn/lctt/Cubik65536

Welcome to reprint in accordance with the CC-BY-SA agreement,

If you need to reprint, please leave a message under the article " Reprint: official account name ",

We will add a whitelist for you and authorize " you can modify the article when reposting ".

Latest Programming News and Information | GeekBar

Related Posts