Skip to content

Code Editors

Code editors can help a lot when programming.

Editors can help you autocomplete the things that you need to write (similar to your smartphone). And editors can help you detect errors in your code.

For editors to be able to provide all these features, they need to know about the packages you use in your code.

When programming in Python, for editors to know about those packages you use in your code (and in your virtual environment), they need to know about that virtual environment.

The way to do this is normally to tell your editor which Python program to use.

Normally you configure your editor to use the Python program inside of the directory in your virtual environment.

Open your editor

Open your editor and select that environment.

Visual Studio Code

If you have Visual Studio Code and a shell like Bash, you can just run:

$ code ./

In any case, make sure you select the environment you just created for your editor.

If you use Visual Studio Code, make sure you have the Python Extension.

You can then create a dummy file dummy.py and open it. That will make VS Code load the extension and show the Python environment used.

In the lower left corner you will see the Python version used, if you click it, you can select a different one.

After this, you can delete the dummy.py file.

PyCharm

If you use PyCharm as your editor, open it.

Select your project directory ./apiapp/ as the workspace.

Then Configure a Python interpreter for your project, and select the interpreter inside of the environment you just created.

Using the correct environment

Using the correct environment in your editor as we described here and opening it exactly in your project directory will make your editor know the installed packages and will let it provide autocompletion, type checks, relative imports, etc.

If you didn't configure the environment correctly or if you didn't open it exactly in your project directory (for example, you open one directory above), your editor won't be able to give you all those features.