How to implement Python import libraries on Xampp localhost? - python

I'm trying to implement running machine learning on my web.
I set my Xampp addhandler .py so that can handle python files.
Basically, I checked everything python works on my web.
But the problem is that cannot import any libraries such as cv2, easyocr, and imutils.
#!C:\Users\parkc\AppData\Local\Programs\Python\Python310\python.exe
print("Content-type: text/html\n")
import cv2
import numpy as np
import imutils
import easyocr
from matplotlib import pyplot as plt
print("Hello World")
And this is my result page,
result page
Nothing shows.
So, what I doubt is that it can't load libraries from localhost.
Because if I set the code like,
#!C:\Users\parkc\AppData\Local\Programs\Python\Python310\python.exe
print("Content-type: text/html\n")
print("Hello World")
import cv2
import numpy as np
import imutils
import easyocr
from matplotlib import pyplot as plt
Then, it prints Hello World very well!
I'm googling for 2 days to solve this problem. But totally cannot get what's the problem.
Is it not possible to use package libraries on web?
My web server is Apache Xampp.

Maybe you would like to read this, it will help you a lot I think:
the article
“How to Easily Run Python Visualizations On a Web Browser with PyScript”

Related

Python MacOS Error: Unable to revert mtime: /Library/Fonts

I am trying to run a python script on my mac but
"Unable to revert mtime: /Library/Fonts"
keeps popping up when i run the program. i have the latest version of python installed as well as matplotlib. i am very new to python so i do not know what the issue is but here is the snippet of the code:
from plotly import graph_objs as go
import matplotlib.pyplot as plt
import numpy as np
import json
import datetime
with open('ELIX.json') as json_file:
data = json.load(json_file)
you need to have libmagic
brew install libmagic
In my situation, I had to restore the fonts that came with my system. To do so:
Open up the Font Book app
Go to File
Click Restore Standard Fonts
Video: https://www.loom.com/share/379ad4f9539d4730af75039623027888

A problem regarding image handling on python

from skimage import io
photo=io.imread('myimage.jpg')
print(type(photo))
photo.shape
print(photo.shape)
import matplotlib.pyplot as plt
plt.imshow(photo)
This is my code on my editor. I don't use anacona distribution or jupyter notebook. print(type(photo)) and print(photo.shape) lines works but plt.imshow(photo) doesn't.How to fix it? Though ,I have installed those necessary modules and packeges.
My second question , is there another python distribution which is so efficient like anaconda.

ImportError: no module named miniconda

I've installed miniconda on my mac following the instructions from the python website. However, when I write any new script and try and import miniconda, matplotlib or Pandas, I get the error above.
My script so far
from miniconda import *
from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns
CORRECTED
my code is now
from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns
I'm now getting the same import error for pandas and seaborn.
UPDATED:
Turns out the corrected code above works and the issue was with Python runner. The code runs when executed through the terminal. Probably an issue with permissions!
Miniconda is not a module indeed it is a variant of Anaconda python distribution, hence you could not import it. You could get further info about miniconda from the link below.
https://conda.io/miniconda.html

No module called spectrogram

Hi I am having a little trouble with the module spectrogram which I need to use in order to create spectrograms from my wav files.
I repeatedly get the error message No module named spectrogram when importing on my Windows which is running Python version 2.7.12. In contrast when importing the module on my mac which runs version 2.7.11 I have no problems. I can't find anything that suggests that this is a version specific problem and was hoping someone might be able to help me fix this.
Here is the code I am using to import the needed modules. This runs absolutely fine on my mac, but won't run on Windows.
import glob
import numpy as np
import scipy.io import wavfile
import spectrogram as sp
import os
import matplotlib.pyplot as plt
Spectrogram is a part of scipy, you must make that known.
from scipy import signal
signal.spectrogram(bla,bla,bla)

cv2 Module not Found Even though I downloaded it

I am currently in PyCharm and I have the following line of code:
import cv2
Nonetheless, it gives me the error No module named cv2
I went to Preferences > Project Interpreter > + then found and downloaded cv2 just fine. In the Project Interpreter it lists cv2 as installed. I am not sure why it still shows that the module doesn't exist. Is there some way to download cv2 via command line. I am on OS X 10.10.
Here is the code I have so far (all the other imports work just fine):
# Program for OCR
import numpy as np
import cv2
from matplotlib import pyplot as plt
I find that sometimes after installing a module in PyCharm it requires a restart in order for it to work. Also, if you do want to do it in the command line, try pip3 install cv2.

Categories

Resources