Python programming on the MSS
Programming in Python can be taught on the My sCool Server right out-of-the-box. It comes pre-installed with Python 2.7.x and Python 3.6.x. You may teach or practise via one of the following tools -
- Terminal
- IDLE (Integrated Development and Learning Environment)
- SciTE
Below are a few common to-dos that shall ease your experience of Python programming on the My sCool Server.
Terminal
Open a Terminal and activate the pre-configured virtual environment that contains several modules and libraries needed to teach Python at school.
For activating the Python 3.x virtual environment, execute :
- source /usr/local/share/msspython3/bin/activate
For activating the Python 2.x virtual environment, execute :
- source /usr/local/share/msspython2/bin/activate
Once done with the programming session, to exit, execute :
- deactivate
To explore more about Python virtual environments, a very powerful tool and concept, continue reading
herein.
IDLE (Integrated Development and Learning Environment)
IDLE is Python’s Integrated Development and Learning Environment.
On the MSS, IDLE has been pre-configured to use the Python 3.x from the virtual environment. So you may start teaching and learning right away.
SciTE
SciTE is a SCIntilla based Text Editor. Originally built to
demonstrate
Scintilla, it has grown to be a generally useful editor with facilities for
building and running programs.
Configuring SciTE for custom experience
SciTE has a lot of
configuration settings, which are read from
~/.SciTEUser.properties
(user-specific) and
/usr/share/scite/SciTEGlobal.properties
(global). Both of these files can be accessed from the
Options menu of SciTE.
You may edit your user-specific ~/.SciTEUser.properties
residing in your home directory via the SciTE Options -> Open User Options File menu option.
Herein below are given the two main custom settings that may be needed by every user. Those interested in further guidance and tips may visit
this article.
Making Python 3.x the default in SciTE instead of Python 2.x
By default, SciTE is configured to use python i.e. Python 2.7.x to execute Python code. However, you may need to use python3 i.e. Python 3.6.x based on your curricular requirements. Don't worry as we have you covered.
Add the following lines to your ~/.SciTEUser.properties
file -
- if PLAT_GTK
- command.go.*.py=/usr/local/share/msspython3/bin/python3 -u "$(FileNameExt)"
- command.build.SConscript=scons --up .
- command.build.SConstruct=scons .
Preserve the indentation while copy/pasting or typing the above lines.
Now when using Tools -> Go the Python version used will be 3.x.
By default, SciTE requires executing a program needing manual inputs via the Terminal. However, it is possible to add an option to the Tools menu to invoke the execution via SciTE itself.
Add the following lines to your ~/.SciTEUser.properties
file -
- if PLAT_GTK
- command.name.0.*.py=Go in Terminal
- command.0.*.py=mate-terminal -x sh -c "\
- $(command.go.*.py);\
- echo;\
- read -p 'Hit enter to close ...' x\
- "
Preserve the indentation while copy/pasting or typing the above lines.
Now you shall see Tools -> Go in Terminal option. Use this when executing programs that need a manual input.
Those interested in digging deep into this customisation and its limitations may refer this
excellent document.
Installing additional Python modules
There may be a need to install additional Python modules to teach / learn advanced concepts. This can only be done by a teacher or admin who has access to the mssadmin credentials.
Herein is an example showing how one may install the mysql-connector module in the Python 3.x virtual environment while being logged into a MSS client -
- ssh mssadmin@server
- sudo su -
- cd /usr/local/share/msspython3/
- source bin/activate
- pip install mysql-connector
- deactivate
Explanation of the above steps :
Step 1: Login to the admin account onto the MSS. Enter mssadmin's password when prompted.
Step 2: Become superadmin on the MSS. Enter mssadmin's password when prompted.
Step 3: Navigate to the Python 3.x virtual environment directory
Step 4: Activate the virtual environment
Step 5: Install the mysql-connector module
Step 6: Deactivate and exit the virtual environment