How do you set Python version in Sonarcloud UI?

With all of my analyses, I now get the warning message:
"Your code is analyzed as compatible with python 2 and 3 by default. This will prevent the detection of issues specific to python 2 or python 3. You can get a more precise analysis by setting a python version in your configuration via the parameter “sonar.python.version”

I reviewed this ticket but it isn’t clear to me how to set the Python version for the property sonar.python.version in the Sonarcloud UI.

Hi Vince,

Not all parameters are settable in the UI. In this case you will have to set the property sonar.python.version manually.

Since you are analyzing a Python project, I assume that you are using automatic analysis, in which case you need to add a file called .sonarcloud.properties to the root of your repo and set sonar.python.version in there. See https://sonarcloud.io/documentation/advanced-setup/automatic-analysis/#additional-analysis-configuration

If you are using a CI-based analysis then you would do the same except in a file called sonar-project.properties or on the command line of the scanner.

Sorry for reviving the topic, but we’ve got a similar issue, and I’ve been struggling to find anything in the documentation on this subject.

@Peeter_Piegaze What kind of format should this setting be?

We’ve tried the following:

# in .sonarcloud.properties
sonar.python.version=3

# in .sonarcloud.properties
sonar.python.version=3.9

# in sonar-project.properties
sonar.python.version=3

None of these seems to work – we’re still getting the warning in SonarCloud console.

Hi Magda,

The format for the Python version should be a comma-delimited list of versions having the format “X.Y”

Examples:

  • sonar.python.version=2.7
  • sonar.python.version=3.8
  • sonar.python.version=2.7, 3.7, 3.8, 3.9

As described here: https://sonarcloud.io/documentation/advanced-setup/languages/python/

Which file you put this in depends on whether you are running automatic analysis or a CI-based analysis.

In the former case, you would put this property declaration in the file .sonarcloud.properties. In the latter case, you would put it in sonar-project.properties.

I hope this helps.