Ghostscript Can not find Ghostscript library (libgs) - python

I'm on a macbookpro 10.6.8 and I get this error message when trying to use ghostscript:
Traceback (most recent call last):
File "/Users/arnoutaertgeerts/Documents/Eclips/SlideTalk 2.0/slidetalk.py", line 13, in <module>
import ghostscript
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ghostscript-0.4.1-py2.7.egg/ghostscript/__init__.py", line 33, in <module>
import _gsprint as gs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ghostscript-0.4.1-py2.7.egg/ghostscript/_gsprint.py", line 290, in <module>
raise RuntimeError('Can not find Ghostscript library (libgs)')
RuntimeError: Can not find Ghostscript library (libgs)
Installed the package with:
pip install ghostscript

For newer user who are using M1 mac, ghostscript might show a missing libgs file error and the file would be unavailable at usr/local/lib
The issue can be resolved by following these steps, in the same order:
brew install ghostscript
conda install ghostscript, which installs the arm_64 based library from conda-forge
If conda throws a channel error try using conda install -c conda-forge ghostscript
pip install ghostscript
Note:
The libgs.dylib file can be found in the home brew installation of ghostscript
Changing the address in _gsprint.py will throw an error as the brew installed version will be arm_64 based and the pip installed version will be OS_X86 based
Python doesn't recognise ghostscript module from conda install unless pip install is run, so that is an essential step

How are you trying to 'use' Ghostscript ? This seems to be an error from Python which can't find libgs (I do not speak Python I'm afraid)
I'm not certain that libgs is is included in the Mac installation but if it is, then libgs should be in the Ghostscript folder. Have you checked to see if it is present ?
If it is, then the most likely problem is that its not in the search path, I have no idea how searches are resolved on a Mac though.

The ctypes.find_library searches in /urs/local/lib.
I added this path to my ghostscript module:
/opt/local/lib/libgs

