PythonMagick Unable to open config file - windows-10

I am running Python 3.6 in a venv on 64 bit Windows 10 inside PyCharm. Here are the steps I performed:
Open PyCharm and start a new project using Python 3.6 as the venv.
Downloaded the PythonMagick from a wheel file for Python3.6 from this source:PythonMagick wheel file
Open the terminal in PyCharm and run:
pip install PythonMagick-0.9.19-cp36-cp36m-win_amd64.whl
Download ghostscript from here: Ghostscript 9.25 for Windows (64 bit) and run the exe file.
Add the ghostscript directory C:\Program Files\gs\gs9.25\bin to the user PATH environment variable.
Now I run the sample file from here
import PythonMagick
if __name__ == "__main__":
pdf = 'a.pdf'
p = PythonMagick.Image()
p.read(pdf)
p.write('doc.jpg')
I get the following error:
RuntimeError: Magick: UnableToOpenConfigureFile `delegates.xml' #
warning/configure.c/GetConfigureOptions/714
How do I fix this error?

When installing PythonMagick in a VENV, apparently you need to also add a system variable called MAGICK_HOME so that Magick can find the config files.
Add the following to the User Variable
MAGICK_HOME = %your-project-dir%\venv\Lib\site-packages\PythonMagick
Then restart PyCharm.

Related

How to execute latest version python which just been installed?

I just installed the latest python(3.7.6).
Then I open python file as I usually do, my Mac open the file with version 3.7.3, not 3.7.6(as shown in the image)
How to open a python file with latest version of Python installed on PC?
enter image description here
just execute the below code if your .path to py file is test.py.
python3 test.py
if you only have one python in you machine, then you can execute the below command.
python test.py

Unable to import sqlite3 using Anaconda Python

I am trying to do the following in Python 3.7.1 on Windows
import sqlite3
but I get the following error message
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "c:\programdata\anaconda3\lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "c:\programdata\anaconda3\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
I have searched for a solution to the problem for quite a while now to no avail. I have also successfully run pip install pysqlite3 on the Anaconda prompt, but the import still fails. What do?
I got this working on windows by downloading: the sqlite3 dll (find your system version)
And placing it into the folder: C:\Users\YOURUSER\Anaconda3\DLLs
(Depending on how you installed Anaconda, this may have to be placed into
the following folder: C:\ProgramData\Anaconda3\DLLs)
According to #alireza-taghdisian, you can locate the exact path of
your conda environments (where you need to copy the sqlite3 dll) by typing:
conda info --envs on your anaconda prompt.
Locate the sqlite3.dll file. In my case it was in following folder
C:\Users\Admin\anaconda3\Library\bin
where C:\Users\Admin\anaconda3 is the folder where Anaconda was installed
Add this to PATH in environment variables, and it should work then.
Try copying the sqlite3.dll from the
C:\Users\YOURUSER\anaconda3\Library\bin
folder to
C:\Users\YOURUSER\Anaconda3\DLLs
Please check https://github.com/jupyter/notebook/issues/4332
I added anaconda root/Library/bin to my PATH and now it works!
Add CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1 to your environment variables.
before executing the program, enter conda activate in your shell.
I had tried all above solutions But for me and my system I got to know that
I downloaded Python in C:\Python27 hence there is dll folder in python C:\Python27\DLLs
I installed Sqlite3.dll in my above dll folder
May be this solution will help you because it completely depends on where do you install your python
Happy coding :)
I put the sqlite3.dll in the path folder of my Python venv and still wont work. I suspected it is a path problem.
(In my case: E:\Virtual_Env\mini_zinc\env\Scripts)
I found in my case I messed up installation in a virtual evn, somehow using an anaconda python kernel within a Python venv.
I reinstall the Python Venv and check the python version after installed Env is correct (not the Anaconda python), then proceed with Jupyter Notebook (or Juyterlab) and works fine.
I was able to resolve this issue by putting sqlite3.dll file in the C:\Users<USERID>\AppData\Local\conda\conda\envs<ENV NAME>\DLLs.
Download sqlite3.dll file from https://www.sqlite.org/download.html
or copy it from C:\ProgramData\Anaconda3\DLLs\
I found the #elgsantos useful. But for those who are new to Python and Conda like me, I would like to add a little bit of details.
1- I use miniconda3 for creating new environment.
2- interestingly, I got two installation path on my computer for conda: the first one (the obvious) is located on "C:\Users\taghdisian\miniconda3". The second one is on "C:\Users\taghdisian\AppData\Local\r-miniconda". The latter is the primary path that you need to copy your sqlite3 files into the envs folder. I copy them in the "C:\Users\taghdisian\AppData\Local\r-miniconda\envs\sdr3.9\DLLs" in which the sdr3.9 is one of my virtual Condo environment.
you can locate the exact path of your conda environments (where you need to copy sqlite3) by typing the conda info --envs on your anaconda prompt.
I hope this help.
got the same error while loading the jupyter notebook from other conda prompt than "base" environment.
[1]: https://i.stack.imgur.com/2DW7E.png
Resolved by installing sqlite package
(nlpenv) C:\Users\arunk>conda install sqlite
launching
*
(nlpenv) C:\Users\arunk>jupyter notebook

Unable to import Libraries even though Installed in Anaconda on Pycharm

I am using Ubuntu 18.10(dual Boot win10), I have installed anaconda (conda version- 4.6.7) on ubuntu. After this Installation I installed Pycharm via snap on Command Prompt. Since Pycharm(version - 2018.3.5) didnt Detect my python Location automatically I set the python Interpreter via
Adding Location ->System Interpreter (As I didn't want any Venv) -> Path
But when I try to import opencv in Pycharm it says
ModuleNotFoundError: No module named 'cv2'
Python3.6 in Anaconda Bin is shown to which I have linked in Pycharm (I have also tried other Python files there as well but no luck)
When I run in Terminal: python3 -c 'import sys; print(sys.path)'
It shows:
['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6
/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/local
/lib/python3.6/dist-packages/setuptools-39.1.0-py3.6.egg', '/usr/lib`/python3
/dist-packages']
So could anyone help me out in this?? Thank You in Advance!!
Edit 1:
I am also unable to access any of the libraries from terminal Itself. So Could anyone help me with that as well. Should I export path of this Python in Anaconda bin folder to bashrc file in Ubuntu?
Edit 2:
The libraries affected is not just opencv. There are few other Libraries like Portaudio which are affected as well along with Opencv

