How do I install python packages in a nodejs project?

Hi I’m having a nodejs server where it calls a python through child process. There are a few python packages required. However, since it’s nodejs project, the built-in package manager seems to only able to install nodejs packages. How do I install packages for the python? I tried pip install but it does not have permission.

You can install python-shell through npm. From there, you can use $ pip install WHATEVER_LIBRARY to install the python libraries.

1 Like

You don’t have to install python-shell - just modify your replit.nix

If you used the default Node.JS template, it will look like this:

{ pkgs }: {
  deps = [
    pkgs.nodejs-18_x
    pkgs.nodePackages.typescript-language-server
    pkgs.yarn
    pkgs.replitPackages.jest
  ];
}

Modify it to look like this (from the Python template):

{ pkgs }: {
  deps = [
    # Node.JS Template
    pkgs.nodejs-18_x
    pkgs.nodePackages.typescript-language-server
    pkgs.yarn
    pkgs.replitPackages.jest
    # Python Template
    pkgs.strace
    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
    ];
    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";
  };
}
2 Likes