'Heroku: NodeJS: pip is missing if I use NodeJS app

I have a NodeJS app, in which I want to invoke Python interpreter, to run some processing for me.

When I check for "python --version" from NodeJS using exec(...), I get the output as Python 3.8.5. That's good. I need to install certain packages using pip.

But when I try to invoke pip, it saying command error. So basically pip is not available on that dyno.

My question is if I use a NodeJS app, how can I install pip? So that I can download certain Python packages.



Solution 1:[1]

I was struggling with the same problem. You can't install pip, but instead what you need to do is install a python buildpack. This buildpack will set your dyno to properly work with python/pip.

Using Heroku CLI:

  1. First install python buildpack at the first position: heroku buildpacks:add --index 1 heroku/python. You should receive the message below: enter image description here NOTE: The buildpack for the primary language of your app should always be the last buildpack in the list. This ensures that defaults for that primary language are applied instead of those for another language, and allows Heroku to correctly detect the primary language of your app.

  2. Second create a commit so you can run git push heroku main.

That's it. Now you have pip in your dyno, and if you have a file requirements.txt with all the python packages it will be automatically downloaded every time you push to heroku main.

Documentation: Using Multiple Buildpacks for an App

Let me know if it worked.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zaibil