Poppler in path for pdf2image

I'm trying to use pdf2image and it seems I need something called propeller :
(sum_env) C:\Users\antoi\Documents\Programming\projects\summarizer>python ocr.py -i fr13_idf.pdf
Traceback (most recent call last):
File "c:\Users\antoi\Documents\Programming\projects\summarizer\sum_env\lib\site-packages\pdf2image\pdf2image.py", line 165, in __page_count
proc = Popen(["pdfinfo", pdf_path], stdout=PIPE, stderr=PIPE)
File "C:\Python37\lib\subprocess.py", line 769, in __init__
restore_signals, start_new_session)
File "C:\Python37\lib\subprocess.py", line 1172, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "ocr.py", line 53, in <module>
pdfspliterimager(image_path)
File "ocr.py", line 32, in pdfspliterimager
pages = convert_from_path("document-page%s.pdf" % i, 500)
File "c:\Users\antoi\Documents\Programming\projects\summarizer\sum_env\lib\site-packages\pdf2image\pdf2image.py", line 30, in convert_from_path
page_count = __page_count(pdf_path, userpw)
File "c:\Users\antoi\Documents\Programming\projects\summarizer\sum_env\lib\site-packages\pdf2image\pdf2image.py", line 169, in __page_count
raise Exception('Unable to get page count. Is poppler installed and in PATH?')
Exception: Unable to get page count. Is poppler installed and in PATH?
I tried this link but it the thing to download didn't solved my problem.
pdf2image is only a wrapper around poppler (not propeller!), to use the module you need to have poppler-utils installed on your machine and in your path.
The procedure is linked in the project's README in the "How to install" section.
1st of all Download Poppler from here here,Then extract it.In the code section just add poppler_path=r'C:\Program Files\poppler-0.68.0\bin'(for eg.) like below
from pdf2image import convert_from_path
images = convert_from_path("mypdf.pdf", 500,poppler_path=r'C:\Program Files\poppler-0.68.0\bin')
for i, image in enumerate(images):
fname = 'image'+str(i)+'.png'
image.save(fname, "PNG")
Now its done.With this trick no need to add Environmental Variables.Let me know if you have any problem.
These pdf2image and pdftotext library backend requierment is Poppler,
so you have to install
'conda install -c conda-forge poppler '
then the error will be resolved.
and if still it won't work for you then you can follow
http://blog.alivate.com.au/poppler-windows/ to install this library.
It is poppler which is not installed properly.
Using this you can get correct package for installation.
sudo apt-get install poppler-utils
For windows; to solve PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH? :
Install chocolatey https://chocolatey.org/install
then install poppler using choco:
choco install poppler
Poppler in path for pdf2image
While working with pdf2image there are dependency that needs to be satisfied:
Installation of pdf2image
pip install pdf2image
Installation of python-dateutil
pip install python-dateutil
Installation of Poppler
Specifying Poppler path in environment variable (system path)
Installing Poppler on Windows
Go to https://github.com/oschwartz10612/poppler-windows/releases/
Under Release 21.11.0-0 Latest v21.11.0-0
Go to Assets 3
Download Release-21.11.0-0.zip
Adding Poppler to path
Add Poppler installed to loaction :C:\Users\UserName\Downloads\Release-21.11.0-0.zip
Add C:\Users\UserName\Downloads\Release-21.11.0-0.zip to system
variable path in Environment Variable
Specifying poppler path in code
pages = convert_from_path(filepath, poppler_path=r"actualpoppler_path")
If anyone still has this error on Windows, I solved the problem by:
Download the Latest binary of Poppler for Windows from Poppler for Windows
Unzip it into C drive like C:\poppler-0.68.0
Specify the Poppler path like this:
from PIL import Image
import pytesseract
import sys
from pdf2image import convert_from_path
import os
ROOT_DIR = os.path.abspath(os.curdir)
# Path of the pdf
PDF_file = ROOT_DIR + r"\PdfToImage\src\2.pdf"
'''
Part #1 : Converting PDF to images
'''
# Store all the pages of the PDF in a variable
pages = convert_from_path(PDF_file, 500, poppler_path=r'C:\poppler-0.68.0\bin')
FOR MAC, if you have brew installed, that is the way to go.
brew install poppler
Takes several minutes to install all the dependencies, but pdf2image will work afterwards.
This is a repeat of an answer here and the answer is also in a comment on this page. Adding this answer b/c it took me a while to find the correct solution FOR MACs.
In Windows
Install the Poppler for Windows Poppler
500 = Quality of JPG
the path contains the pdf files
pip install pdf2img
path = r'C:\ABC\FEF\KLH\pdf_extractor\output\break'
def spliting_pdf2img( path):
from pdf2image import convert_from_path, convert_from_bytes
for file in os.listdir(path):
if file.lower().endswith(".pdf"):
pages = convert_from_path(os.path.join(path,file), 500,poppler_path= r'C:\ABC\DEF\Downloads\poppler-0.68.0\bin')
for page in pages:
page.save(os.path.join(path,file.lower().replace(".pdf",".jpg")),'JPEG')
In Linux/UBUNTU
Install the below packages in the ubuntu/linux terminal
sudo apt-get update
sudo apt-get install poppler-utils
path = r'C:\ABC\FEF\KLH\pdf_extractor\output\break'
def spliting_pdf2img( path):
from pdf2image import convert_from_path, convert_from_bytes
for file in os.listdir(path):
if file.lower().endswith(".pdf"):
pages = convert_from_path(os.path.join(path,file), 500)
for page in pages:
page.save(os.path.join(path,file.lower().replace(".pdf",".jpg")),'JPEG')
I'm working on a mac in Visual Studio Code and I encountered this error. I followed the install instructions and was able to verify the packages were installed but the error persisted when running in VSC.
Even though I had my python.condaPath and python.pythonPath specified in my settings.json it wasn't until activated the conda environment inside of the VSC integrated terminal itself
conda activate my_env
that the error went away..
Bizarre.
After downloading poppler do this....
import os
os.environ["PATH"] = r"C:.....\poppler-xxxxxxx\bin"
use this to make environment hope it works.It worked for me.
I had the same problem on my Mac
I solved it by replacing the poppler_path from - poppler_path= '\usr\bin'
" to poppler_path= '\usr\local\bin'
but you can try to print all the places that poppler might be in your mac
by echo $PATH in the Terminal and try all the options as poppler_path=" "
I had the same issue on Mac using Visual Studio Code and a conda environment.
I found out that I could run the code from the command line, however not from VS code. I then printed the environment variables when running from the command line and in VS code using:
print(os.environ)
When I compared the two, I noticed that the "PATH" variable was different. My conda environment was not in the "PATH" variable in VS code. I think this means that VS code was not correctly activating my conda environment. I therefore took my "PATH" from the command line and set it in my launch.json environment variables. Then the problem was fixed.
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"python": "/Users/<username>/miniconda3/envs/<env_name>/bin/python",
"env": {
"PATH":"<PATH STRING from command line>"
},
"program": "${file}"
}
I kind of followed the steps from one of the previous posted answers except I had to add the path in env variables. Adding path in pdf2image.convert_from_path didn't worked for me. So, if anyone still has this error on Windows, I solved the problem by:
Download the Latest binary of Poppler for Windows from Poppler
Windows
Unzip it into C drive like C:\poppler-0.68.0
Specify the Poppler path in environment variables
Poppler path in env variables
I had same issue but I have fixed it in my django project by changing directory.
Actually first you need to store this pdf image file in side your media directory.
Then you need to change your current directory to this media directory(where this pdf image file has been stored).
This is my code snippet in django project where I have converted .pdf image to .jpg
import PIL
from PIL import Image
def convert_pdf_2_image(uploaded_image_path, uploaded_image,img_size):
project_dir = os.getcwd()
os.chdir(uploaded_image_path)
file_name = str(uploaded_image).replace('.pdf','')
output_file = file_name+'.jpg'
pages = convert_from_path(uploaded_image, 200)
for page in pages:
page.save(output_file, 'JPEG')
break
os.chdir(project_dir)
img = Image.open(output_file)
img = img.resize(img_size, PIL.Image.ANTIALIAS)
img.save(output_file)
return output_file

