nb! These instructions apply to Thonny since version 3.0
The main Thonny+Python bundles are designed to be installed by the end user. Therefore the Windows and Linux installers don't require admin privileges and install under the user home (%LOCALAPPDATA%\Programs\Thonny
or ~/apps/thonny
respectively) by default. For macOS it's a non-issue -- you simply copy the app bundle where you want it.
The Thonny Windows installer also has an all-users mode -- for this you just need to run it as administrator (Right-click and "Run as administrator").
In Linux you can either install the thonny
package from your distro's repository (this may be an older version) or you can simply run the bundle installer with sudo
and choose a target directory which is accessible for all users. If the target directory is outside of /home
, the installer creates a launcher for all users.
If the computer lab supports persistent user profiles and the users' disk quota is big enough, then the single user deployment scheme is also suitable in the classroom setting. (Depending on your lab set-up you may want to recommend students to install into ...\AppData\Roaming\...
instead of ...\AppData\Local\...
in Windows.)
Most likely the admins will want to install it for all users (see above). The installation procedure can be scripted (see http://www.jrsoftware.org/ishelp/index.php?topic=setupcmdline for instructions about command line usage of the Windows installer). You can install Thonny either locally or to a network drive.
You can pre-configure Thonny for all future users by arranging a suitable configuration.ini
in their Thonny user directory (see below). You can do it by letting Thonny know how to initialize that directory. For this you should create a directory named user_dir_template
under the thonny
-package (eg. P:\ClassroomNetworkPrograms\Thonny\Lib\site-packages\thonny\user_dir_template
). This directory will be copied as the Thonny user directory for all users who haven't run Thonny yet.
For example, if you want to use a separate Python installation for the backend, the configuration.ini should be something like this:
[run]
backend_name = CustomCPython
[CustomInterpreter]
path = C:\Python37-64\python.exe
You can arrange your shared Thonny so that the students can start off with the same set of 3rd party packages.
Just pip-install the required packages and plug-ins directly into the site-packages
of the bundled Python (or external Python if so configured). The easiest way for this is to open Thonny, select "Tools => Open system shell..." and use command-line pip.
nb! Each time you re-install Thonny, its program directory will be cleaned first. This means that the shared packages you installed into the bundled Python's site-packages
need to be reinstalled after reinstalling/upgrading Thonny.
If you use only a couple of packages then have your students install these one-by-one via "Tools => Manage packages". Alternatively have them use them from the command line, but pay attention as to whether to use --user
or not.
Since version 3.2 the same dialog also allows installing from a requirements.txt file.
You can put the Thonny+Python bundle onto an external hard-drive or USB stick and run it in compatible systems without installing anything.
Since 3.2 Thonny will work in portable mode simply when being run from a removable drive. In this mode it keeps (almost) all traces of its work (configuration files, logs) within its program directory.
- In Windows extract the zip-file from the release page to the removable drive. Launch the program with
thonny.exe
- (Since 3.2) In Linux extract the tar.gz file from the release page to the removable drive. Delete (or ignore) the
install
andinstall.py
files. Launch the program withbin/thonny
. - (Since 3.2) In macOS simply copy the app bundle to the removable drive. Launch the program as usual.
nb! Always pay attention to the installation target directory in "Tools => Manage packages" and "Tools => Manage plug-ins". Unless you are using a virtual backend, Thonny will install new packages to global user-site-packages even when running in portable mode. This will probably be changed in version 4.0 (#718).
If you want to add new 3rd party packages to your portable Thonny, then install them directly into main site-packages (Tools => Open System shell and pip install ...
).
See here.
Independently of the Thonny program files' location, on the first run it creates a directory which is used for storing user configuration and logs. The path of this directory is chosen as follows:
- if environment variable
THONNY_USER_DIR
is defined ⇒ the value of this variable - else if Thonny runs in portable mode ⇒
user_data
under the main directory of the program (Since 3.2) - else if pip-installed into a virtual environment ⇒
.thonny
under the root of the environment - else if installed on Windows ⇒
%APPDATA%\Thonny
- else if installed on macOS ⇒
~/Library/Thonny
- else if installed on Linux ⇒
$XDG_CONFIG_HOME/Thonny
(usually~/.config/Thonny
)
This directory can be opened when you select "Tools => Open Thonny data directory" in Thonny.
At launch time Thonny looks for a script named customize.py
under thonny package (eg. C:\Users\Aivar\AppData\Local\Programs\Thonny\Lib\site-packages\thonny
). If present, this is run before the main launch procedure.
You can use this to prepare the environment for Thonny, eg:
import os
os.environ["AN_IMPORTANT_ENV_VAR"] = "1234"