Uncategorized

Install Python 3.9 on Raspberry Pi OS or Debian 10 (for Ansible or other uses)

I’ve started getting a lot of bug reports on my repos to the effect of “Ansible won’t install on my Raspberry Pi anymore”. Accompanying it is a debug message like one of the following:

$ python3 -m pip install ansible
...
No matching distribution found for ansible-core<2.13,>=2.12.0 (from ansible)

# Alternatively:
ERROR: No matching distribution found for ansible-core<2.13,>=2.12.0

The problem is ansible-core 2.12 has a new hard requirement for Python 3.8 or newer. And ansible-core 2.12 is included in Ansible 5.0.0, which was recently released. Raspberry Pi OS, which was based on Debian 10 (“Buster”) until recently, includes Python 3.7, which is too old to satisfy Ansible’s installation requirements.

There was recently a fix that makes it so Ansible 5.x won’t get installed on these older systems, but who wants to get stuck on old unsupported Ansible versions?

There are three options:

  • Stick with Ansible 4.x or earlier
  • Switch to Debian 11 “Bullseye” (download the latest version of Pi OS) or another newer OS that has Python 3.8 or later by default.
  • Install at least Python 3.8

Workaround: Stay on Ansible 4.x

The easiest workaround for now is to install the latest version of Ansible 4, which uses ansible-core 2.11, which is compatible with the version of Python (3.7) that ships with Debian 10 Buster. To do that, run:

$ python -m pip install --user ansible==4.9.0

That should work, and as long as you don’t try upgrading to Ansible 5, you’d have a stable (if no longer supported) version of Ansible running.

Best fix: Install Python 3.9

It’s best to upgrade Python so you can install the latest version of Ansible cleanly. Unfortunately for those with older OSes that don’t have a pre-packaged version of Python available, you will need to either deal with the complexity of pyenv, or build a newer version of Python from source.

If you’re running Debian 10 or the slightly-older version of Raspberry Pi OS based on it, you can still install Python 3.9 using apt, but you’ll need to update your ‘apt sources’ to pull down a newer version of Python.

Edit /etc/apt/sources.list:

$ sudo nano /etc/apt/sources.list

Then add the following line to the bottom of the file and save it:

deb http://http.us.debian.org/debian/ testing non-free contrib main

Now, to install Python 3.9, run:

$ sudo apt update
$ sudo apt install -y python3.9

Now you should start seeing a Python 3.9 version installed:

$ python3 --version
Python 3.9.9

And you can now install the latest version of Ansible without an issue:

$ python3 -m pip install ansible