I changed the path for libgs in the file "_gsprint.py" and it works~
Instead of libgs.so (libgs = cdll.LoadLibrary("libgs.so"), I used
libgs = cdll.LoadLibrary("Corresponding_Path_in_my_laptop/libgs.dylib").
Ps: There's no libgs.so on my Mac, only one libgs.dylib file.
Thanks #KenS and #arnoutaertgeerts!

Related

Mac Poppler + pdf2image PATH bug

Problem:
I've been attempting to use the Python library pdf2image, which I am aware requires the prior installation of poppler. Poppler is installed (via homebrew) and the package via pip.
However, when running convert_to_path(my_pdf) I get the following:
Traceback (most recent call last):
File "<ipython-input-9-ba107659b495>", line 1, in <module>
test_image = convert_from_path(testfile,
File "/Users/<myuser>/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pdf2image/pdf2image.py", line 97, in convert_from_path
page_count = pdfinfo_from_path(pdf_path, userpw, poppler_path=poppler_path)["Pages"]
File "/Users/<myuser>/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pdf2image/pdf2image.py", line 467, in pdfinfo_from_path
raise PDFInfoNotInstalledError(
PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
My System:
Mac, OC 10.15.7
Python (via Homebrew) version 3.8.0
which python
/Users/<myuser>/.pyenv/shims/python
which pip
/Users/<myuser>/.pyenv/shims/pip
What I've tried so far:
Poppler is installed via homebrew (brew install poppler) and pdf2image installed with pip3 install pdf2image
I've run brew cleanup too.
Attempted to force the poppler path in convert_to_path with the following,
pop_path = "/usr/local/Cellar/poppler/21.03.0_1"
convert_to_path(my_pdf_file,poppler_path = pop_path)
but still get the same error.
Had a decent look online and found many people with similar, yet not identical, problems. I feel like I must be doing something wrong, so any guidance would be great.
Partial Solution?
In manually entering the pop_path file path, I forgot to append /bin to the path,
pop_path = "/usr/local/Cellar/poppler/21.03.0_1/bin"
The code works now. Though my pride will take some time to recover...
I feel like I might still be sitting on a bad configuration issue? The many posts on similar issues seem to imply a homebrew installed-popper shouldn't have this issue. Is it maybe because I am using pyenv too?
if you use conda environment run the below code in mac terminal
conda install -c conda-forge pdf2image
conda install -c conda-forge poppler
It solve the problem

FileNotFoundError Installing PyQt5

I'm been trying to install PyQt and I can't get past the below error. I've read a few posts suggesting that I should upgrade PIP, setup_tools, and ez_install. I've tried all of that with no luck. Any tips?
c:\Python27>pip install PyQt5_gpl-5.10.tar.gz
Processing c:\python27\pyqt5_gpl-5.10.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\program files (x86)\python36-32\lib\tokenize.py", line 452, in open
buffer = _builtin_open(filename, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\JAME~1.KRK\\AppData\\Local\\Temp\\pip-0u8uht47-build\\setup.py'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\JAME~1.KRK\AppData\Local\Temp\pip-0u8uht47-build\
Same thing in 3.6:
c:\Program Files (x86)\Python36-32>pip install PyQt5_gpl-5.10.tar.gz
Processing c:\program files (x86)\python36-32\pyqt5_gpl-5.10.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\program files (x86)\python36-32\lib\tokenize.py", line 452, in open
buffer = _builtin_open(filename, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\JAME~1.KRK\\AppData\\Local\\Temp\\pip-f9s0_6sp-build\\setup.py'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in
C:\Users\JAM~1.KRK\AppData\Local\Temp\pip-f9s0_6sp-build\
I just encountered the same issue and find clue in the topic. It has been solved by pip upgrade.
Here is the detail:
1. Issue case:
pip3 install pyqt5.
failed and report FileNotFoundError: [Errno 2] No such file or directory:
2. OS environment:
Win10 64x WSL2
3. Python environment
python 3.7.3
pip version 19.X (not write down)
Solved steps:
pip3 install --upgrade pip
pip3 install --user PyQt5
sudo apt-get update -y
sudo apt install libgl1-mesa-glx -y
now. It works.
Root cause:
a. pyqt
in wsl, pip old version download wrong package.
pip (v20.x) download below version
PyQt5-5.15.2-5.15.2-cp35.cp36.cp37.cp38.cp39-abi3-manylinux2014_x86_64.whl
b. libgl1.so1.
not such lib need install by apt intall
Hope my experience can help you.
On PyPI it seems PyQT5 is for python 3.5 or higher only. Not python 2.7. Use an earlier version of PyQt or a newer version of python (Python 2.7 isn't supported beyond 2020, you'll need to move sooner or later).
You appear to be trying to make pip install the PyQt5 source archive. PyQt doesn't use the usual setup.py script that many python packages use and cannot be built and installed from source with pip. Furthermore, the .tar.gz format is intended for linux systems and Windows provides no native support. I am not sure whether pip on Windows would even handle the format. There is a .zip version provided for Windows users.
You need to either extract the archive and build from source, or allow pip to download and install the package itself with pip install PyQt5.
If you are using Python < 3.5, you will have to build from source (or install PyQt4 instead), as there are no official builds provided for these versions of Python. For everything else the pip command above should be enough.
you need to use Python >= 3.5 or try the older PyQt4
on debianoids there is a nice way out of this bug
apt install python3-pyqt5

Installing PIP Python 3.6.3 Ubuntu 16.04 Zlib Not Available, But It's Installed

I'm trying to follow this tutorial on installing Python 3.6.3 and PIP with virtual environments, but when I get to sudo python3.6 get-pip.py I get the error
Traceback (most recent call last):
File "get-pip.py", line 20061, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
zipimport.ZipImportError: can't decompress data; zlib not available
but I have zlib1g-dev installed and don't know how to fix this problem. I've googled a lot and tried reinstalling, but haven't had any success.
Sorry to start a new question, but I did not have enough Karma to comment on the other one. Any help would be greatly appreciated.
Update: I ended up installing everything from source instead of using any packages and it seems to be working. I was not able to solve the problem, but found an alternative way to get things working.
For pip to work, Python needs to be linked to the zlib library when Python itself is installed. It appears that either zlib was not installed when you installed Python, or at least that the Python installer couldn't locate it. To help it along, you may issue the following before installing Python. In bash syntax,
zlib_lib="/usr/lib32"
zlib_inc="/usr/include"
export CPPFLAGS="-I${zlib_inc} ${CPPFLAGS}"
export LD_LIBRARY_PATH="${zlib_lib}:${LD_LIBRARY_PATH}"
export LDFLAGS="-L${zlib_lib} -Wl,-rpath=${zlib_lib} ${LDFLAGS}"
Here I've assumed that zlib is installed under /usr/lib32 and /usr/include/. To check this, look for the libz.so.1 file in the "lib" directory and the zlib.h file in the "inc" directory. If you find them somewhere else, simply change zlib_lib and zlib_inc accordingly.
IF you have different versions of Python installed it is likely the install is on another version. for example. I have pyperclip in 3.6.3 32bit version, but I an not access it in 3.6.3 64bit or 3.7.2dev.

Unable to import python modules (numpy, scipy, matplotlib)

I've used the following tutorial to install Python, numpy, scipy and matplotlib:
https://penandpants.com/2012/03/01/install-python-2/
I downloaded each and installed by double-clicking. I'm using a Mac with OS X Yosemite Version 10.10.5
When I try to import numpy, scipy and matplotlib in IDLE I get the follow error message:
`>>> import numpy
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import numpy
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper`
Can anyone please explain to me how to resolve this?
Thanks
use terminal and type
sudo pip install numpy
sudo pip install matplotlib
sudo pip install scipy
for python3+ use pip3
I can't say for sure what's wrong with your installation, but I suspect it's due to a some PATH-conusion... Python 2.7 and Numpy should be installed on your Mac by default.
If you run the command which python, you'll see which executable the python-commands invokes... is it the same as the one you installed?
If you write python in the terminal, and press tab twice, do you see multiple options of installed python versions?
Alternative method of installation
I prefer the Anaconda Python Distribution, which you can download like the full version or minimal version, which is the one I prefer.
If you install this, you should consider uninstalling the one you just installed.
Here's how to install the mini version:
Download the installer, and run it by opening a terminal in the folder with the installer, and running the command bash Miniconda2-latest-MacOSX-x86_64.sh. This will start the text-based installer, and if you read the instructions on screen, you'll be fine.
Notice that you have to scroll to the end of the licence agreement, before you can write yes when asked to accept the terms stated.
Say yes when it asked you if you'd like it to add Anaconda Python to your path.
Anaconda Python is different from other python distributions in the regard that it comes with it's own package and environment manager conda. With conda you can have multiple versions of Python installed at the same time (or several environments of the same Python version, but with different packages or versions of packages).
To create a new environment with the name py27, which is using Python 2.7, write conda create -n py27 python=2.7 --yes. Once created, activate the environment by source activate py27.
With the new environment now active, install the packages you need by using conda: conda install scipy matplotlib --yes.
I'd also recommend installing Ipython, which is an improved shell, and possibly the Jupyter notebook: conda install ipython --yes and conda install notebook --yes.
Hope it helps.

Not able to install the python-module numpy

After hours of trying I'm still not able to install numpy. I READ LOTS OF HINTS, ANSWERS USW. BUT IT DOESN'T HELP.
Furthermore I have windows 7, 32 bit, Python 27.
What I did:
download numpy-1.10.2.zip:
http://sourceforge.net/projects/numpy/files/
unzip it
start the windows command prompt and input:
cd C:\Users\myname\Desktop\numpy-1.10.2
now it appears:
C:\Users\myname\Desktop\numpy-1.10.2>
I input:
python setup.py install
and there appears an error:
Running from numpy source directory.
Traceback (most recent call last):
File "setup.py", line 263, in <module>
setup_package()
File "setup.py", line 246, in setup_pa
import setuptools
ImportError: No module named setuptools
I hope somebody can help me or even better IS THERE NOT EASIER WAY TO INSTALL NUMPY OR OTHER MODULES??
Building numpy from source on windows is non-trivial. Best use official binaries (http://sourceforge.net/projects/numpy/files/NumPy/1.10.2/) or Gohlke binaries (http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy) or a distribution like Anaconda or Canopy or WinPython.
You need to install the setuptools package as well. See here.
A more easy way to install python packages is using pip, which resolves package dependencies automatically. See here. Pip should be included in your python installation if you use a recent version.
You should succeed by calling pip install numpy.

Categories

Resources