How to change .py to .exe

I made a program in python which is in .py format. However, I would like it to be in .exe
The options I have found are:
py2exe
pyinstaller
The problems with those 2 are because I am running python 3.6 and those 2 programs do not support it, HELP!
Python 3.6 still isn't supported by Pyinstaller. So in order to use it you're gonna need Python 3.5 or below. So, you might wanna change your python version to 3.4 or 2.7. Then you can follow the procedure for creating the exe with pyinstaller. Also I think pyinstaller is a better option than py2exe.
However to make things work without switching to other versions, you might wanna try using cx_freeze:
1.Install the latest version of cx_freeze by pip install cx_Freeze.
2.Create a new python file named ‘setup.py’ on the current directory of your script.
3.On the setup.py, code this and save it:(here my prog.py refers to your .py file name)
from cx_Freeze import setup, Executable
base = None
executables = [Executable("my prog.py", base=base)]
packages = ["idna"]
options = {
'build_exe': {
'packages':packages,
},
}
setup(
name = "<any name>",
options = options,
version = "<any number>",
description = '<any description>',
executables = executables
)
4.With shift pressed right click on the same directory to open a command prompt window.
5.Type: python setup.py build.
6.Check the newly created folder ‘build‘. Within that folder you can able to find your application.
pyinstaller
pip install pyinstaller
Basic usage is very simple, just run it against your main script:
pyinstaller /path/to/yourscript.py
cx_Freeze
pip install cx-Freeze
auto-py-to-exe
pip install auto-py-to-exe
Then to run it, execute the following in the terminal:
auto-py-to-exe
With a simple google search, I found this question which gives a link to a version of py2exe which happens to support python 3.3 and up. Here is the link!
On that page you will find the following bit of information:
Py2exe is a distutils extension which allows to build standalone Windows executable programs (32-bit and 64-bit) from Python scripts; Python 3.3 and later are supported. It can build console executables, windows (GUI) executables, windows services, and DLL/EXE COM servers.
Notice:
Python 3.3 and later are supported.
I have created a batch file to do the work, but first, go to https://datatofish.com/add-python-to-windows-path/ and add python to your path.
Then create a new notepad file with this:
SET /P _input1= Enter the file directory:
cd %_input1%
SET /P _input2= Enter the file name:
pyinstaller --onefile %_input2%
ECHO The exe file is in the dict folder in %_input1%
pause
Save this as a .bat file anywhere and run it.
Enter the directory of the python script.
then the name.
Hope this helps!

Resources