Python virtual environments on Schokr
Do you need a venv for a Python app on Schokr? How package installs work on the Python template and when to create a virtual environment yourself.
Updated · 2 min read
You usually do not need to create a virtual environment for a Python app on Schokr. Each server runs in its own isolated container, so packages you install for one app cannot clash with another server's packages. Install from requirements.txt and let the template handle it.
Why venvs exist
On your own computer, a virtual environment keeps each project's packages separate from the system Python and from other projects. On Schokr, that isolation already exists at the server level: every server has its own container and its own files.
Never upload your local venv
A venv or .venv folder from your computer will not work on the server. It contains absolute paths to your machine's Python and, often, binaries built for a different operating system. Exclude it when you upload:
venv/
.venv/
__pycache__/
What to upload instead
- Activate your local venv and freeze your packages:
pip freeze > requirements.txt
- Upload your code and
requirements.txtwith the file manager. - Start the server. The Python template typically installs packages from
requirements.txton startup; watch the console for pip output. If your template does not, see installing dependencies.
Where packages end up
Depending on the template, pip may install packages into a folder inside your server's files (for example a user-level or prefix directory) rather than into the system Python. That is expected. Do not delete unfamiliar folders like .local in the file manager, or your packages will need to reinstall.
When a venv can still help
If you want full control and your startup command can be edited, you can create a venv inside the server:
python -m venv .venv && .venv/bin/pip install -r requirements.txt && .venv/bin/python app.py
This runs on every start, which is slower. Most apps do not need it.
Check the Python version
Packages pin minimum Python versions. Print the version the server uses at startup:
import sys
print(sys.version)
If a package needs a newer Python than the server offers, choose a version of the package that supports it, or check whether your server's Startup settings let you pick a different runtime image.
Common errors
| Error | Cause |
|---|---|
ModuleNotFoundError: No module named 'x' | Package missing from requirements.txt, or install failed. See module not found errors. |
externally-managed-environment | pip refuses to install into a system Python. Use the template's install step or a venv as above. |
No matching distribution found | Package version not available for this Python version. |