Error while installing PySWIP for use of Prolog in Python - python

I am trying to follow the installation guide for PySWIP in Windows, which first asks to install a 32 bit version of SWI-Prolog first and include its bin in PATH, which I did. Then I installed the 64 bit version of PySWIP since my Python-2.7 is 64 bit Anaconda version. But it doesn't work (see error below).
As suggested by some elsewhere, I also made of copy of libswipl.dll (in C:\Program Files (x86)\pl\bin ) as libpl.dll and of swipl.ico (in C:\Program Files (x86)\pl ) as pl.ico but no luck.
The error that I am getting (in Spyder and EclipsePyDev IDEs using Anaconda interpreter) when I enter the first line below is:
>>> from pyswip import Prolog
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\XXX\Anaconda\lib\site-packages\pyswip\__init__.py", line 29, in <module>
from pyswip.prolog import Prolog
File "C:\Users\XXX\Anaconda\lib\site-packages\pyswip\prolog.py", line 29, in <module>
from pyswip.core import *
File "C:\Users\XXX\Anaconda\lib\site-packages\pyswip\core.py", line 360, in <module>
_lib = CDLL(_path)
File "C:\Users\XXX\Anaconda\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 is not a valid Win32 application
How to fix this?
Background: I am working through the first order logic programming of natural language semantics of NLTK book, and I thought it would be nice to have a logic program that can do constraint programming (specifically, solve for equality logical constraints)

Found my answer - it was that I should have installed a 64 bit (instead of 32 bit) version of SWI-Prolog for it to work with 64 bit PySWIP and Python (even though the installation guide at PySWIP specifically mentioned 32 bit SWI-Prolog). Its working now.
PS: I didn't find the need to rename libswipl.dll or swipl.ico

Related

ModuleNotFoundError: No module named 'utils.cython_bbox'

I'm a student and a complete newbie, so please forgive me if this is a basic question. I have followed the instructions to run PCL model (https://github.com/ppengtang/pcl.pytorch) on the voc2007 data by following the instructions on the github page.
I'm using Windows 10 64 bit, Python 3.10.5, and as far as I can tell I've installed all dependencies including Visual Studio Code C++ libraries, SDK etc., although I had a lot of trouble trying to install cython_bbox.
When I run in CMD:
python tools/test_net.py --cfg configs/baselines/vgg16_voc2007.yaml \ --load_ckpt Outputs/vgg16_voc2007/$MODEL_PATH \ --dataset voc2007trainval
I get the following:
C:\Users####\py_virtual_env\lib\site-packages\torchvision\models\detection\anchor_utils.py:63: UserWarning: Failed to initialize NumPy: module compiled against API version 0x10 but this version of numpy is 0xf (Triggered internally at ..\torch\csrc\utils\tensor_numpy.cpp:68.)
device: torch.device = torch.device("cpu"),
Traceback (most recent call last):
File "C:\Users####\pcl.pytorch\tools\test_net.py", line 14, in
from core.test_engine import run_inference
File "C:\Users####\pcl.pytorch\lib\core\test_engine.py", line 36, in
from core.test import im_detect_all
File "C:\Users####\pcl.pytorch\lib\core\test.py", line 43, in
import utils.boxes as box_utils
File "C:\Users####\pcl.pytorch\lib\utils\boxes.py", line 54, in
import utils.cython_bbox as cython_bbox
ModuleNotFoundError: No module named 'utils.cython_bbox'
In the lib\utils folder, there are two files: cython_bbox.c and cython_bbox.pyx. This appears to be the root of the issue but I have no idea what exactly the issue is or how to fix it.
For information, I also have:
Requirement already satisfied: cython_bbox in c:\users####\py_virtual_env\lib\site-packages (0.1.3)
I've searched online for a solution but cannot find one.
I'd appreciate any help.

Setting up PyOpenGL with freeglut for Python 3.5.2

