how to fix ghostscript - python

I have already installed ghostscript with pip install ghostscript.
But I got the error with treepoemerror: Cannot determine path to ghostscript, is it installed?
I've changed gs to gswin64, because I've winx64:
def _get_ghostscript_binary() -> str:
binary = "gswin64"
if sys.platform.startswith("win"):
binary = EpsImagePlugin.gs_windows_binary
if not binary:
raise TreepoemError(
"Cannot determine path to ghostscript, is it installed?"
)
return binary
but I still get that error. How do I set something with Path?
Can anyone give me the steps, easily explained?
So here's it installed:

Related

ImportError: /home/dminstalluser/script/lib/prctl.so: cannot open shared object file: No such file or directory

I am trying to run a python script, and seems when it try to import a library called prctl.so, some error happens:
def update_cmd_title():
"""Remove the secure informations in the command title"""
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + "/script/lb")
import prctl
prctl.setprocname(" ".join(sys.argv))
but I can find this file prctl.so in directory /home/dminstalluser/script/lib/,
-rwxr-xr-x 1 dminstalluser dm_group 10344 Aug 1 03:55 prctl.so
I search from google, and can find somebody had the same problem, but after i followed their solutions, they all failed, like:
export LD_LIBRARY_PATH=/home/dminstalluser/script/lib
or run:
ldconfig
I don't know what's the problem for this error for my case,
On a 64-bit system, the error is most likely caused by a mismatch between the Python you are running, and prctl.so that you've installed.
For example, trying to load 64-bit prctl.so into a 32-bit Python, or vice versa, will produce the error you've observed.
Run file $(which python) /home/dminstalluser/script/lib/prctl.so. If one of them says ELF 64-bit ..., and the other ELF 32-bit ..., then that's exactly your problem.
The fix is to install prctl.so matching your python.

Meson cannot find pykeepass module, I am certain it is installed

