JSPyBridge icon indicating copy to clipboard operation
JSPyBridge copied to clipboard

How to install a python package so I can use it in node

Open u9g opened this issue 2 years ago • 3 comments

Couldn't find the info anywhere, maybe I didn't look hard enough. I found how to install node packages in python but not vice-versa.

u9g avatar Dec 16 '21 14:12 u9g

The python packages need to be installed with pip, either globally or in a virtual environment

E.g.

pip install numpy

extremeheat avatar Dec 16 '21 18:12 extremeheat

The python packages need to be installed with pip, either globally or in a virtual environment

E.g.

pip install numpy

Just tried that, doesn't seem to work though:

PS C:\Users\---\Documents\js-projects\do-it-lol> pip install keyboard
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
Requirement already satisfied: keyboard in c:\python39\lib\site-packages (0.13.5)
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
PS C:\Users\---\Documents\js-projects\do-it-lol> node .
node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

[🐍  Python Error  Call to 'python' failed:
>   const kb = await python('keyboard')
  at async main (C:\Users\---\Documents\js-projects\do-it-lol\index.js:4:14)

... across the bridge ...

> return _bootstrap._gcd_import(name[level:], package, level)
  at import_module (C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py:127)
  at _gcd_import (<frozen importlib._bootstrap>:1030)
  at _find_and_load (<frozen importlib._bootstrap>:1007)
  at _find_and_load_unlocked (<frozen importlib._bootstrap>:984)
🌉 ModuleNotFoundError: No module named 'keyboard']

u9g avatar Dec 16 '21 21:12 u9g

Looks like you have two Python installations installed, one in c:\python39 and another in C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0. Pip is installing to the former, but python points to the latter.

You need to update the PATH env var to prioritize the Python install to c:\python39

extremeheat avatar Dec 17 '21 08:12 extremeheat