I want to install sequitor g2p a data-driven grapheme-to-phoneme converter
getting error while building sequitor-g2p
I gave command $ python setup.py install --prefix /usr/local/
getting error as follows:
Utility.cc:43:21: error: ‘EOF’ was not declared in this scope
if (is.get() == EOF) return EOF;
^
Utility.cc:48:35: error: ‘EOF’ was not declared in this scope
while (((token = is.get()) != EOF) &&
^
error: command 'i686-linux-gnu-gcc' failed with exit status 1
thanks in advance.
See also fcgio.cpp:50: error: 'EOF' was not declared in this scope
The easiest option is to add
#include <stdio.h>
to Utility.cc.
You can automatically do this for example using patch as in the provided link or by using sed:
wget http://www-i6.informatik.rwth-aachen.de/web/Software/g2p-r1668.tar.gz
tar xvf g2p-r1668.tar.gz
rm -r g2p-r1668.tar.gz
cd g2p
sed -i "27 a #include <stdio.h>" Utility.cc
python setup.py install --prefix /usr/local
Related
If executed inside a Docker container, os.getlogin() throws a FileNotFoundError: [Errno 2] No such file or directory.
I am aware that the Python Docs recommend using a different method, but it's in some code that I can't just change.
I am using ubuntu 22.04 and python 3.10.6 (both inside the Docker container).
I'm hosting from Windows 10 with Docker Desktop and WSL2.
Here's a MWE:
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y \
python3
Build and run it with:
docker build -t mwe .
docker run -it mwe
then execute the following inside the Docker container:
python3 -c "import os; print(os.getlogin())"
and it will throw the error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory
Is there a good way to avoid this error?
This is partially a duplicate of Python os.getlogin problem, but the answers there don't really get to the root of the problem.
This is not a Python issue. We can reproduce the same behavior with a minimal C program:
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int main() {
char *login = getlogin();
if (login == NULL) {
perror("getlogin");
exit(1);
}
printf("login: %s\n", login);
exit(0);
}
If you run this in your container, you'll get as output:
getlogin: No such device or address
Tracing this through the glibc source code, the error comes from the getlogin code, but is actually caused by this code in __getlogin_r_loginuid:
if (uid == (uid_t) -1)
{
__set_errno (ENXIO);
return ENXIO;
}
And we're hitting that code because /proc/self/loginuid has the value:
$ cat /proc/self/loginuid
4294967295
Where 4294967295 is simply -1, which in this case means, "this value has not been initialized", and that's because we haven't entered this shell through any sort of login manager that would normally set that for us.
For a simple workaround, we can just write our current UID to that file:
root#d4da9e11f42e:~# python3 -c 'import os; print(os.getlogin())'
Traceback (most recent call last):
File "<string>", line 1, in <module>
OSError: [Errno 6] No such device or address
root#d4da9e11f42e:~# echo $UID > /proc/self/loginuid
root#d4da9e11f42e:~# python3 -c 'import os; print(os.getlogin())'
root
That would be relatively easy to bake into your container startup.
Another option is monkeypatching the os module to replace os.getlogin with something else (such as getpass.getuser()).
It sounds as if WSL doesn't provide the loginuid feature.
This answer still accurately identifies the problem: getlogin() fails to read the loginuid file, and you get the same error (you can see that code path earlier in the implementation of __getlogin_r_loginuid).
If your kernel doesn't provide this feature, your only real option is fixing the code -- either by modifying the calls to os.getlogin(), or by arranging to monkeypatch the os module before the legacy code calls os.getlogin().
One slightly less orthodox alternative is to use function interposition to override the getlogin library call.
Start with this minimal C code in fake_getlogin.c:
char *getlogin(void) {
return "root";
}
Compiled it to a shared library:
gcc -fPIC -c fake_getlogin.c
ld -o fake_getlogin.so -shared fake_getlogin.o
Embed this in a Dockerfile and arrange to preload it via /etc/ld.so.preload:
FROM ubuntu:22.04
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && \
apt-get install -y \
python3
COPY fake_getlogin.so /lib/fake_getlogin.so
RUN echo /lib/fake_getlogin.so > /etc/ld.so.preload
Now re-try your original reproducer and you should find that it runs without errors:
root#4c86cde47db1:/# python3 -c 'import os; print(os.getlogin())'
root
This assumes that there aren't any more WSL-specific quirks to overcome.
If you were to decide to use the function interposition solution in practice, you should probably arrange to build the shared library as part of your image build process; e.g.:
FROM ubuntu:22.04 AS builder
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && \
apt-get install -y \
build-essential
WORKDIR /src
COPY fake_getlogin.c ./
RUN gcc -fPIC -c fake_getlogin.c && \
ld -o fake_getlogin.so -shared fake_getlogin.o
FROM ubuntu:22.04
COPY --from=builder /src/fake_getlogin.so /lib/fake_getlogin.so
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && \
apt-get install -y \
python3
RUN echo /lib/fake_getlogin.so > /etc/ld.so.preload
I am trying to install guppy. My program uses python3 so I must use pip3 exclusively. When I run:
pip3 install guppy
I get:
src/sets/sets.c:77:1: error: expected function body after function declarator
INITFUNC (void)
^
src/sets/sets.c:39:18: note: expanded from macro 'INITFUNC'
#define INITFUNC initsetsc
^
1 error generated.
error: command 'clang' failed with exit status 1
I tried doing this, even thourgh it wasn't the same and exported gcc and g++:
➜ ~ export CC=gcc
➜ ~ export CXX=g++
Running again:
src/sets/sets.c:77:1: error: expected function body after function declarator
INITFUNC (void)
^
src/sets/sets.c:39:18: note: expanded from macro 'INITFUNC'
#define INITFUNC initsetsc
^
1 error generated.
error: command 'gcc' failed with exit status 1
Most who had this issue used sudo apt-get python-dev or something of the like to resolve this issue, I couldn't find an equivalent for Mac. Is there a way to resolve this issue?
Unfortunately it seems that guppy library works only for Python 2.x. An alternative could be objgraph
Try installing the guppy3 fork of guppy that supports Python 3:
pip3 install guppy3
I am trying to install OpenCV 3.0 for Python on Ubuntu 14.04 but after many installations (and StackOverflow pages read) it still does not work.
In Python (Python 2.7) when importing typing import cv2 I obtain this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libopencv_core.so.2.4: cannot open shared object file: No such file or directory
I have seen that this error may be due to the file /etc/ld.so.conf.d/opencv.conf and therefore I wrote inside it the line /usr/local/opencv/ but it did not help (actually there is no folder opencvin /usr/local/ on my computer...
For the installation I followed the instructions on this website: http://milq.github.io/install-opencv-ubuntu-debian/
I suspect errors occurred during the cmake phase because I got failures like -- Performing Test HAVE_CXX_WMISSING_PROTOTYPES - Failed. I don't know what that means and if it is important for the installation...
I have other errors like
-- checking for module 'gstreamer-base-1.0'
-- package 'gstreamer-base-1.0' not found
During the make phase I obtained this error
[ 31%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/qrc_window_QT.cpp.o
In file included from /home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp:9:0:
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp: In function ‘int qInitResources_window_QT()’:
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp:1749:25: warning: no previous declaration for ‘int qInitResources_window_QT()’ [-Wmissing-declarations]
int QT_MANGLE_NAMESPACE(qInitResources_window_QT)()
^
/usr/include/qt5/QtCore/qglobal.h:100:36: note: in definition of macro ‘QT_MANGLE_NAMESPACE’
# define QT_MANGLE_NAMESPACE(name) name
^
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp: In function ‘int qCleanupResources_window_QT()’:
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp:1758:25: warning: no previous declaration for ‘int qCleanupResources_window_QT()’ [-Wmissing-declarations]
int QT_MANGLE_NAMESPACE(qCleanupResources_window_QT)()
^
/usr/include/qt5/QtCore/qglobal.h:100:36: note: in definition of macro ‘QT_MANGLE_NAMESPACE’
# define QT_MANGLE_NAMESPACE(name) name
^
[ 31%] Generating opencl_kernels_superres.cpp, opencl_kernels_superres.hpp
Do you know what is wrong?
I finally managed to solve my problems. Since this may interested other people, here how I proceed.
I removed entirely opencv from my computer:
sudo make unistall in the repository where I wrote sudo make install
sudo find / -name "*opencv*" -exec rm -i {} \; to remove all files containing "opencv"
sudo find / -name "*cv2.so*" -exec rm -i {} \; to remove all files containing "cv2.so"
conda uninstall opencv (if needed)
I followed this link to install OpenCV2.4.10 for Python2.7: I did only the points 5,6,7 and 12 (the remaining ones are useless for what I wanted). I changed a bit the cmake command and I typed
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_OPENGL=ON -D WITH_VTK=ON -D WITH_GTK=ON ..
Now if when typing import cv2 in Python you get an error like "No module named cv2", edit your .bashrc file with the following command
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
You will have to reload the .bashrc file (source .bahsrc) to apply the change.
Finally I rebooted my computer. And it worked!
To conclude, I don't know why it did not work previously but it appears that with this version of OpenCV I did not encounter any problem!
Good luck!
You didn't install it correctly that's why you can't import it. Here is a guide on how to install it, (it is for an .older version but the commands are the same). OpenCV 3.0 Trouble with Installation
I'm trying to install a python package using easy_install but it keeps saying that a file is missing. I have tried 'sudo apt-get install python2.7-dev'
I'm on xubuntu.
sudo easy_install autopy
Searching for autopy
Reading https://pypi.python.org/simple/autopy/
Best match: autopy 0.51
Downloading https://pypi.python.org/packages/source/a/autopy/autopy-0.51.tar.gz#md5=b92055aa2a3712a9c3b4c874014b450e
Processing autopy-0.51.tar.gz
Writing /tmp/easy_install-lFRYYC/autopy-0.51/setup.cfg
Running autopy-0.51/setup.py -q bdist_egg --dist-dir /tmp/easy_install-lFRYYC/autopy-0.51/egg-dist-tmp-WC7CUY
src/snprintf.c: In function ‘portable_vsnprintf’:
src/snprintf.c:569:19: warning: variable ‘starting_p’ set but not used [-Wunused-but-set-variable]
const char *starting_p;
^
src/png_io.c:3:17: fatal error: png.h: No such file or directory
#include <png.h>
^
compilation terminated.
error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
I have a newish Slackware 14.1 64-bit install (Python 2.7.5), and am trying to install pygraphviz via pip.
When I run:
pip install pygraphviz
however, I get the following error:
In file included from /usr/include/python2.7/Python.h:8:0,
from pygraphviz/graphviz_wrap.c:124:
/usr/include/python2.7/pyconfig.h:6:25: fatal error: pyconfig-64.h: No such file or directory
#include "pyconfig-64.h"
^
compilation terminated.
error: command 'gcc' failed with exit status 1
The referenced pyconfig.h file is:
#include <bits/wordsize.h>
#if __WORDSIZE == 32
#include "pyconfig-32.h"
#elif __WORDSIZE == 64
#include "pyconfig-64.h"
#else
#error "Unknown word size"
#endif
Looking around, there is a lot of info for missing a pyconfig.h file, but not the 64 variant, and I'm struggling to find the package to install to take care of this. I tried to use rpm2tgz and the python-devel rpm for 2.7.5 from Fedora, but it didn't take care of the issue. Also, as I'm running slack, a yum or apt-get command isn't a valid solution, I need to know where I can find the actual package.
to solve problem you need to install python dev pakege
sudo apt-get install python2.7-dev