I am attempting to build an application using meson, Gnome PasswordSafe. I have successfully built it on Arch, but have since moved to PureOS (Debian).
When running:
$ meson . _build --prefix=/usr
it tells me:
meson.build:36:4: ERROR: Problem encountered: Missing dependency pykeepass >= master
What am I missing?
Thanks!
I installed pykeepass using pip. When that did not work, I tried using pip3. When that did not work, I tried both again, but with sudo. Still no dice.
I then installed it from the repo/source (https://github.com/pschmitt/pykeepass). No dice.
Currently, python help recognizes pykeepass as being installed to:
/home/dc3p/.local/lib/python3.7/site-packages/pykeepass/__init__.py
/usr/local/lib/python3.7/dist-packages/pykeepass/__init__.py
/home/dc3p/.local/lib/python2.7/site-packages/pykeepass/__init__.py
/usr/local/lib/python2.7/dist-packages/pykeepass/__init__.py
pip and pip3 list shows pykeepass as being present.
While I have it installed in all four locations currently, I have also tried while having only one installed at any location at a time.
I have also tried the meson command without and with sudo. Regardless of what I do, meson throws the same error.
Expected result is a build.
The meson.build file in PasswordSafe is testing for the presence of a directory in the file system which can lead to false negatives if the installation directory varies. See the code extract below.
# Python Module Check
pykeepass_dir = join_paths(python_dir, 'pykeepass')
construct_dir = join_paths(python_dir, 'construct')
if run_command('[', '-d', pykeepass_dir, ']').returncode() != 0
error('Missing dependency pykeepass >= master')
endif
if run_command('[', '-d', construct_dir, ']').returncode() != 0
error('Missing dependency python-construct >= 2.9.45')
endif
You can replace the above with the following to test for dependencies based on imports:
python3_required_modules = ['pykeepass', 'construct']
foreach p : python3_required_modules
script = 'import importlib.util; import sys; exit(1) if importlib.util.find_spec(\''+ p +'\') is None else exit(0)'
if run_command(python_bin, '-c', script).returncode() != 0
error('Required Python3 module \'' + p + '\' not found')
endif
endforeach
This should solve the issue providing that pykeepass is within your path.

Pip install upgrade unable to remove temp files

In the course of maintaining a CLI utility, I want to add an update action that will grab the latest version of that package from PyPI and upgrade the existing installation.
$ cli -V
1.0.23
$ cli update
// many lines of pip spam
$ cli -V
1.0.24 // or etc
This is working perfectly on all machines that have Python installed system-wide (in C:\Python36 or similar), but machines that have Python installed as a user (in C:\users\username\AppData\Local\Programs\Python\Python36) receive this error as the old version is uninstalled:
Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'C:\\Users\\username\\AppData\\Local\\Temp\\pip-uninstall-f5a7rk2y\\cli.exe'
Consider using the `--user` option or check the permissions.
I had assumed that this is due to the fact that the cli.exe called out in the error text is currently running when pip tries to remove it, however the path here is not to %LOCALAPPDATA%\Programs\Python\Python36\Scripts where that exe lives, but instead to %TEMP%. How is it allowed to move the file there, but not remove it once it's there?
including --user in the install args as recommended by the error message does not (contrary to the indication of an earlier edit of this question) resolve the issue, but moving the cli executable elsewhere does.
I'm hoping for an answer that:
Explains the underlying issue of failing to delete the executable from the TEMP directory, and...
Provides a solution to the issue, either to bypass the permissions error, or to query to see if this package is installed as a user so the code can add --user to the args.
While the question is fairly general, a MCVE is below:
def update(piphost):
args = ['pip', 'install',
'--index-url', piphost,
'-U', 'cli']
subprocess.check_call(args)
update('https://mypypiserver:8001')
As originally surmised, the issue here was trying to delete a running executable. Windows isn't a fan of that sort of nonsense, and throws PermissionErrors when you try. Curiously though, you can definitely rename a running executable, and in fact several questions from different tags use this fact to allow an apparent change to a running executable.
This also explains why the executable appeared to be running from %LOCALAPPDATA%\Programs\Python\Python36\Scripts but failing to delete from %TEMP%. It has been renamed (moved) to the %TEMP% folder during execution (which is legal) and then pip attempts to remove that directory, also removing that file (which is illegal).
The implementation goes like so:
Rename the current executable (Path(sys.argv[0]).with_suffix('.exe'))
pip install to update the package
Add logic to your entrypoint that deletes the renamed executable if it exists.
import click # I'm using click for my CLI, but YMMV
from pathlib import Path
from sys import argv
def entrypoint():
# setup.py's console_scripts points cli.exe to here
tmp_exe_path = Path(argv[0]).with_suffix('.tmp')
try:
tmp_exe_path.unlink()
except FileNotFoundError:
pass
return cli_root
#click.group()
def cli_root():
pass
def update(pip_host):
exe_path = Path(argv[0])
tmp_exe_path = exe_path.with_suffix('.tmp')
handle_renames = False
if exe_path.with_suffix('.exe').exists():
# we're running on Windows, so we have to deal with this tomfoolery.
handle_renames = True
exe_path.rename(tmp_exe_path)
args = ['pip', 'install',
'--index-url', piphost,
'-U', 'cli']
try:
subprocess.check_call(args)
except Exception: # in real code you should probably break these out to handle stuff
if handle_renames:
tmp_exe_path.rename(exe_path) # undo the rename if we haven't updated
#cli_root.command('update')
#click.option("--host", default='https://mypypiserver:8001')
def cli_update(host):
update(host)
Great solution provided by the previous commenter: Pip install upgrade unable to remove temp files by https://stackoverflow.com/users/3058609/adam-smith
I want to add to remarks that made the code work for me (using python 3.8):
Missing parentheses for the return of the entrypoint function (however, the function I'm pointing to is not decorated with #click.group() so not sure if that's the reason)
def entrypoint():
# setup.py's console_scripts points cli.exe to here
tmp_exe_path = Path(argv[0]).with_suffix('.tmp')
try:
tmp_exe_path.unlink()
except FileNotFoundError:
pass
>>> return cli_root() <<<
Missing with_suffix('.exe') when attempting the rename in the update function. If I use the original code I get FileNotFoundError: [WinError 2] The system cannot find the file specified: '..\..\..\updater' -> '..\..\..\updater.tmp'
def update(pip_host):
exe_path = Path(argv[0])
tmp_exe_path = exe_path.with_suffix('.tmp')
handle_renames = False
if exe_path.with_suffix('.exe').exists():
# we're running on Windows, so we have to deal with this tomfoolery.
handle_renames = True
>>> exe_path.with_suffix('.exe').rename(tmp_exe_path) <<<
...

Using Image (Pillow)/Pytesseract (Python): FineNotFound: [WinError 2] The system cannot find the file specified

On a little project I had an issue with on of the two modules, so I created a short code to see where the problem comes from.
Here is my code:
import pytesseract
from PIL import Image
text= pytesseract.image_to_string(Image.open('pict.jpg'))
With this, I get the same error:
FileNotFoundError: [WinError 2]The system cannot find the file specified
and PyScripter open the subprocess.py file and show me the following line:
# Start the process
try:
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
# no special security
None, None,
int(not close_fds),
creationflags,
env,
cwd,
startupinfo)
When I googled this issue, it looked like my version of pytesseract was causing this. I tried to install different versions of pytesseract or Pillow, but the error still occurs.
What should I do ? How can I be sure that my installation is proper ?
Thanks.
EDIT1:
I tried adding this to make sure the module directory is in the system path:
sys.path.insert(0,'C:\Python34\Lib\site-packages\pytesseract')
It looks like pytesseract can't find your installation of Tesseract. Ensure that the folder containing tesseract.exe is in your system path so that the module can actually run the binary.
If you don't want to modify your environment variables, you can manually specify the full path:
import pytesseract
pytesseract.tesseract_cmd = r'C:\Path\To\tesseract.exe'
# ^ the `r` is needed to have the backslashes
# be interpreted as literal backslashes
# The rest of your code

Python GEOS ImportError

I'm getting this error:
ImportError: Could not find the GEOS library (tried ""geos_c"", ""libgeos_c-1"").
Try setting GEOS_LIBRARY_PATH in your settings
when I run:
from django.contrib.gis.geos import *
pnt=GEOSGeometry('POINT(23 5)')
print(pnt)
I added GEOS_LIBRARY_PATH = 'C:/Python34/Lib/site-packages/osgeo/geos_c.dll'
in C:\Python34\Lib\site-packages\django\conf\project_template\project_name\settings.py
But still Im getting the same error. How to solve this?
I don't know what is the most correct way to use with Windows, you can try to find solution here, but for ubuntu command:
sudo apt-get install binutils libproj-dev gdal-bin
solved the problem.
P.S. From dock:
The setting must be the full path to the C shared library; in other words you want to use libgeos_c.so, not libgeos.so.
Extension of the library must be *_c.so
Are You sure path is correct? This is My path:
GEOS_LIBRARY_PATH = 'c:\\Program Files\\PostgreSQL\\9.1\\bin\\libgeos_c-1'
You need GEOS from PostgreSQL.

Categories