Installation
Prerequisite¶
- You need Python >=3.8 to run the
twa. You can install Python by going to the official Python download page - You also need to install a Java Runtime Environment version 11
Virtual environment setup¶
It is highly recommended to use a virtual environment before installing the twa package. The virtual environment can be created as follows:
(Windows)
(Linux)
The above commands will create and activate the virtual environment twa_venv in the current directory. The terminal display for new commands will be as follows (to facilitate direct copying and pasting of commands from this documentation into the command line, the virtual environment prefix will be omitted throughout the remainder of the documentation):
Alternatively, if one wish to use conda for managing environments, please follow the instructions provided on the conda website.
Installation via pip¶
To install the twa simply run the following command:
The above command will install the twa package including the JpsBaseLib Java library that has been packaged together with the Python code.
[For developers] Installation from the version-controlled source¶
This type of installation is only for the developers. To install twa directly from its repository you need to first clone the TheWorldAvatar project. Then simply navigate to the TheWorldAvatar\JPS_BASE_LIB\python_wrapper directory and execute the following commands:
# build and install
pip install .
# or build for in-place development
pip install -e .
# or use the provided "install_wrapper.sh" convenience script,
# that can create virtual environment and install the twa package in one go
# build and install
install_wrapper.sh -v -i
# or build for in-place development
install_wrapper.sh -v -i -e
The above commands will install the twa Python package only. To include the JpsBaseLib Java library, i.e. the JPS_BASE_LIB library, please follow the below steps:
- Navigate to the
TheWorldAvatar\JPS_BASE_LIBdirectory and build theJPS_BASE_LIBproject: - Go to the
JPS_BASE_LIB/targetdirectory and copy the main project jar file,jps-base-lib.jar, and the entirelibfolder containing the project dependencies into a temporary directory, let us call ittmp_JpsBaseLib. - Run the following command in the terminal (with the virtual environment where
twais installed activated, e.g.twa_venv): - After successful installation you can access the
JpsBaseLibresource (classes and methods) intwaby simply importing it: - Remove the no longer needed
tmp_JpsBaseLibdirectory.
[For developers] Installing additional java resources¶
The twa project can be easily extended to provide wrapping for other TheWorldAvatar java projects. To do that, all resource files and their dependencies must be collated into a single directory, with the main jar file located at the directory root. The JpsBaseLib pom.xml file shows an example of how to do it with maven. If you wish to do it for other TheWorldAvatar project, simply copy the maven-jar-plugin and maven-dependency-plugin plugins into the project pom file and add the net.sf.py4j dependency. These changes will collate all the project dependencies into the target\lib directory and include the required py4j package in your project. Once that is done and the project is successfully built, the twa resource manager command-line utility, jpsrm, can be used to install and register the resource. Here are the steps:
- Copy the project main jar file and the entire
libfolder a temporary directory, e.g.,tmp_dir. - Run the following command in the terminal (with the virtual environment where
twais installed activated, e.g.twa_venv): wherejpsrmis thetwaresource manager,<YourResourceName>is the name you wish to assign to your java resource, e.g.JpsBaseLibin the previous section. The<from>argument is the absolute path to thetmp_dirwith all the java project files and the--jaroption is used to provide a name of the main jar file,JARFILE, to be used for communication.NOTE that the
<YourResourceName>MUST follow Python's classes names requirements, otherwise it will be impossible to import it in Python. - After the successful installation you can access the resource (classes and methods) in
twaby simply importing it: - Remove the no longer needed
tmp_dirdirectory.
[For developer] jpsrm resource manager¶
jpsrm is a resource manager to effectively manage the Java packages in twa. To see all jpsrm commands and options, run jpsrm -h in the terminal.
NOTE The
jpsrmincludes a developer-only convenience commanddevinstallwhich will run all the installation steps for theJpsBaseLibresource. The command will only work if: - theJPS_BASE_LIBproject is present and was successfully built - thetwaproject was installed in a developer mode (-e option) inside theTheWorldAvatarrepository
Here is how to execute the devinstall command: