2

I have installed all the Node.js libraries as required for my nodejs application. But the nodejs application at the backend uses python libraries which has some lines of code such as import nltk and all other libraries. and these import statements when uploaded on a heroku platform is raising an error.

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'

I have uploaded all the files but still it is raising an error.

complete code deployed on heroku is available in github link - https://github.com/rinku16/patranker

nodejs application code files is present in app folder

Issue: How can i use this nltk and other python libraries in my application.

Below are the python libraries required in the python file

# 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

For example, for nltk library below is path of the file i got

>>> import nltk 
>>> nltk.__file__ 'C:\\Users\\Carthaginian\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\nltk\\__init__.py'

how i use this path to clone it in my nodejs application. please see this.

2
  • When i run this project in my localhost, it run smoothly becoz all python libraries required in python code is available in my C drive of the system. Commented Feb 26, 2021 at 7:58
  • can it be done by git cloning of the python libraries available Commented Feb 26, 2021 at 8:04

2 Answers 2

1

You can create a custom_lib folder and clone all the libraries in it. Provide the correct path using import or require in Node.js project. Use gulp runner or any task runner to copy these custom_lib to your build folder and remember follow the same hierarchy in the build folder structure.

You can also write a custom script to copy these python_lib to the build folder. You can add this custom script in package.json in scripts.

We have the same issue in our project and it work like a charm.

Sign up to request clarification or add additional context in comments.

15 Comments

is it i have to clone from my local system or from some online repository of the python
i m actually just started using git, i used git for push, pull, commit and status only
please look at the directory structure of my project link - github.com/rinku16/patranker
Apoorva, i m not able to get with you answer, please can you help me in this
can you give example for import nltk
|
1

You can use JSPyBridge https://github.com/extremeheat/JSPyBridge (in readme there are plenty of examples)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.