Note: If you get an error like AttributeError: 'HTMLParser' object has no attribute 'unescape', try running python3 -m pip install --upgrade setuptools and then try installing Ansible again (thanks to this answer for the solution). You may also get an error like can't find Rust compiler'—if so, also runpython3 -m pip install –upgrade pip` and then try installing Ansible again.

Note 2: Please read through the first few comments below for suggestions on how to do this while also pinning the change to just Python—if you don’t do that, you could end up upgrading a lot of other packages unintentionally, leading to system breakage!

Now verify that Ansible’s installed:

$ python3 -m pip freeze
ansible==5.0.1
ansible-core==2.12.0
cffi==1.15.0

 

 

 

Load more 3001
Load more 3002
Load more 3003
Load more 3004
Load more 3005
Load more 3006
Load more 3007
Load more 3008
Load more 3009
Load more 3010
Load more 3011
Load more 3012
Load more 3013
Load more 3014
Load more 3015
Load more 3016
Load more 3017
Load more 3018
Load more 3019
Load more 3020
Load more 3021
Load more 3022
Load more 3023
Load more 3024
Load more 3025
Load more 3026
Load more 3027
Load more 3028
Load more 3029
Load more 3030
Load more 3031
Load more 3032
Load more 3033
Load more 3034
Load more 3035
Load more 3036
Load more 3037
Load more 3038
Load more 3039
Load more 3040
Load more 3041
Load more 3042
Load more 3043
Load more 3044
Load more 3045
Load more 3046
Load more 3047
Load more 3048
Load more 3049
Load more 3050
Load more 3051
Load more 3052
Load more 3053
Load more 3054
Load more 3055
Load more 3056
Load more 3057
Load more 3058
Load more 3059
Load more 3060
Load more 3061
Load more 3062
Load more 3063
Load more 3064
Load more 3065
Load more 3066
Load more 3067
Load more 3068
Load more 3069
Load more 3070
Load more 3071
Load more 3072
Load more 3073
Load more 3074
Load more 3075
Load more 3076
Load more 3077
Load more 3078
Load more 3079
Load more 3080
Load more 3081
Load more 3082
Load more 3083
Load more 3084
Load more 3085
Load more 3086
Load more 3087
Load more 3088
Load more 3089
Load more 3090
Load more 3091
Load more 3092
Load more 3093
Load more 3094
Load more 3095
Load more 3096
Load more 3097
Load more 3098
Load more 3099
Load more 3100
Load more 3101
Load more 3102
Load more 3103
Load more 3104
Load more 3105
Load more 3106
Load more 3107
Load more 3108
Load more 3109
Load more 3110
Load more 3111
Load more 3112
Load more 3113
Load more 3114
Load more 3115
Load more 3116
Load more 3117
Load more 3118
Load more 3119
Load more 3120
Load more 3121
Load more 3122
Load more 3123
Load more 3124
Load more 3125
Load more 3126
Load more 3127
Load more 3128
Load more 3129
Load more 3130
Load more 3131
Load more 3132
Load more 3133
Load more 3134
Load more 3135
Load more 3136
Load more 3137
Load more 3138
Load more 3139
Load more 3140
Load more 3141
Load more 3142
Load more 3143
Load more 3144
Load more 3145
Load more 3146
Load more 3147
Load more 3148
Load more 3149
Load more 3150
Load more 3151
Load more 3152
Load more 3153
Load more 3154
Load more 3155
Load more 3156
Load more 3157
Load more 3158
Load more 3159
Load more 3160
Load more 3161
Load more 3162
Load more 3163
Load more 3164
Load more 3165
Load more 3166
Load more 3167
Load more 3168
Load more 3169
Load more 3170
Load more 3171
Load more 3172
Load more 3173
Load more 3174
Load more 3175
Load more 3176
Load more 3177
Load more 3178
Load more 3179
Load more 3180
Load more 3181
Load more 3182
Load more 3183
Load more 3184
Load more 3185
Load more 3186
Load more 3187
Load more 3188
Load more 3189
Load more 3190
Load more 3191
Load more 3192
Load more 3193
Load more 3194
Load more 3195
Load more 3196
Load more 3197
Load more 3198
Load more 3199
Load more 3200
Load more 3201
Load more 3202
Load more 3203
Load more 3204
Load more 3205
Load more 3206
Load more 3207
Load more 3208
Load more 3209
Load more 3210
Load more 3211
Load more 3212
Load more 3213
Load more 3214
Load more 3215
Load more 3216
Load more 3217
Load more 3218
Load more 3219
Load more 3220
Load more 3221
Load more 3222
Load more 3223
Load more 3224
Load more 3225
Load more 3226
Load more 3227
Load more 3228
Load more 3229
Load more 3230
Load more 3231
Load more 3232
Load more 3233
Load more 3234
Load more 3235
Load more 3236
Load more 3237
Load more 3238
Load more 3239
Load more 3240
Load more 3241
Load more 3242
Load more 3243
Load more 3244
Load more 3245
Load more 3246
Load more 3247
Load more 3248
Load more 3249
Load more 3250
Load more 3251
Load more 3252
Load more 3253
Load more 3254
Load more 3255
Load more 3256
Load more 3257
Load more 3258
Load more 3259
Load more 3260
Load more 3261
Load more 3262
Load more 3263
Load more 3264
Load more 3265
Load more 3266
Load more 3267
Load more 3268
Load more 3269
Load more 3270
Load more 3271
Load more 3272
Load more 3273
Load more 3274
Load more 3275
Load more 3276
Load more 3277
Load more 3278
Load more 3279
Load more 3280
Load more 3281
Load more 3282
Load more 3283
Load more 3284
Load more 3285
Load more 3286
Load more 3287
Load more 3288
Load more 3289
Load more 3290
Load more 3291
Load more 3292
Load more 3293
Load more 3294
Load more 3295
Load more 3296
Load more 3297
Load more 3298
Load more 3299
Load more 3300
Load more 3301
Load more 3302
Load more 3303
Load more 3304
Load more 3305
Load more 3306
Load more 3307
Load more 3308
Load more 3309
Load more 3310
Load more 3311
Load more 3312
Load more 3313
Load more 3314
Load more 3315
Load more 3316
Load more 3317
Load more 3318
Load more 3319
Load more 3320
Load more 3321
Load more 3322
Load more 3323
Load more 3324
Load more 3325
Load more 3326
Load more 3327
Load more 3328
Load more 3329
Load more 3330
Load more 3331
Load more 3332
Load more 3333
Load more 3334
Load more 3335
Load more 3336
Load more 3337
Load more 3338
Load more 3339
Load more 3340
Load more 3341
Load more 3342
Load more 3343
Load more 3344
Load more 3345
Load more 3346
Load more 3347
Load more 3348
Load more 3349
Load more 3350
Load more 3351
Load more 3352
Load more 3353
Load more 3354
Load more 3355
Load more 3356
Load more 3357
Load more 3358
Load more 3359
Load more 3360
Load more 3361
Load more 3362
Load more 3363
Load more 3364
Load more 3365
Load more 3366
Load more 3367
Load more 3368
Load more 3369
Load more 3370
Load more 3371
Load more 3372
Load more 3373
Load more 3374
Load more 3375
Load more 3376
Load more 3377
Load more 3378
Load more 3379
Load more 3380
Load more 3381
Load more 3382
Load more 3383
Load more 3384
Load more 3385
Load more 3386
Load more 3387
Load more 3388
Load more 3389
Load more 3390
Load more 3391
Load more 3392
Load more 3393
Load more 3394
Load more 3395
Load more 3396
Load more 3397
Load more 3398
Load more 3399
Load more 3400
Load more 3401
Load more 3402
Load more 3403
Load more 3404
Load more 3405
Load more 3406
Load more 3407
Load more 3408
Load more 3409
Load more 3410
Load more 3411
Load more 3412
Load more 3413
Load more 3414
Load more 3415
Load more 3416
Load more 3417
Load more 3418
Load more 3419
Load more 3420
Load more 3421
Load more 3422
Load more 3423
Load more 3424
Load more 3425
Load more 3426
Load more 3427
Load more 3428
Load more 3429
Load more 3430
Load more 3431
Load more 3432
Load more 3433
Load more 3434
Load more 3435
Load more 3436
Load more 3437
Load more 3438
Load more 3439
Load more 3440
Load more 3441
Load more 3442
Load more 3443
Load more 3444
Load more 3445
Load more 3446
Load more 3447
Load more 3448
Load more 3449
Load more 3450
Load more 3451
Load more 3452
Load more 3453
Load more 3454
Load more 3455
Load more 3456
Load more 3457
Load more 3458
Load more 3459
Load more 3460
Load more 3461
Load more 3462
Load more 3463
Load more 3464
Load more 3465
Load more 3466
Load more 3467
Load more 3468
Load more 3469
Load more 3470
Load more 3471
Load more 3472
Load more 3473
Load more 3474
Load more 3475
Load more 3476
Load more 3477
Load more 3478
Load more 3479
Load more 3480
Load more 3481
Load more 3482
Load more 3483
Load more 3484
Load more 3485
Load more 3486
Load more 3487
Load more 3488
Load more 3489
Load more 3490
Load more 3491
Load more 3492
Load more 3493
Load more 3494
Load more 3495
Load more 3496
Load more 3497
Load more 3498
Load more 3499
Load more 3500

Related Articles

Leave a Reply

Back to top button