I am working with Anaconda-spyder, my scripts are working fine in spyder also I can run it from CMD
but I can not run my scripts with my Nodejs app
Nodejs
const express = require('express');
const router = express.Router();
const {PythonShell} = require("python-shell");
router.get('/hi', (req, res, next)=> {
console.log("here");
PythonShell.run('pyt//home.py', {
args: ['infoo']
}, function (err, results) {
console.log("here2");
if(results)
{ console.log(results);}
if(err)
{ console.log(err);}
});
});
module.exports = router;
In python code, used libraries
import os
import sys
import tweepy,codecs
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import nltk
from textblob import Word
import six
import numpy as np
import pandas as pd
from os import path
from PIL import Image
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
from nltk.corpus import stopwords
from matplotlib.backends.backend_pdf import PdfPages
import time
And getting the argv parameter in home.py with
if __name__ == "__main__":
twt = sys.argv[1]
print("hi python")
When I run server, get the route with postman. console says
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node ./bin/www`
here
here2
{ Error: ModuleNotFoundError: No module named 'pandas'
at PythonShell.parseError (C:\Users\username\Desktop\NodejsBitirme\node_modules\python-shell\index.js:258:21)
at terminateIfNeeded (C:\Users\username\Desktop\NodejsBitirme\node_modules\python-shell\index.js:141:32)
at ChildProcess.<anonymous> (C:\Users\username\Desktop\NodejsBitirme\node_modules\python-shell\index.js:133:13)
at ChildProcess.emit (events.js:198:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
----- Python Traceback -----
File "pyt\home.py", line 9, in <module>
Seems like installed libs problem. It work from cmd.
In the same folder
python home.py "hello"
It works
Related
I am trying to load FlaUI libraries using pythonnet. The code is able to load the FlaUI.UIA3.dll. However, importing FlaUI.UIA3 namespace fails.
Here is my code,
import clr
import sys
dll_path = 'C:\\Users\\amit_tendulkar\\.nuget\\packages\\flaui.core\\3.2.0\\lib\\net45'
dll_path2 = 'C:\\Users\\amit_tendulkar\\.nuget\\packages\\flaui.uia3\\3.2.0\\lib\\net45'
sys.path.append(dll_path)
clr.AddReference('FlaUI.Core')
sys.path.append(dll_path2)
clr.AddReference('FlaUI.UIA3')
from FlaUI.Core import Application
from FlaUI.Core.Conditions import ConditionFactory
from FlaUI.Core.Tools import Retry
from FlaUI.UIA3 import UIA3Automation
from FlaUI.UIA3 import UIA3PropertyLibrary
The error I am getting is below (using command python sample.py),
Traceback (most recent call last):
File ".\ToadApp.py", line 12, in <module>
from FlaUI.UIA3 import UIA3Automation
ModuleNotFoundError: No module named 'FlaUI.UIA3'; 'FlaUI' is not a package
If I don't include the FlaUI.UIA3 library then I am able to Launch the application with Application.Launch('software.exe').
Here is the content of my directory containing FlaUI3.UIA3.dll,
C:\Users\amit_tendulkar>dir C:\Users\amit_tendulkar\.nuget\packages\flaui.uia3\3.2.0\lib\net45
Volume in drive C has no label.
Volume Serial Number is 8692-D75E
Directory of C:\Users\amit_tendulkar\.nuget\packages\flaui.uia3\3.2.0\lib\net45
25-01-2022 22:28 <DIR> .
25-01-2022 22:28 <DIR> ..
17-07-2020 02:05 105,472 FlaUI.UIA3.dll
17-07-2020 02:05 28,095 FlaUI.UIA3.xml
2 File(s) 133,567 bytes
Dotnet version (using Windows 10),
C:\Users\amit_tendulkar>dotnet --version
6.0.101
Looks like FlaUI.UIA3.dll has dependency on Interop.UIAutomationClient.dll.
Updating the code to the below solved my issue.
import clr
import sys
flaui_core_path = 'C:\\Users\\amit_tendulkar\\.nuget\\packages\\flaui.core\\3.2.0\\lib\\net45'
flaui_uia3_path = 'C:\\Users\\amit_tendulkar\\.nuget\\packages\\flaui.uia3\\3.2.0\\lib\\net45'
interop_uiautomation_path = 'C:\\Users\\amit_tendulkar\\.nuget\\packages\\interop.uiautomationclient\\10.18362.0\\lib\\net45'
sys.path.append(flaui_core_path)
clr.AddReference('FlaUI.Core')
sys.path.append(interop_uiautomation_path)
clr.AddReference('Interop.UIAutomationClient')
sys.path.append(flaui_uia3_path)
clr.AddReference('FlaUI.UIA3')
from FlaUI.Core import Application
from FlaUI.Core.Conditions import ConditionFactory
from FlaUI.Core.Tools import Retry
from FlaUI.UIA3 import UIA3Automation
from FlaUI.UIA3 import UIA3PropertyLibrary
I am trying to run a .py script on my Manjaro box and I keep getting the following error:
[keithm#home2 python]$ python3 gspppff.py
['/home/keithm/bin/python', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/keithm/.local/lib/python3.8/site-packages', '/usr/lib/python3.8/site-packages']
Traceback (most recent call last):
File "gspppff.py", line 7, in <module>
import matplotlib.pylot as plt
ModuleNotFoundError: No module named 'matplotlib.pylot'
Here's the script:
#!/usr/bin/python
import datetime as dt
import sys
print(sys.path)
import matplotlib.pylot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
# graph style
style.use('ggplot')
start = dt.datetime(2020, 1, 1)
end = dt.datetime.now()
# dataframe
df = web.DataReader("TSLA", 'morningstar', start, end)
print(df.head())
I included print(sys.path) to see where python was looking for the mods and I made sure matlablib was installed in both locally: /home/keithm/.local/lib/python3.8/site-packages and in /usr/lib/python3.8/site-packages, but still no change.
The package name is "pyplot", not "pylot". Here is the corrected code:
import matplotlib.pyplot as plt
It's spelled "pyplot", not "pylot".
import matplotlib.pyplot as plt
try "pyplot" you have incorrect spelling
i am trying to convert my python code to dll, in the code below under ffi.embedding_init_code i can import packages which i have installed with pip or conda like cv2, numpy, pil etc but i have created python file my_tools.py this is giving error while accessing the dll. "ModuleNotfoundError: no module named 'my_tools' "
import re
import cffi
ffi = cffi.FFI()
with open('plugin.h') as f:
include = f.read()
ffi.embedding_api(include)
ffi.set_source("my_plugin",
re.sub(r'^extern(?=\s)', 'CFFI_DLLEXPORT', include, flags=re.M))
ffi.embedding_init_code("""
from my_plugin import ffi, lib
import keras_ocr
import my_tools # as m_tools
import logging
import sys
import cv2
import numpy as np
from PIL import Image
import io
import base64
#ffi.def_extern()
def hello(out_result):
out_result=ffi.string(out_result)
print("hello python="+str(out_result))
return 0
""")
ffi.cdef("""
char *strdup(const char *);
""")
ffi.compile(target="plugin-1.5.*", verbose=True)
below is my plugin.h
extern int hello(char* out_result);
how can import my own created file here.
There is no one-size-fits-all answer, but a quick way to get started is to add this as the first line in
embedding_init_code:
import sys; sys.path.insert(0, "/path/containing/the/python/files")
input code:
import os
import logging
import logging.handlers
import random
import numpy as np
import skvideo.io
import cv2
import matplotlib.pyplot as plt
import utils
Some codes here ... ... ... then:
if __name__ == "__main__":
log = utils.init_logging()
if not os.path.exists(IMAGE_DIR):
log.debug("Creating image directory `%s`...", IMAGE_DIR)
os.makedirs(IMAGE_DIR)
main()
Output:
AttributeError: module 'utils' has no attribute 'init_logging'
I have tried to rename the file into utils.py. Nothing
I assume you're making a tutorial of Making Road Traffic Counting App based on Computer Vision and OpenCV. You just need to download from github the file named "utils.py" that the author made.
Following is my project structure:
root directory
| - __init__.py
| - notdoneyet.py
| - helpers.py
| - opencv_generators.py
| - seam_carve.py
| - imgtovideos.py
notdoneyet.py file contains the entry point of project and the remaining scripts are imported as modules and when required.
My __init__.py contains following code:
from .notdoneyet import user_input
from .helpers import createFolder
from .helpers import getFileExtension
from .helpers import writeImage
from .opencv_generators import generateEnergyMap
from .opencv_generators import generateColorMap
from .imagetovideos import generateVideo
from .imagetovideos import getToProcessPaths
from .seam_carve import cropByColumn
from .seam_carve import cropByRow
I have published the package on testPyPI. But when I try to import it after installing on local machine, I get the import error.
Initial code for notdoneyet.py:
import os, sys, cv2, argparse
#Local imports
import imgtovideos as itv
import helpers as hp #Error on this line
import opencv_generators as og
import seam_carve as sc
def main(argsip):
#usr inpt
I am getting the error "no module named helpers"
Here is screenshot of the error:
Please help me.
Thank you.