I am using windows os. Want to detect the text from an image with fontAttributes by tesserocr. But when I am running the python code, I am getting this error -
RuntimeError: Failed to init API, possibly an invalid tessdata path: C:\Program Files (x86)\Tesseract-OCR\tessdata/
i) I have installed -
tesseract-ocr-w32-setup-v5.0.0-alpha.20190623.exe
//(though my system is 64 bit)
ii) Added to path variable (both system and user path) -
C:\Program Files (x86)\Tesseract-OCR
C:\Program Files (x86)\Tesseract-OCR\tessdata
iii) Created new system path variable - TESSDATA_PREFIX and linked path of
tessdata folder, like -
TESSDATA_PREFIX - C:\Program Files (x86)\Tesseract-OCR\tessdata
import pytesseract
import locale
locale.setlocale(locale.LC_ALL, 'C')
from tesserocr import PyTessBaseAPI, RIL, iterate_level,OEM
with PyTessBaseAPI(oem=OEM.TESSERACT_ONLY,lang='bask') as api:
api.SetImageFile('sugar.png')
api.Recognize()
ri = api.GetIterator()
level = RIL.WORD
for r in iterate_level(ri, level):
attrs = r.WordFontAttributes()
symbol = r.GetUTF8Text(level)
print(symbol,attrs)
with PyTessBaseAPI(oem=OEM.TESSERACT_ONLY,lang='bask') as api:
File "tesserocr.pyx", line 1168, in tesserocr._tesserocr.PyTessBaseAPI.__cinit
__
File "tesserocr.pyx", line 1181, in tesserocr._tesserocr.PyTessBaseAPI._init_a
pi
RuntimeError: Failed to init API, possibly an invalid tessdata path: C:\Program
Files (x86)\Tesseract-OCR\tessdata/
Probably you don't have the .traineddata files in your system. you have to copy it from
C:\Program Files\Tesseract-OCR\tessdata
and paste all the data files to your directory , I'd suggest create a virtual environment ans then use it
Related
I need to change the output/working directory of the hydra config framework in such a way that it lies outside of my project directory. According to my understanding and the doc, config.yaml would need to look like this:
exp_nr: 0.0.0.0
condition: something
hydra:
run:
dir: /absolute/path/to/folder/${exp_nr}/${condition}/
In my code, I then tried to access and set the path like this:
import os
import hydra
from omegaconf import DictConfig
#hydra.main(config_path="../../config", config_name="config", version_base="1.3")
def main(cfg: DictConfig):
print(cfg)
cwd = os.getcwd()
print(f"The current working directory is {cwd}")
owd = hydra.utils.get_original_cwd()
print(f"The Hydra original working directory is {owd}")
work_dir = cfg.hydra.run.dir
print(f"The work directory should be {work_dir}")
But I get the following output and error:
{'exp_nr': '0.0.0.0', 'condition': 'something'}
The current working directory is /project/path/subdir/subsubdir
The Hydra original working directory is /project/path/subdir/subsubdir
Error executing job with overrides: ['exp_nr=1.0.0.0', 'condition=somethingelse']
Traceback (most recent call last):
File "/project/path/subdir/subsubdir/model.py", line 13, in main
work_dir = cfg.hydra.run.dir
omegaconf.errors.ConfigAttributeError: Key 'hydra' is not in struct
full_key: hydra
object_type=dict
I see that hydra.run.dir doesn't appear in the cfg dict printed first but how can I access the path through the config if os.getcwd() isn't set already? Or what did I do wrong?
The path is correct as I already saved files to the folder before integrating hydra and if the process isn't killed due to the error the folder also gets created but hydra doesn't save any files to it, not even the log file with the parameters it should save by default. I also tried to set the path relative to the standard output path or having an extra config parameter work_dir: ${hydra.run.dir} (returns an Interpolation error).
You can access the Hydra config via the HydraConfig singleton documented here.
from hydra.core.hydra_config import HydraConfig
#hydra.main()
def my_app(cfg: DictConfig) -> None:
print(HydraConfig.get().job.name)
I need to move files from my PC to a network location, however if I execute the script I get an error. If have tested this to execute on my PC to a different local folder and it works perfectly.
Here is my code which I got, and modified slightly, from https://thispointer.com/python-how-to-move-files-and-directories/ (giving credit to the author):
import shutil, os, glob, time
def moveAllFilesinDir(srcDir, dstDir):
# Check if both the are directories
if os.path.isdir(srcDir) and os.path.isdir(dstDir) :
# Iterate over all the files in source directory
for filePath in glob.glob(srcDir + '\*'):
# Move each file to destination Directory
if(os.path.getctime(filePath) != os.path.getmtime(filePath)):
shutil.move(filePath, dstDir);
else:
print("srcDir & dstDir should be Directories")
sourceDir = r"C:\Folder A"
destDir = r"\\Server\Folder B"
moveAllFilesinDir(sourceDir,destDir)
Any help will be highly appreciated.
Update
I forgot to mention that I am making use of Remote Desktop to access the server.
Errors I receive:
FileNotFoundError: [WinError 67] The network name cannot be found.
FileNotFoundError: [Errno 2] No such file or directory
the important part of the error message:
I am getting the following error
starting uWSGI 2.0.18
setting pythonHome to /var/www/demo/venv
python version :3.5.3
Fatal Python error :unable to get the locale encoding
import error : no module named 'encodings'
It shows python version :3.5.3
however inside my venv/lib folder , there is only one package python 2.7
does this have something to do with my error?
please help me out with this.
this is my demo_uwsgi.ini file
#application's base folder
base = /var/www/demo
#python module to import
app = flaskfile //flaskfile is my flask file
module = %(app)
home = %(base)/venv
pythonpath = %(base)
#socket file's location
socket = /var/www/demo/%n.sock
#permissions for the socket file
chmod-socket = 666
#the variable that holds a flask application inside the module imported at line #6
callable = app
#location of log files
logto = /var/log/uwsgi/%n.log```
Am I missing plugins or something? I added plugins = python32 in my demo_uwsgi.ini file and it shows no such file or directory. Do I need to change or unset python path or something?
figured it out myself. Delete the default Nginx configuration file and add your new configuration file at the /etc/nginx. Then follow the instructions in this link https://vladikk.com/20.13/09/12/serving-flask-with-nginx-on-ubuntu/ step by step. change the ownership from root to user. It works perfectly
I have a main folder called 'test', the inner structure is:
# folders and files in the main folder 'test'
Desktop\test\use_try.py
Desktop\test\cond\__init__.py # empty file.
Desktop\test\cond\tryme.py
Desktop\test\db\
Now in the file tryme.py. I want to generate a file in the folder of 'db'
# content in the file of tryme.py
import os
def main():
cwd = os.getcwd() # the directory of the folder 'Desktop\test\cond'
folder_test = cwd[:-4] # -4 since 'cond' has 4 letters
folder_db = folder_test + 'db/' # the directory of folder 'db'
with open(folder_db + 'db01.txt', 'w') as wfile:
wfile.writelines(['This is a test.'])
if __name__ == '__main__':
main()
If I directly run this file, no problem, the file 'db01.txt' is in the folder of 'db'.
But if I run the file of use_try.py, it will not work.
# content in the file of use_try.py
from cond import tryme
tryme.main()
The error I got refers to the tryme.py file. In the command of 'with open ...'
FileNotFoundError: [Error 2] No such file or directory: 'Desktop\db\db01.txt'
It seems like the code
'os.getcwd()'
only refers to the file that calls the tryme.py file, not the tryme.py file itself.
Do you know how to fix it, so that I can use the file use_try.py to generate the 'db01.txt' in the 'db' folder? I am using Python3
Thanks
Seems like what you need is not the working directory, but the directory of the tryme.py file.
This can be resolved using the __file__ magic:
curdir = os.path.dirname(__file__)
Use absolute filenames from an environment variable, or expect the db/ directory to be a subdirectory of the current working directory.
This behavior is as expected. The current working directory is where you invoke the code from, not where the code is stored.
folder_test = cwd # assume working directory will have the db/ subdir
or
folder_test = os.getEnv('TEST_DIR') # use ${TEST_DIR}/db/
On Linux, luarocks installs rocks to
/usr/local/lib/luarocks/rock
and puts a corresponding lua file into
/usr/local/share/lua/5.3
On Windows(LUA 5.1), the rocks are in:
C:\Program Files (x86)\LuaRocks\systree\lib\luarocks
and the lua files are in:
C:\Program Files (x86)\LuaRocks\systree\share\lua\5.1
but lua cannot find them on the windows install.
I must have a PATH problem
This is some of my PATH:
Path=C:\Program Files (x86)\Lua\5.1\lua\;C:\Program Files (x86)\LuaRocks\2.2;C:\Program Files (x86)\LuaRocks\2.2\lua\luarocks;C:\Program Files (x86)\LuaRocks\systree\bin;C:\Perl64\site\bin;C:\UnxUpdts;C:\Perl64\bin;C:\Program Files (x86)\Lua\5.1;C:\Program Files (x86)\Lua\5.1\clibs
I am trying ZeroBraneStudio as the IDE and my system prefs specify this path
path.lua = 'C:\Program Files (x86)\Lua\5.1'
I ran
luarocks install inspect
and that generated the necessary files. Then I wrote this simple test code:
require "inspect"
assert(inspect(1) == "1")
assert(inspect("Hello") == '"Hello"')
and got this error
Program starting as '"E:\Anonamouse\ZeroBraneStudio\bin\lua.exe" -e "io.stdout:setvbuf('no')" "E:\Anonamouse\ZeroBraneStudio\myprograms\DemoInspectModule.lua"'.
Program 'lua.exe' started in 'E:\Anonamouse\ZeroBraneStudio\myprograms' (pid: 14776).
E:\Anonamouse\ZeroBraneStudio\bin\lua.exe: ...namouse\ZeroBraneStudio\myprograms\DemoInspectModule.lua:2: attempt to call global 'inspect' (a nil value)
stack traceback:
...namouse\ZeroBraneStudio\myprograms\DemoInspectModule.lua:2: in main chunk
[C]: at 0x00402a57
Program completed in 0.04 seconds (pid: 14776).
I get the same error when I execute the same simple app directly in the console.(That tells me that PATH variable for lua is working)
What am I missing?
Judging from the error message you quoted the require "inspect" worked just fine, but the module didn't set a global variable inspect. For some time now it has been policy to not set globals from within modules, but instead return something (usually the module table) from the module code, which in turn gets passed down via require. So probably something like
local inspect = require "inspect"
assert(inspect(1) == "1")
assert(inspect("Hello") == '"Hello"')
or
local inspect = require "inspect"
assert(inspect.inspect(1) == "1")
assert(inspect.inspect("Hello") == '"Hello"')
should work.