Chromia
Start Building

06 / 15Module 1: Project setupAdvanced

Finalize your Python environment

This lesson walks you through setting up your Python environment with the bundled installation script. The script creates a virtual environment, picks the right PyTorch build for your hardware (GPU or CPU), and installs every dependency the project needs.

From the rell/ folder, go up one level and enter the Python folder:

bash
cd ../python

From the project root, use this instead:

bash
cd python

Stay in the python/ folder for the remaining steps.

Run the install script

The script takes care of the full setup:

  • Sets up a vector_demo_env virtual environment, unless one already exists
  • Checks your platform and whether a GPU is available
  • Installs PyTorch with the matching backend: CUDA, MPS, or CPU-only
  • Installs the project dependencies from requirements.txt

Note: your system might not include venv by default. On Ubuntu/Debian, add it with sudo apt install python3-venv.

Start the installer:

bash
python3 install.py

When the script completes, activate the virtual environment:

bash
source vector_demo_env/bin/activate

Update your .env file

Edit python/.env and fill in the values from your deployment:

env
# A list of Postchain node URLs (must be valid JSON)NODE_URL_POOL='["https://node0.testnet.chromia.com:7740", "https://node1.testnet.chromia.com:7740", "https://node2.testnet.chromia.com:7740", "https://node3.testnet.chromia.com:7740"]'# The blockchain RID of your deployed chainBLOCKCHAIN_RID=<your-blockchain-rid># Your private key (for signing transactions)PRIV_KEY=<your-private-key># 💰 Box office threshold for vectorization (movies below this are skipped)BOX_OFFICE_THRESHOLD=100_000_000# 🧠 Embedding model selectionEMBEDDING_MODEL=sentence-transformers/all-mpnet-base-v2
  • Set PRIV_KEY to the private key you created earlier with chr keygen
  • Set EMBEDDING_MODEL to the same model you chose in the embedding model lesson (Lesson 1)
  • BOX_OFFICE_THRESHOLD determines how many movies get embedded and stored on-chain:
    • A higher value keeps only the highest-grossing movies.
      Fewer vectors mean faster embedding (converting text to vectors).
    • A lower value keeps more titles.
      More vectors mean slower embedding, particularly on CPU.

On a CPU-only machine, pick a higher threshold such as 500_000_000 to keep things fast.
With a GPU, you can go lower, or use 0 to embed the entire dataset, which can take roughly 15–20 minutes.
The default of 100_000_000 gives quick results on a GPU without dropping too many titles.

What’s next?

Your Python environment is installed and .env is configured, so you can move on to working with the data.

Written for this site from Chromia’s public course. Code samples are the course’s own.