Trying to get arithmentic formatter to run on replit

Hi, I’m trying to work through python exercises. I’ve written an arithmetic formatter, which seems to work fine on VS Code and now I’m trying to run it on replit, but all I get in my replit console is the following error:

 python3 main.py
Traceback (most recent call last):
  File "/home/runner/boilerplate-arithmetic-formatter-1/main.py", line 2, in <module>
    from pytest import main
ModuleNotFoundError: No module named 'pytest'
exit status 1

So it seems that it can’t find a moudle called “pytest”. These are the contents of my main.py:

# This entrypoint file to be used in development. Start by reading README.md
from pytest import main

from arithmetic_arranger import arithmetic_arranger
import re #I've added this line because my solution uses regex

print(arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]))


# Run unit tests automatically
main(['-vv'])

I know that some other people had similar problems and had to modify their replit.nix file but so far nothing worked for me. These are the contents of my replit.nix file:

{ pkgs }: {
  deps = [
    pkgs.python310Full
    pkgs.replitPackages.prybar-python310
    pkgs.replitPackages.stderred
  ];
  env = {
    PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
      # Needed for pandas / numpy
      pkgs.stdenv.cc.cc.lib
      pkgs.zlib
      # Needed for pygame
      pkgs.glib
      # Needed for matplotlib
      pkgs.xorg.libX11
    ];
    PYTHONHOME = "${pkgs.python310Full}";
    PYTHONBIN = "${pkgs.python310Full}/bin/python3.10";
    LANG = "en_US.UTF-8";
    STDERREDBIN = "${pkgs.replitPackages.stderred}/bin/stderred";
    PRYBAR_PYTHON_BIN = "${pkgs.replitPackages.prybar-python310}/bin/prybar-python310";
  };
}

And lastly here is my arithmetic_formatter, it uses regex so I’ve imported “re” module in my main.py, but I don’t think that’s the problem because even if I remove it and replace the arithmetic_formatter contents with a “Hello world!” program it throws the same error.

def arithmetic_arranger(problems, display=False):
    
    operators=[]
    operands=[]
    results=[]
    maxLength=[]
    arranged_problems=''

    for item in problems:
        # Checking if input formatting is correct
        if len(problems)>5:
            print('Error: Too many problems.')
            return 'Error: Too many problems.'
        if bool(re.search(' *[\+-] *',item.strip()))==False:
            print('Error: Operator must be \'+\' or \'-\'.')
            return 'Error: Operator must be \'+\' or \'-\'.'
        if bool(re.search('^[0-9]+ *[\+-]',item.strip()))==False or bool(re.search('[\+-] *[0-9]+$',item.strip()))==False:
            print('Error: Numbers must only contain digits.')
            return 'Error: Numbers must only contain digits.'
        if bool(re.search('^[0-9]{1,4} *[\+-]',item.strip()))==False or bool(re.search('[\+-] *[0-9]{1,4}$',item.strip()))==False:
            print('Error: Numbers cannot be more than four digits.')
            return 'Error: Numbers cannot be more than four digits.'
        if bool(re.search('^[0-9]{1,4} *[+-] *[0-9]{1,4}$',item.strip()))==False:
            print('Error: Wrong input.')
            return 'Error: Wrong input'
        
        #Set up operands, operators, results and their max length
        operands.append(re.split('[\+-]',item))
        if bool(re.search('\+',item)):
            operators.append('add')
        else:
            operators.append('substract')

    for i in range(len(problems)):
        operands[i][0]=int(operands[i][0].strip())
        operands[i][1]=int(operands[i][1].strip())
    
    for i in range(len(problems)):
        if operators[i]=='add':
            results.append((operands[i][0])+(operands[i][1]))
        else:
            results.append((operands[i][0])-(operands[i][1]))

    for i in range(len(problems)):
        maxLength.append(len(str(max(abs(operands[i][0]),abs(operands[i][1]),abs(results[i])))))

    #Constructing returned string
    for i in range(len(problems)):
        arranged_problems=arranged_problems+' '*2+' '*(maxLength[i]-len(str(abs(operands[i][0]))))+str(operands[i][0])+' '*4
    
    arranged_problems=arranged_problems+'\n'
    
    for i in range(len(problems)):
        if operators[i]=='add':
            arranged_problems=arranged_problems+'+'
        else:
            arranged_problems=arranged_problems+'-'
        arranged_problems=arranged_problems+' '+' '*(maxLength[i]-len(str(abs(operands[i][1]))))+str(operands[i][1])+' '*4

    arranged_problems=arranged_problems+'\n'

    for i in range(len(problems)):
        arranged_problems=arranged_problems+'--'+'-'*maxLength[i]+' '*4

    arranged_problems=arranged_problems+'\n'
    
    for i in range(len(problems)):
        if results[i]>=0:
            arranged_problems=arranged_problems+' '*2+' '*(maxLength[i]-len(str(abs(results[i]))))+str(results[i])+' '*4
        else:
           arranged_problems=arranged_problems+' '+' '*(maxLength[i]-len(str(abs(results[i]))))+str(results[i])+' '*4 
    
    
    #print(operators)
    #print(operands)
    #print(results)
    #print(maxLength)
    if display==True:
        print (arranged_problems)

    return arranged_problems

#arithmetic_arranger(["32 + 8", "1 - 3801", "9999 + 9999", "523 - 49"], True)

What do you suggest I should do to make my function run on replit?

at the Shell command prompt: pip install pytest

Reinstalling pytest module worked like a charm, thank you.

You might run into this with other packages, same fix could work:

pip install pandas
pip install matplotlib

etc.