python - 如何在 nodejs 应用程序中使用 python 库
问题描述
我已经安装了我的 nodejs 应用程序所需的所有 Node.js 库。但是后端的 nodejs 应用程序使用 python 库,其中包含一些代码行,例如import nltk
所有其他库。并且这些导入语句在heroku
平台上上传时会引发错误。
Traceback (most recent call last): File "mainfile.py", line 2, in import functionfile as f File "/app/functionfile.py", line 1, in import nltk ModuleNotFoundError: No module named 'nltk'
我已经上传了所有文件,但仍然出现错误。
在 github 链接中提供了部署在 heroku 上的完整代码 - https://github.com/rinku16/patranker
nodejs 应用程序代码文件存在于 app 文件夹中
问题:如何在我的应用程序中使用这个 nltk 和其他 python 库。
下面是python文件中需要的python库
# Import function file as reference to use defined python functions
import functionfile as f
import sys
import nltk
from nltk.corpus import stopwords
#for generating sentence token
from nltk.tokenize import sent_tokenize
#for generating word token
from nltk.tokenize import word_tokenize
# BeautifulSoup for scraping and Requests to make HTTP requests.
from bs4 import BeautifulSoup
# BeautifulSoup is in bs4 package
import requests
#Counter class For Getting Most Occurred Biwords
from collections import Counter
#FOR MAKING DATA FRAME AND WRITING THE PATENT EXTRACTED DATA TO CSV FILE
from pandas import DataFrame
import pandas as pd
import os
import os.path
from os import path
import re
from datetime import datetime, timedelta
from datetime import date
import math
例如,对于nltk
下面的库是我得到的文件的路径
>>> import nltk
>>> nltk.__file__ 'C:\\Users\\Carthaginian\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\nltk\\__init__.py'
我如何使用此路径在我的 nodejs 应用程序中克隆它。请看这个。
解决方案
推荐阅读
- angular - *ngFor 循环中的多个输入文件的问题
- java - jar 顶层内的多个入口点(主类)
- javascript - Firebase 实时数据库规则防止节点删除
- sql-server - 如何为在 Docker for MSSQL Server 中运行的 Kafka 设置 Debezium
- mysql - 单个 SQL 连接可以运行并发事务吗?
- php - 使用 XMLreader 和 PHP 进行搜索和获取
- php - 使用 JSON 原始数据 Laravel 搜索 SQL
- java - 未能配置数据源:“url”属性 - 尽管已指定
- windows - 在 Windows 终端的 $USERPROFILE 中启动 Cygwin(预览版)
- c# - 实例化类时自动获取属性和默认值?