Installing Python Packages
Script and Server files run full Python 3.10 environments where you can install third-party Python packages.
To install a package, click the ‘Packages’ tab in the code editor to open the side panel. Here, you can enter a package name (as it appears in PyPI) and a version number. Leaving the version number blank will install the latest version of the package. Once you’ve added the package name (and optional version number), click “Add”, and the new Python environment will start building.
Editing the requirements.txt
directly
You can also add Python packages to your widget’s environment by editing its requirements.txt
directly. py.space uses pip for package management, so you can install packages from PyPI, a GitHub repository or a URL using pip’s Requirements File Format. Click “Edit requirements.txt directly” to switch to a text editor view where you can type in your package list directly, just as you would a requirements.txt
file. This way, you can specify more nuance in your version dependencies, such as using the <=
operator.
Build output
Once you add a Python package to your environment, py.space will start installing your packages and creating a new server environment. You’ll be able to see the output from this process if you click the caret next to ‘Building…’ (or ‘Built’ if the environment is built already!)
Possible errors
Sometimes, an error can occur during the build process, and py.space displays the output from pip’s install process directly. The two most common causes of build failures happen when a requested package could not be found or when there is a conflict in dependency versions.
Package does not exist
ERROR: Could not find a version that satisfies the requirement `bad-package` (from versions: none)
ERROR: No matching distribution found for `bad-package`
Error: Build failed
This typically happens due to a typo. Double-check that the package you have requested is spelled correctly and that the requested version (if any) is correct.
Conflicting dependencies
ERROR: Cannot install pymongo==4.1.0 and pymongo==4.1.1 because these package versions have conflicting dependencies.
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
Error: Build failed
This happens when the dependencies you have requested have incompatible requirements. For help resolving this, visit pip’s dependency conflict management page.
Vunerabilities
Once a server environment has been built, py.space will use safety to check the installed dependencies of that environment for vulnerabilities. The output of this can be seen below the Build Output section.
If security vulnerabilities are detected, a button will appear. Click on this button to bring up the vunerability report
Do you still have questions?
Our Community Forum is full of helpful information and friendly experts.