Advanced labs provide options for installing packages and libraries on the current environment, depending on what language you choose.
Packages installed or uploaded to an advanced lab exist in that lab workspace only. They will persist in the learner's copy of the lab, but not for any other labs you create. Cloning the lab will retain all the packages that were added.
More information about /userdata and /usercode or other environment configurations is available here.
Advanced Labs' pip install
Many language options available in advanced labs include pip functions that allow you to 'pip install' packages and dependencies to the workspace, such as Python.
This includes both the default, CR2 IDE above, and the VSC IDE below.
Jupyter Notebook
In Jupyter notebook, pip install requires !
at the beginning of the cell. For example: !pip install cowsay
Persisting Packages
Once all the necessary packages are installed, you can create a model solution if needed and confirm your code works as expected, then save your assignment.
The template your learners see will include your installed packages, as visible in the VSC example here using pip list:
Any packages added to the template after learners have accessed it will need to be installed by the learners, or they will need to reset the lab to pull your changes to the template. Reset lab will remove their current work.
In order for anything installed with pip install to persist, the .envrc file must include "use service pip".
Python languages include this by default. Other installers like npm may also be used. A workspace can be restarted from the same menu above to confirm the packages are persisting.
Troubleshooting pip install
The console/terminal will display the download and installation process. Errors in the process indicate the installation failed.
In this instance, the package being installed requires different versions of already installed packages, and requires using the --upgrade option to force replacement of existing packages.
pip install --upgrade [package_name]
Should resolve those warnings. Then, the incompatible packages can be addressed.
pip install --upgrade numpy==[version#]
The version was 1.22.4 in this case. Next, upgrade pandas:
pip install --upgrade --no-deps pandas==[version#]
Because numpy is a dependency of pandas, the install would overwrite the numpy install. In this case, we want to install the 1.5.3 version of Pandas without changing numpy. The --no-deps performs the install without any dependencies.
Keep in mind that using options during pip install may cause issues leading to incompatibility or errors. It's also possible code may run even when there are errors present with the install.
Some other useful options include:
--no-build-isolation : overrides install targets like --home or --prefix in favor of our configuration defaults
--ignore-installed : overrides installed packages
See the pip install documentation here for more info.
View the list of installed packages at any time by typing 'pip list' in the console/terminal to confirm currently installed packages.
JARs / packages / libraries in Java
Language options that use Java will compile any JARs, packages, or libraries included in /usercode, including in the autograder. Another good practice is to create a library folder in /usercode called “libs” and place libraries there.
When using particularly large JARs or libraries, placing them in /userdata/zylabfiles is the best option. You can navigate to /userdata from the desktop view.
After clicking Run in our IDE, you'll see the option to open the desktop. In this VSC option, Open Desktop appears in the top:
The view here is small, and there are several options to enlarge the desktop view, like the fullscreen button in the top right.
After opening the file manager, you can see several folders:
You’ll need to create a new folder at /userdata/zylabfiles, then add JARs there.
/userdata/zyscripts contains the java-update.jars.sh script that symlinks the JAR files included with the image. Any JARs added to the newly created zylabfiles should be symlinked in this file.
Alternatively, you can use commands in the terminal.
- Create or upload your JAR files in /usercode.
- Create the folder using `mkdir /userdata/zylabfiles`
- Move the JAR files to the new directory `mv /usercode/example.jar /userdata/zylabfiles/`
- Move to the /userdata/zyscripts folder `cd /userdata/zyscripts`
- Open the file in the vi editor using `vi java-update-jars.sh` and press i to enter insert mode
- Move down to the symlink section and add your symlinks there:
Test Bench
Any packages or files needed in the test bench require "include workspace data" checked off in the test case. This includes anything added with pip install, and anything else added to /userdata that is required for the test. MySQL languages have this checked by default, as /userdata is where databases are stored.