Cannot change Flask application Python version with runtime.txt

To deploy my Flask application, I have added a runtime.txt file otherwise Netlify defaults to Python 2.7. In the runtime file, I wrote python-3.7.2. When I deploy it on Netlify, the build keeps failing.

This is the error that I get.

3:19:04 PM: Installing dependencies
3:19:04 PM: /usr/local/bin/run-build-functions.sh: line 170: /opt/buildhome/pythonpython- 
3.7.2/bin/activate: No such file or directory
3:19:04 PM: Error setting python version from runtime.txt
3:19:04 PM: failed during stage 'building site': Build script returned non-zero exit code: 1

I’ve read the docs, searched online for 3 hours and still no fix. Any advice would be greatly appreciated.

I’m not sure on the versions allowed, but try putting only the version number without the python- prefix.

I answered this on SO, but it was never marked as the correct answer.

1 Like

Wow, it actually worked! Thank you!

Now, I get this error:

7:33:49 PM:   ERROR: Could not find a version that satisfies the requirement pywin32==224 (from -r requirements.txt (line 6)) (from versions: none)
7:33:49 PM: ERROR: No matching distribution found for pywin32==224 (from -r requirements.txt (line 6))
7:33:50 PM: Error installing pip dependencies
7:33:50 PM: Error running command: Build script returned non-zero exit code: 1

I tried to installing pypiwin32, it still doesn’t work

7:39:13 PM: Collecting pywin32>=223 (from pypiwin32->-r requirements.txt (line 6))
7:39:13 PM: ERROR: Could not find a version that satisfies the requirement pywin32>=223 (from pypiwin32->-r requirements.txt (line 6)) (from versions: none)
7:39:13 PM: ERROR: No matching distribution found for pywin32>=223 (from pypiwin32->-r requirements.txt (line 6))
7:39:14 PM: Error installing pip dependencies
1 Like

Wonder if it is a version issue.

I tried removing the version number and even changing it to a different number but it still doesn’t work

What is the pywin32 package? I doubt we need it in our environment since there is no “win” here :wink: , either while building or serving.

Versions of Python allowed are shown here, depending on which build image you use

for Xenial/Ubuntu 16.06: https://github.com/netlify/build-image/blob/xenial/included_software.md
For Trusty/Ubuntu 14.04: https://github.com/netlify/build-image/blob/trusty/included_software.md

So to use version 2.7 (included as default in both images), I’d use a runtime.txt that is literally:

2.7

without a “v”, or patchlevel, or trailing carriage return.

1 Like

Changed the runtime to just 3.6

Also removed the package pywin32 and replaced it with tkinter. Now I get this error when deploying

5:10:37 PM: Executing user command: python main.py
5:10:37 PM: Traceback (most recent call last):
5:10:37 PM:   File "/usr/lib/python3.6/tkinter/__init__.py", line 37, in <module>
5:10:37 PM:     import _tkinter
5:10:37 PM: ModuleNotFoundError: No module named '_tkinter'
5:10:37 PM: During handling of the above exception, another exception occurred:
5:10:37 PM: Traceback (most recent call last):
5:10:37 PM:   File "main.py", line 2, in <module>
5:10:37 PM:     from tkinter import Tk, font
5:10:37 PM:   File "/usr/lib/python3.6/tkinter/__init__.py", line 39, in <module>
5:10:37 PM:     raise ImportError(str(msg) + ', please install the python3-tk package')
5:10:37 PM: ImportError: No module named '_tkinter', please install the python3-tk package
5:10:37 PM: Skipping functions preparation step: no functions directory set
5:10:37 PM: Caching artifacts

I’m not sure we have tk in the build environment, which I assume would be needed to build that extension. Mind including a link to your build logs so we can check them out in-situ to see if they have any more information that would be helpful?

Yes, you are correct. Here is a link to the Build Log.
https://pastebin.com/sZcbRp6k

Thanks @SaiG, but can you give an actual link to the deploy log or provide us with the deploy ID from the URL of the deploy log? Also, have you tried changing the build image to Trusty instead of Xenial? That may work better for you.

Here is the deploy link:
https://app.netlify.com/sites/fontscan/deploys/5d0be34972e961de80bca4dd

This s deploy ID form the URL: 5d0be34972e961de80bca4dd

Thanks for that.

Last we said was “I don’t think tk is in the build environment.”, and I’ve confirmed that to be true, and it seems like it would need a fix beyond what you can affect during build, based on my reading of this thread: https://askubuntu.com/questions/815874/importerror-no-named-tkinter-please-install-the-python3-tk-package

If you actually plan to use tk, rather than just testing with it, you can file a feature request here: https://github.com/netlify/build-image/issues (or better, a PR adding it: https://github.com/netlify/build-image/pulls). However, it makes sense that that particular package doesn’t work right now, and you are the first person to ever ask for it, so we’ll probably not get it shipped too soon even if you do request it there, but we’ll put it in the backlog and let you know if we do.

A PR is likely to get applied sooner but still not “in the next week” kind of timeline.