How to use an old Python version

Hi guys,
I’m trying to implement snapcraft within the Kivy Buildozer tool. The problem is that buidozer packager use an old version of Python (I do not know why, but I think it’s due to some compatibility issues) and I would like to use the same version with the snapcraft Python plugin.

So my question is:
Can you download an older version of Python on Snapcraft?


1 Like

Yes, there’s no constraint on what you can do to package the software you need inside a given snap. You’ll just need to be careful to organize the content in a way that allows that Python to work from within the snap path (/snap/yoursnap/current/usr/bin or similar).

We also have a feature coming that will simplify some of that significantly, allowing you to map part of the snap content in arbitrarily locations in the filesystem.

Someone else might have more detailed hints on how to install the old Python version that could make your life easier. I haven’t gone through that myself.

Thanks Niemeyer for your reply.
What i meant is if is possible to download the required Python version automatically with the standard python plugin.
For example, with a specific plugin keyword that change the downloaded python version.

I do not refer to the already existing Keyword named python-version, but something that change from Python 2.7.13 to 2.7.2.

Thanks again

Great question @Tungsteno. The python plugin, as you noticed, doesn’t support this. It uses the python from the archives, and is thus limited to what is available there. However, nothing prevents you from building whatever version of upstream Python you want as a part. In fact, the Snapcraft snap itself does exactly that, so you can learn by referring to it.


The go plugin behaves like the python plugin. It’s not obvious how to override the go compiler being used.

Me thinks this should be documented in the plugins’ help outputs to make it more discoverable.

1 Like

@kalikiana this is a good tip. I will check better later.
@kyrofa Are you saying that as an alternative to the default python plugin I could use the dump plugin to import a custom Python version into my snap, right?

The dump plugin would only work if you had a Python installation already built lying around somewhere. You probably want to actually build the exact version of python you want, which would use the autotools plugin, as done in Snapcraft.

I read posts on your link and what said here is what i need. The Go part mentioned in your link would solve my problem properly. Unfortunately I noticed that it is not available for Python.
Do you have any suggestions for finding something similar to Python?


What happened to my main post???
I’m trying to solve a problem with an open-source project that i do not own and i receive a notification that this post has been hidden because someone in the community flag that topic as spam?

Now as I’m near to solve that problem i really can’t know if i can post the solved solution here or not (for those in the future will have the same problem) because the solution is a link to a github test snap, and it seem to me that links here are checked as spam.

Weird forum… very helpful…I hope someone can fix the problem, because I would not start hating the support of this excellent tool.

@kyrofa @kalikiana @niemeyer

Huh, indeed, it tells me that it got flagged as well. Don’t worry, we’ll get it sorted :slight_smile: .

1 Like

Thanks @kyrofa for your contribution.
At least I can still post under this topic.

I checked the link you suggested and I think I have found an acceptable solution.
It seems that I fixed the problem with the following snapcraft.yaml (a modified htmlstat test example hosted on Github):

name: python
version: '0.1'
summary: Build any version of Python.
description: |
  This snapcraft part allows to build programs with any version of Python.
    Add "after: [python]" to your part written in python. By default, this will use the latest Python
    from the master branch to compile your program.
    If you want to specify a Python version, also add a Python part with the version as
    the source-tag value. For example, to use Python 2.7.2, use:
          after: [python]
          source-tag: v2.7.2
confinement: strict

    plugin: autotools
    source-type: git    
    configflags: [--prefix=/usr]
    build-packages: [libssl-dev]
    stage-packages: [curl] 
    #prime:  #raise "IOError invalid Python installation unable to open /snap/httpstat/x1/usr/include/python2.7/pyconfig.h (No such file or directory)" with 2.7.4 and earlier
     # - -usr/include  #python 2.7.4 and earlier work well without that line (seem work well without above 2.7.4 too). 

Now, what I want to understand is whether the line under the “prime” keyword is essential for the proper functioning of the snap. I wonder why, as you can see from comments, by removing it I can build a custom (old) Python version with that example (tested from 2.7.2 to 2.7.13).

Do you know anything more about that path?


The python page here says:

Here are some snap advantages that will benefit many Python projects:

Bundle all the runtime requirements, including the exact versions of system libraries and the Python interpreter.

I didn’t see much documentation on doing that so I went to the forums. Then I don’t even see a reply to this post.
I additionally found this blog post.

I don’t want to be pessimistic, but it seems Snapcraft is leaving an awful lot of opportunity for improving their python support out there. Am I missing a cache of documents or examples somewhere?

If Canonical is interested in getting snap used more in the python world they are likely going to have to provide some of the conveniences of docker. It is easy to target python versions in docker and there are alpine images with all the python versions already available.

something like this in the yaml file:

plugin: python3.6 (newest in 3.6 series)
plugin: python3.6.0 (specific version)

plugin: python 3.6.6 (specific version)
plugin: python3.7 (newest in 3.7 series)

These should be readily downloadable in compiled form for Intel and ARM platforms.

Compiling python is a time consuming process (especially on slower IoT devices). And downloading a bunch of dev libs and tools over slow and expensive cellular links is not really feasible. Would the compilation occur every time somebody did a snap install? (Are the compiled versions stored online to save someone the time afterwards? Is “autotools” downloaded if the compiled code is available?