FAQ/common problems#

Please search on this page if you can not find an exact match. We welcome any suggestions for FAQ entries, please contact us at pythonsupport@dtu.dk or on our Discord channel.

VS Code and virtual environments#

This is particularly tricky configuration since it depends on the way you have setup VS Code.

VS Code works in two ways:

Workspaces

A special folder with custom VS Code configurations

Basically if your EXPLORER shows a top folder name according to a folder, you will be working in a workspace.

One cannot change the interpreter in VS Code workspaces (as one would generally do.

In this case you can only get virtual environments to work by following this:

  1. Open the VS Code terminal (press Ctrl-Shift-P, or Command-Shift-P on Mac) and search for python env, select the menu Python: Create Environment

  2. Now two additional options open up, choose Venv

  3. Wait until it is done.

  4. Execute a single line of code, e.g. exit() + Shift-Enter to force the virtual environment being activated in the terminal associated with the workspace (you should see that the left of the terminal shows .venv). Then it will execute the exit() code and return to the terminal.

    Alternatively you can press the button to run the currently opened script.

Warning

The terminal will not be in the virtual environment if VS Code is freshly opened and you have not executed any Python code.

Click this box to get information about workspaces.

https://code.visualstudio.com/docs/editor/workspaces

File editing

Single file scripts

If not in a workspace (see above), you can freely select the interpreter.

If you have a Python file open (extension .py), you will see a Python block at the bottom right. To the right of this small box, you can press a button which lets you choose the interpreter.

This should be a full path to the python interpreter (a Python executable). There will generally be a list of Python executables present to choose from, if your wanted interpreter is not present, you’ll have to navigate manually to the wanted interpreter.

Click this box to get additional details regarding changing the interpreter.

https://code.visualstudio.com/docs/python/environments#_manually-specify-an-interpreter

Windows only problems#

Windows execution policy in PowerShell#

Some times a Windows setup has disabled default execution policies.

This happens when you find an error message looking like:

AuthorizationManager check failed.
At line:1 char:1
+ C:\scriptpath\scriptname.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

Or, something similar (depending on versions etc.)

To enable execution do the following:

  1. Open PowerShell in administrator mode: Search for powershell in the windows search bar

  2. Select Run as administrator

  3. Execute this code:

    Set-ExecutionPolicy Unrestricted
    

    Important: Press A when asked (not Y)!

Restart any terminals (including VS Code) and try again.

Click here to get more information about execution policies.

ImportError: DLL load failed ...#

When importing dtumathtools some Windows machines are missing certain libraries.

The error can look similar to this:

ImportError: DLL load failed while importing _cext: The specified module could not be found
  1. Click here and download (most likely) the X64 one.

  2. Install the application

  3. Re-start your editor (or machine) and try again If it still does not work, then try the X86 version.

  4. If problems still occur, please write us at pythonsupport@dtu.dk

ERROR: Could not install packages due to an OSError: ...#

The exact error message can look different depending on when you encounter this error. It happens because of a default limitation of 260 characters in file names.

The remedy is quite simple, download this script and double-click it.

Now try to install the packages again.