I am trying to set up my machine to use PyOpenGL with freeglut. I have Python version 3.5.2 and a 64 bit copy of Windows 8.
I have downloaded PyOpenGL using pip, then downloaded freeglut and placed the include\ and lib\ folders at C:\Program Files\Common Files\MSVC\freeglut. I have also placed a link to the 64 bit freeglut.dll file in the environment variables linking to C:\Work\freeglut.dll
As I do not know any OpenGL yet I am simply trying to run the code from this page to see if my setup is functional http://www.de-brauwer.be/wiki/wikka.php?wakka=PyOpenGLSierpinski. When run I receive the error message
Traceback (most recent call last):
File "sier_tri.py", line 35, in <module>
glutInit()
File "C:\Users\Dylan\AppData\Local\Programs\Python\Python35-32\lib\site-packag
es\OpenGL\GLUT\special.py", line 333, in glutInit
_base_glutInit( ctypes.byref(count), holder )
File "C:\Users\Dylan\AppData\Local\Programs\Python\Python35-32\lib\site-packag
es\OpenGL\platform\baseplatform.py", line 407, in __call__
self.__name__, self.__name__,
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit,
check for bool(glutInit) before calling
Does anyone know what is causing this/how to fix it?
place the glut32.dll next to the py file.
Check this link
I fixed this by switching to the 32 bit freeglut.dll file. I thought that the 32bit vs 64bit was dependent on your operating system but it's actually dependent on which kind of Python you have, as I have 32 bit Python I need the 32 bit dll.

python - pyinstaller "RuntimeWarning: Parent module 'PyInstaller.hooks.hook-PIL' not found while handling absolute import" and "tcl" related errors

I get a warning message while trying to create exectable file using pyinstaller. This warning appeared after installing Pillow. Previously i nevre got any warnings and was able to make it through.
the warning i get by pyinstaller is:
7314 INFO: Analyzing main.py
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/hooks/hook-PIL.Image.py:14: RuntimeWarning: Parent module 'PyInstaller.hooks.hook-PIL' not found while handling absolute import
from PyInstaller.hooks.shared_PIL_Image import *
Also when i tried to run the executable's exe/consol version of my code that lies inside the dist folder created by the pyinstaller (dist/main/main), these are displayed..
Traceback (most recent call last):
File "<string>", line 26, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 276, in load_module
exec(bytecode, module.__dict__)
File "/Users/..../build/main/out00-PYZ.pyz/PIL.PngImagePlugin", line 40, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 276, in load_module
exec(bytecode, module.__dict__)
File "/Users/..../build/main/out00-PYZ.pyz/PIL.Image", line 53, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 276, in load_module
exec(bytecode, module.__dict__)
File "/Users/..../build/main/out00-PYZ.pyz/FixTk", line 74, in <module>
OSError: [Errno 20] Not a directory: '/Users/.../dist/main/tcl'
logout
[Process completed]
so, i tried by uninstalling pillow, installing tk tcl dev version. And then installed pillow. Even that didnt helped.
I also tried reinstalling pyinstaller,. didnt help too
Update 1:
It seems Pyinstaller.hooks.hook-PIL.py file was missing in the Pyinstaller/hooks directory. And it was missing on all platforms(Mac, windows and linux). This is the warning/error message that i get on windows, which is the same i got on mac and on linux.
Later i found a link which said, its just to need Python import machinery happy. so i created as said so. Then i dont get the same error on all platforms, But on mac i still get the PILImagePlugin,Image and FixTk errors
Solution for tcl:
I found what was going wrong,.. Every problem that i faced on OSX was the OS itself(exactly the macport). Python by default comes with the mac OS. And this version of python may be useful for just learning basic python, but is not suitable for Development purpose.
Installing brew's python helped. I followed this SO link. After doing these i was still getting errors. Later i had to change the paths on /etc/paths. Basically rearranging them should work. But still then i wasn't getting it right.
Then i had to change the .bash_profile, which worked for most users, But still i was getting mac's version of python and pip, not the brews version of python.
Finally i had to restart the machine for a couple of times and do the /etc/paths and .bash_profile steps repeatedly to get the system wide effect to accept brews version of python and pip
Solution for PIL:
just adding a file called hook-PIL.py with an empty content would serve the purpose. I found a link which was having the hook files content of pyinstaller.
The location to create
for mac : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/hooks/ Actually for mac this step wouldn’t be required. When we install python through brew and change the path, everything that you try to install later either through pip install or from source packages tend to choose a different path. And everything will be taken care of.
for windows:C:\Python27\lib\site-packages\PyInstaller-2.1.1.dev0-py2.7.egg\PyInstaller\hooks
**Please check if this is a valid path on your machine before creating the file and then create the file. And im not sure or i don't know if just adding an empty file is the right way. But it worked for me

Why can't this python script find the libclang dll?

