Defining which python version streamlit uses

I am developing my streamlit apps on a windows machine, then deploy on a aws-linux-ami server. I recently upgraded python on aws to 3.9.0.
python3 – version shows 3.9.0.

however if I output the version within the streamlit app using st.write(sys.version_info) I get the formerly installed 3.6.12:
sys.version_info(major=3, minor=6, micro=12, releaselevel=‘final’, serial=0). is there any variable I need to set to force streamlit to use the newes python version? thanks in advance for any help on this.

1 Like

Hi @godot63 -

This is a function of what is installed on the aws-linux-ami. If you want to have a different version of Python, you can install it from, use virtualenv, or use conda to create a specific environment.

It sounds like what’s happening currently is that you’re using the system install of Python in the AMI, which tends to lag the newest version by several months (and sometimes, years).


thanks Randy
I had installed my Python 3.6 and streamlit must have installed in this folder and used therefore Python 3.6 even if I later installed 3.9. It now seems logical. I followed your advice and made a virtual env but now I run in the following problem:

import ctypes
  File "/usr/local/lib/python3.9/ctypes/", line 8, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

I had this on a windows machine once and fixed it by installing the c libraries. I tried ot do something similar on my linux machine. This is what I used to install Python 3.9, I was under the impression that it would include the steps to install the required c libraries:

$ wget
$ tar zxvf Python-3.9.0.tgz
$ cd Python-3.9.0
$ sudo yum -y install gcc gcc-c++ 
$ sudo yum -y install zlib zlib-devel
$ sudo yum -y install libffi-devel 
$ sudo ./configure --prefix=/opt/python3
$ sudo make
$ sudo yum install openssl-devel
$ sudo make install

any suggestions how to make the <No module named ‘_ctypes’> error go away?

1 Like

Are you compiling Python from source? If so, not sure I’ve got much to suggest, as I just use pre-built versions.

yes, since the newest builbuilt version for AMI seems to be 3.6.12, and I needed 3.8 for a sqlite3 feature, I tried to follow instructions how to compile python from source. it seems to work fine, but I still get the _ctypes error. in the meantime I have worked around the sqlite3 feature (printf statement) and am using again version 3.6, for the time being. thanks anyways for looking into this.

In that case, if you’re just looking for an updated version, you can download miniconda and avoid the compilation cycle:

I do this on every machine I use, so that I can create a fresh conda environment for each project, which also allows me to install whatever Python version I choose.

Unless you are looking to make changes to base Python, I wouldn’t recommend trying to build it from source. Life is too short for that :laughing: