Deployment options (since version 3.0)
Main Thonny+Python bundles are designed to be installed by the end user. Therefore Windows installer does not require admin privileges and installs under %LOCALAPPDATA%\Programs\Thonny by default. Since version 2.1.21 the installer has also all-users mode -- for this you just need to run it as administrator (Right-click and "Run as administrator").
Independently of Thonny main files' location, on first run it creates a user data directory which is used for storing user configuration and logs. The path to this directory is
- %APPDATA%\Thonny on Windows
- ~/Library/Thonny on macOS
- $XDG_CONFIG_HOME/Thonny (usually ~/.config/Thonny) on Linux
- (When Thonny is pip-installed into a virtual environment, the user directory will be .thonny in the root of the virtual environment.
This directory can be opened when you select "Tools => Open Thonny data directory" in Thonny.
If the computer lab supports persistent user profiles and users' disk quota is big enough, then the single user deployment scheme is suitable also in classroom setting. (Depending on your lab set-up you may want to recommend students to install into ...\AppData\Roaming\... instead of ...\AppData\Local\....)
Most likely the admins want to install it for all users (see above). The installation program can be scripted -- see http://www.jrsoftware.org/ishelp/index.php?topic=setupcmdline for details. You can install Thonny either locally or to a network drive.
You could pre-configure Thonny for all users by arranging a suitable configuration.ini in their Thonny user directory. Since version 2.1.10 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 thonny-package (eg. P:\ClassroomNetworkPrograms\Thonny\Lib\site-packages\thonny\user_dir_template).
For example, if you want to use a separate Python installation for the backend:
[run] backend_name = CustomCPython [CustomInterpreter] path = C:\Python36-64\python.exe
Changing the location of user directory
Regardless of your deployment scheme, you may want to override the path of Thonny user directory. This can be done with THONNY_USER_DIR environment variable. You could create a launch script which sets this variable and then runs Thonny, or you can read further ...
Since version 2.1.10 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 as first step of launching.
You can use this to prepare the environment for Thonny, eg:
import thonny thonny.THONNY_USER_DIR = "H:\\home\\.thonny"
Creating a portable version of Thonny
You can use the information from previous sections to prepare yourself a portable, USB-stick-ready Thonny.
Following customize.py should do:
import os.path import thonny user_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..", ".thonny") thonny.THONNY_USER_DIR = os.path.abspath(user_dir)
pip-installing Thonny to an existing Python