I would like to get started with using libclang with Python. I am trying to get a sample code (http://www.altdevblogaday.com/2014/03/05/implementing-a-code-generator-with-libclang/) to work on Windows, here is a part of the code I'm trying to run:
#!/usr/bin/python
# vim: set fileencoding=utf-8
import sys
import os
import clang.cindex
import itertools
...
print("Setting clang path")
# I tried multiple variations. Libclang is correctly installed in the specified location.
#clang.cindex.Config.set_library_path('C:/Program Files (x86)/LLVM/bin')
#clang.cindex.Config.set_library_path('C:/Program Files (x86)/LLVM/bin/libclang.dll')
# I also tried moving the dll into the Python installation folder.
clang.cindex.Config.set_library_file('C:/Python27/DLLs/libclang.dll')
print("Clang path set")
index = clang.cindex.Index.create()
...
I stripped all the other parts of the code, but I can post them if they are relevant. The line
index = clang.cindex.Index.create()
Throws the following error:
Setting clang path
Clang path set
Traceback (most recent call last):
File "D:\libclangtest\boost_python_gen.py", line 60, in <module>
index = clang.cindex.Index.create()
File "D:\libclangtest\clang\cindex.py", line 2095, in create
return Index(conf.lib.clang_createIndex(excludeDecls, 0))
File "D:\libclangtest\clang\cindex.py", line 141, in __get__
value = self.wrapped(instance)
File "D:\libclangtest\clang\cindex.py", line 3392, in lib
lib = self.get_cindex_library()
File "D:\libclangtest\clang\cindex.py", line 3423, in get_cindex_library
raise LibclangError(msg)
clang.cindex.LibclangError: [Error 193] %1 is not a valid Win32 application. To provide a path to libclang use Config.set_library_path() or Config.set_library_file().
What is the reason for this? Am I setting the dll's path wrong? I tried multiple ways, with foreslashes and backslashes, I also tried to move the dll out of Program Files to make the path contain no spaces, but nothing worked.
I am a total beginner to libclang and Python, sry if I'm asking something trivial.
I was running into a similar problem (Windows 7 x64, Anaconda3 x64). Using
import clang.cindex
clang.cindex.Config.set_library_file('C:/Program Files/LLVM/bin/libclang.dll')
fixed the problem. Please note that you need to use slashes (not antislashes), and specify path to bin/libclang.dll (not to lib/libclang.dll).
#SK-logic commented that I should check whether both Python and libclang are either 32bit or 64bit. Libclang was 32bit, but I couldn't find a way to check whether my Python installation is 32 or 64, so I reinstalled the 32bit version, and now it works. So the problem probably was that I had the 64 bit version of Python.

RuntimeError: could not find any library for SDL2_ttf

I have a problem with pysdl2. I'm trying to launch examples from site-packages\sdl2\examples and see this error:
c:\Python33\Lib\site-packages\sdl2\examples>python draw.py
Traceback (most recent call last):
File "draw.py", line 10, in <module>
import sdl2.ext as sdl2ext
File "C:\Python33\lib\site-packages\sdl2\ext\__init__.py", line 14, in <module>
from .common import *
File "C:\Python33\lib\site-packages\sdl2\ext\common.py", line 8, in <module>
from .. import sdlttf
File "C:\Python33\lib\site-packages\sdl2\sdlttf.py", line 40, in <module>
os.getenv("PYSDL2_DLL_PATH"))
File "C:\Python33\lib\site-packages\sdl2\dll.py", line 51, in __init__
raise RuntimeError("could not find any library for %s" % libinfo)
RuntimeError: could not find any library for SDL2_ttf
But files which don't use sdl2_ttf (such as sdl2hello.py) work correctly and without errors. I have no idea how to solve it.
Additional info: WinXP SP3 32bit
This error seems to be the result of the script not finding the SDL2_ttf package.
Following the instructions of the PySDL2 manual, you must have set a PYSDL2_DLL_PATH like so:
# Win32 platforms
set PYSDL2_DLL_PATH=C:\path\to\fancy_project\third_party
# Unix/Posix-alike environments - bourne shells
export PYSDL2_DLL_PATH=/path/to/fancy_project/third_party
# Unix/Posix-alike environments - C shells
setenv PYSDL2_DLL_PATH /path/to/fancy_project/third_party
so you just have to get the SDL2_ttf package here: http://www.libsdl.org/projects/SDL_ttf/ and download the runtime library corresponding to your system (http://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.12-win32-x86.zip) and add it in the same folder where SDL2.dll is. Check out at C:\your-python-directory\DLLs
It's the same with SDL_image, SDL_mixer, SDL_net and SDL_gfx (on another website though for this last one).
Hope this helps !
Got the same issue
brew install sdl2
Solved my problem on OSX

Categories

Resources