pipe: Bad file descriptor when running make command - python

Anyone can help me with this issue?
I am trying to run an app, whenever I run make in the terminal I got that error
process_begin: CreateProcess(NULL, python3.8 -c "import sys; print(sys.version_info[:2] >= (3, 8))", ...) failed.enter code here
Makefile:24: pipe: Bad file descriptor
SETUP Creating virtualenv
FATAL Python not found (python3.8)
make: *** [Makefile:21: .venv] Error 1
I've created a venv before running and installed python8.3, pip as well.
Makefile
PYTHON ?= python3.8
FLASK_HOST ?= 127.0.0.1
FLASK_PORT ?= 5000
VENV ?= .venv
SHELL := /bin/bash
PIP := ${VENV}/Scripts/pip
FLASK := ${VENV}/Scripts/flask
CONFIG := licmon/licmon.cfg
SERVERS := licmon/servers.cfg
.PHONY: all
all: ${VENV} config
#printf "\033[38;5;154mSETUP\033[0m \033[38;5;105mInstalling licmon python package\033[0m\n"
#${PIP} install -q -e '.[dev]'
${VENV}:
#printf "\033[38;5;154mSETUP\033[0m \033[38;5;105mCreating virtualenv\033[0m\n"
ifeq (, $(shell which ${PYTHON} 2> /dev/null))
#printf "\033[38;5;220mFATAL\033[0m \033[38;5;196mPython not found (${PYTHON})\033[0m\n"
#exit 1
endif
ifneq (True, $(shell ${PYTHON} -c 'import sys; print(sys.version_info[:2] >= (3, 8))'))
#printf "\033[38;5;220mFATAL\033[0m \033[38;5;196mYou need at least Python 3.8\033[0m\n"
#exit 1
endif
#${PYTHON} -m venv --prompt licmon .venv
#${PIP} install -q -U pip setuptools
${CONFIG}: | ${CONFIG}.example
#printf "\033[38;5;154mSETUP\033[0m \033[38;5;105mCreating config [\033[38;5;147m${CONFIG}\033[38;5;105m]\033[0m\n"
#cp ${CONFIG}.example ${CONFIG}
#printf "\033[38;5;154mSETUP\033[0m \033[38;5;105mCreating config [\033[38;5;147m${SERVERS}\033[38;5;105m]\033[0m\n"
#cp ${SERVERS}.example ${SERVERS}
#sed -i.bak "s/^SECRET_KEY = None/SECRET_KEY = '$$(LC_ALL=C tr -dc A-Za-z0-9 < /dev/urandom | head -c 32)'/" ${CONFIG}
#sed -i.bak "s/^SKIP_LOGIN = False/SKIP_LOGIN = True/" ${CONFIG}
#sed -i.bak "s/^EMAIL_BACKEND = '[^']\+'/EMAIL_BACKEND = 'licmon.vendor.django_mail.backends.console.EmailBackend'/" ${CONFIG}
#rm -f ${CONFIG}.bak
#printf " \033[38;5;82mDon't forget to update the config files if needed!\033[0m\n"
.PHONY: flask-server
flask-server:
#printf " \033[38;5;154mRUN\033[0m \033[38;5;75mRunning Flask dev server [\033[38;5;81m${FLASK_HOST}\033[38;5;75m:\033[38;5;81m${FLASK_PORT}\033[38;5;75m]\033[0m\n"
#${FLASK} run -h ${FLASK_HOST} -p ${FLASK_PORT} --extra-files $(abspath licmon/licmon.cfg):$(abspath licmon/servers.cfg)
.PHONY: build
build:
#printf " \033[38;5;154mBUILD\033[0m \033[38;5;176mBuilding production package\033[0m\n"
#rm -rf build
#source ${VENV}/bin/activate
#${PIP} list
#python setup.py bdist_wheel -q
.PHONY: config
config: ${CONFIG}
.PHONY: clean
clean:
#printf "\033[38;5;154mCLEAN\033[0m \033[38;5;202mDeleting all generated files...\033[0m\n"
#rm -rf .venv newdle.egg-info pip-wheel-metadata dist build
#find newdle/ -name __pycache__ -exec rm -rf {} +

Never use # to suppress echoing makefile commands until you are sure that the makefile is working correctly. And even then, consider not doing so.
Also, I urge you to avoid putting ANSI escape sequences into your makefile. They are obnoxious to read, and they will not be effective in all contexts. Absolutely omit them from any makefile you present here, as they are not part of any minimal reproducible example unless it is asking specifically about them.
Anyway, this problem ...
process_begin: CreateProcess(NULL, python3.8 -c "import sys; print(sys.version_info[:2] >= (3, 8))", ...) failed.enter code here
Makefile:24: pipe: Bad file descriptor
... appears to be a consequence of this problem ...
FATAL Python not found (python3.8)
. The messages are ordered that way in the output because that is the order in which they are generated, reflecting a deep flaw in your approach.
GNU make directives, such as ifeq, are evaluated when the makefile is parsed, before any recipes are run. Thus, this code ...
ifeq (, $(shell which ${PYTHON} 2> /dev/null))
#printf "\033[38;5;220mFATAL\033[0m \033[38;5;196mPython not found (${PYTHON})\033[0m\n"
#exit 1
endif
... does not halt the build immediately if the requested Python interpreter is not found. The exit command is part of a recipe, which isn't (yet) being run. As a consequence, make proceeds to evaluate the next directive either way:
ifneq (True, $(shell ${PYTHON} -c 'import sys; print(sys.version_info[:2] >= (3, 8))'))
. If indeed ${PYTHON} was not found, then the shell command being executed fails with the error reported, but, occurring as that does inside an execution of the $(shell) function, that does not terminate the build. Make decides to build the ${VENV} target, and when executing the recipe for that target, it finally gets around to printing the "FATAL" message and executing the #exit 1 guarded by the above ifeq. That causes make to stop the build and report that the recipe for .venv (== ${VENV}) had an error.
I've created a venv before running and installed python8.3, pip as well.
Notwithstanding what software may or may not have been installed, whatever shell make uses to execute the $(shell) function (which it will also use to execute recipes) does not have a command python3.8 in its executable search path. There is not enough information provided to troubleshoot that further.
Also, make does not see a subdirectoy .venv in its working directory, for it would not otherwise be executing the recipe for the .venv target. If that surprises you, then possibly it results from running make from the wrong working directory. Not much more can be said about that, either.
Overall, I think you're trying too hard, at least on the make side. I would just let the execution of ${PYTHON} in a recipe fail if need be, having not suppressed command echoing. The makefile would be easier to write, and the diagnostic output easier to interpret.

Related

How do I re compile the conda, activate and deactivate commands in miniconda?

For some bizzare reason when I re-logged in to the cluster/HPC I used the conda, activate and deactivate commands stopped working. I printed the place where they'd be but they weren't there but isntead the .c~ file was there and not the bin anymore:
brando9~/miniconda/bin $ ls
2to3 certtool c_rehash genrb img2webp lzfgrep pip3.10 raw2tiff tiffcp unzstd xzegrep
2to3-3.9 chardetect cwebp gif2rgb infocmp lzgrep pip3.9 rdjpgcom tiffcrop wandb xzfgrep
activate.c cjpeg deactivate.c gif2webp infotocap lzless pkcs1-conv reset tiffdither wb xzgrep
bsdcat clear derb gifbuild jpegtran lzma pkgdata rg tiffdump webpinfo xzless
bsdcpio conda-build djpeg gifclrmp jpgicc lzmadec pkginfo sexp-conv tiffinfo webpmux xzmore
bsdtar conda.c~ dwebp giffix lame lzmainfo pngfix shortuuid tiffmedian wish zstd
bunzip2 conda-convert f2py giftext libdeflate-gunzip lzmore png-fix-itxt sqlite3 tiffset wish8.6 zstdcat
bzcat conda-debug f2py3 giftool libdeflate-gzip makeconv ppm2tiff sqlite3_analyzer tiffsplit wrjpgcom zstdgrep
bzcmp conda-develop f2py3.9 gnutls-cli libpng16-config ncursesw6-config psicc srptool tificc x86_64-conda_cos7-linux-gnu-ld zstdless
bzdiff conda-env.c~ fax2ps gnutls-cli-debug libpng-config nettle-hash psktool tabs toe x86_64-conda-linux-gnu-ld zstdmt
bzegrep conda-index fax2tiff gnutls-serv linkicc nettle-lfib-stream pydoc tclsh torchrun xml2-config
bzfgrep conda-inspect ffmpeg h264dec lz4 nettle-pbkdf2 pydoc3 tclsh8.6 tput xmlcatalog
bzgrep conda-metapackage ffprobe h264enc lz4c normalizer pydoc3.9 tic tqdm xmllint
bzip2 conda-render freetype-config iconv lz4cat ocsptool python tiff2bw transicc xz
bzip2recover conda-skeleton genbrk icu-config lzcat openssl python3 tiff2pdf tset xzcat
bzless convert-caffe2-to-onnx gencfu icuinfo lzcmp pal2rgb python3.9 tiff2ps unlz4 xzcmp
bzmore convert-onnx-to-caffe2 gencnval idle3 lzdiff patch python3.9-config tiff2rgba unlzma xzdec
captoinfo cph gendict idle3.9 lzegrep patchelf python3-config tiffcmp unxz xzdiff
I tried renaming the file to remove the tilde ~ and recompiling it with gcc -Wall activate.c -o activate for each of the three c files but it failed with this msg:
brando9~/miniconda/bin $ gcc -Wall activate.c -o activate
activate.c:1:2: error: invalid preprocessing directive #!
#!/bin/sh
^
activate.c:2:1: warning: data definition has no type or storage class
_CONDA_ROOT="/dfs/scratch0/brando9/miniconda"
^
activate.c:2:1: warning: type defaults to ‘int’ in declaration of ‘_CONDA_ROOT’ [-Wimplicit-int]
activate.c:3:3: error: invalid preprocessing directive #Copyright
# Copyright (C) 2012 Anaconda, Inc
^
activate.c:4:3: error: invalid preprocessing directive #SPDX
# SPDX-License-Identifier: BSD-3-Clause
^
activate.c:5:1: error: stray ‘\’ in program
\. "$_CONDA_ROOT/etc/profile.d/conda.sh" || return $?
^
activate.c:5:4: error: expected identifier before string constant
\. "$_CONDA_ROOT/etc/profile.d/conda.sh" || return $?
^
I tried catting the install .sh file I used with wget wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh but the output was unreadable:
...
m�gI���w%��.{=[��M7O�<��R��yj#���#K��r�q�m���V)=��O���?�˳�����MU���i2|I%�D�h�E:���/C� �l>��pD�Y����w��i#��X�eT��eҠ����Grq����X*9l���dW
�~����q�NyF?�_EbE��׳B&���>�Kw5nZ!~ʒ6m�ˡ�����ǟ�� �nX�г]1��R���S 3�}��<Z���En%'��tS�}�;�G7sFi�[��N3�W34<>[�h����M~�1�T�� {&��>H:�Eo �~��Pp�*��%�Օ� �d��H�W��H�7����~h�2�V[Iў��5O�H&�\�u�
u�ZD��Y[d�
��s*�%�u�j� y\AB����� ��qnm/5��j#k����<Z�s3�y*�i����NO�4&��~�邲�W�S��גDY��{�G���8�[���H�?��������H�e+ix�16-�yYI�܉{�j2��P�D�����ڬ��k^��=M��+ɓ�_p�!����k+!�U���B[nj�]nL�
�/5�5X&��0*:�{�=SJ\I�Z}�;?�d��6�[/�JOn'��G����X���5J���K�P��6>e�!����`*�޿��ěX2ؓ�3��h!�#�qП�R}P�1�ï�)=�U¶#|�G�^C
at which point I decided I had no idea what happened or what to fix it. Of course my path is fine as other question on SO suggest to fix Conda command not found. At this point I decided I have no idea what happened or how to fix it anymore. Any help that doesn't require an hour long re-install of conda?
related:
cross https://www.reddit.com/r/learnmachinelearning/comments/yrt9yf/how_do_i_re_compile_the_conda_activate_and/
other post that didn't help How to run Conda?
google groups: https://groups.google.com/a/anaconda.com/g/anaconda/c/DpdjFjlj0wg
quora: https://www.quora.com/unanswered/How-do-I-re-compile-the-conda-activate-and-deactivate-commands-in-miniconda
conda gitissue: https://github.com/conda/conda/issues/12086
The bin/activate and bin/deactivate files have never been binaries, but rather simple shell scripts. The situation described seems to indicate somehow a .c was appended to the file names. Looks like you could simply rename them (remove the .c) and they would go back to normal functionality.
For reference, here is my version:
$ cat ${CONDA_PREFIX}/bin/activate
#!/bin/sh
_CONDA_ROOT="/Users/mfansler/mambaforge-arm64"
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
\. "$_CONDA_ROOT/etc/profile.d/conda.sh" || return $?
conda activate "$#"
which essentially looks identical (up to paths), to what gcc emits in OP as the lines of the activate.c file.
However, I'd note that using bin/activate is outmoded, AFAIK. Since Conda v4.6, conda (de|)activate have been shell functions defined by conda shell.posix hook. The code in the bin/activate file is a recapitulation of what is already provided in the user shell after running conda init once (usually at installation time).

"except Error as e SyntaxError" when installing nodejs

I've been trying to install nodejs on my VPS for a little while now. Since I'm using CentOs 5.6 I had to build it from source.
More so I need the python 2.7 as the default python on my box was 2.4.
I compiled python from source and it was installed successfully in /usr/local/bin/python2.7.
Now the problem is upon issuing make in the nodejs directory it reaches the following exceptions.
.
.
.
LD_LIBRARY_PATH=/root/node/out/Release/lib.host:/root/node/out/Release/lib.tar
get:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../deps/v8/tools/gyp; mkdir -p
/root/node/out/Release/obj/gen; python ../../tools/generate-trig-table.py "/root
/node/out/Release/obj/gen/trig-table.cc"
touch /root/node/out/Release/obj.host/deps/v8/tools/gyp/generate_trig_table.st
amp
LD_LIBRARY_PATH=/root/node/out/Release/lib.host:/root/node/out/Release/lib.tar
get:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../deps/v8/tools/gyp; mkdir -p
/root/node/out/Release/obj/gen; python ../../tools/js2c.py "/root/node/out/Relea
se/obj/gen/libraries.cc" CORE off ../../src/runtime.js ../../src/v8natives.js ..
/../src/array.js ../../src/string.js ../../src/uri.js ../../src/math.js ../../sr
c/messages.js ../../src/apinatives.js ../../src/debug-debugger.js ../../src/mirr
or-debugger.js ../../src/liveedit-debugger.js ../../src/date.js ../../src/json.j
s ../../src/regexp.js ../../src/arraybuffer.js ../../src/typedarray.js ../../src
/weak_collection.js ../../src/promise.js ../../src/object-observe.js ../../src/m
acros.py
File "../../tools/js2c.py", line 387
except Error as e:
^
SyntaxError: invalid syntax
make[1]: *** [/root/node/out/Release/obj/gen/libraries.cc] Error 1
make[1]: Leaving directory `/root/node/out'
make: *** [node] Error 2
Somewhere I read that the Exception syntax has changed from python 2.6 up and I figured it must be using the old python so I did the following but it made no difference:
PYTHON=/usr/local/bin/python2.7
export PYTHON
python2.7 configure && make && make install
Now I'm wondering how should I proceed?
IMO you need to place python2.7 first in path and then run:
export PATH=/usr/local/bin:${PATH}
python2.7 configure && make && make install
If this does not work, probably one of the Python scripts is looking for python. You can probably fix that by symlinking python, something like:
mkdir /tmp/py27
ln -s /usr/local/bin/python2.7 /tmp/py27/python
export PATH=/tmp/py27:${PATH}
python configure && make && make install
Is all caps PYTHON a valid environment variable?
http://www.wellho.net/resources/ex.php4?item=y115/penv.py
I would think you would rather create a sym link to the correct python interpreter.
ln -s /usr/local/bin/python2.7 /usr/local/bin/python

How to change python version in makefile - compiling Multicorn (PostgreSQL FDW extension)

I'm trying to install PostgreSQL extension Multicorn on CentOS 6.5. The problem that I have though is that default version of python on Centos is 2.6 and Multicorn requires 2.7 or 3.3. I'm trying to compile Multicorn using this tutorial, but it's a little dated and the step where python version is changed doesn't work anymore:
sed -i 's/^PYEXEC = python$/PYEXEC = python2.7/' Makefile
Can someone help me to make the above command work again, or show me how to edit the makefile to change the version of python? I can call python version 2.7 in the command line with python2.7. The version 2.6 is called with just python - apparently I can't change that without breaking CentOS.
This is the makefile:
MODULE_big = multicorn
OBJS = src/errors.o src/python.o src/query.o src/multicorn.o
DATA = $(filter-out $(wildcard sql/*--*.sql),$(wildcard sql/*.sql))
DOCS = $(wildcard doc/*.md)
EXTENSION = multicorn
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
all: preflight-check sql/$(EXTENSION)--$(EXTVERSION).sql
install: python_code
sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql
cp $< $#
preflight-check:
./preflight-check.sh
python_code: setup.py
cp ./setup.py ./setup--$(EXTVERSION).py
sed -i -e "s/__VERSION__/$(EXTVERSION)-dev/g" ./setup--$(EXTVERSION).py
$(PYTHON) ./setup--$(EXTVERSION).py install
rm ./setup--$(EXTVERSION).py
release-zip: all
git archive --format zip --prefix=multicorn-$(EXTVERSION)/ --output ./multicorn-$(EXTVERSION).zip HEAD
unzip ./multicorn-$(EXTVERSION).zip
rm ./multicorn-$(EXTVERSION).zip
sed -i -e "s/__VERSION__/$(EXTVERSION)/g" ./multicorn-$(EXTVERSION)/META.json ./multicorn-$(EXTVERSION)/setup.py ./multicorn-$(EXTVERSION)/python/multicorn/__init__.py
zip -r ./multicorn-$(EXTVERSION).zip ./multicorn-$(EXTVERSION)/
rm ./multicorn-$(EXTVERSION) -rf
coverage:
lcov -d . -c -o lcov.info
genhtml --show-details --legend --output-directory=coverage --title=PostgreSQL --num-spaces=4 --prefix=./src/ `find . -name lcov.info -print`
DATA = sql/$(EXTENSION)--$(EXTVERSION).sql
EXTRA_CLEAN = sql/$(EXTENSION)--$(EXTVERSION).sql ./multicorn-$(EXTVERSION).zip
PG_CONFIG ?= pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
REGRESS = virtual_tests
include $(PGXS)
with_python_no_override = no
ifeq ($(with_python),yes)
with_python_no_override = yes
endif
ifdef PYTHON_OVERRIDE
with_python_no_override = no
endif
ifeq ($(with_python_no_override),yes)
SHLIB_LINK = $(python_libspec) $(python_additional_libs) $(filter -lintl,$(LIBS))
override CPPFLAGS := -I. -I$(srcdir) $(python_includespec) $(CPPFLAGS)
override PYTHON = python${python_version}
else
ifdef PYTHON_OVERRIDE
override PYTHON = ${PYTHON_OVERRIDE}
endif
ifeq (${PYTHON}, )
override PYTHON = python
endif
python_version = $(shell ${PYTHON} --version 2>&1 | cut -d ' ' -f 2 | cut -d '.' -f 1-2)
PYTHON_CONFIG ?= python${python_version}-config
PY_LIBSPEC = $(shell ${PYTHON_CONFIG} --libs)
PY_INCLUDESPEC = $(shell ${PYTHON_CONFIG} --includes)
PY_CFLAGS = $(shell ${PYTHON_CONFIG} --cflags)
PY_LDFLAGS = $(shell ${PYTHON_CONFIG} --ldflags)
SHLIB_LINK = $(PY_LIBSPEC) $(PY_LDFLAGS) $(PY_ADDITIONAL_LIBS) $(filter -lintl,$(LIBS))
override PG_CPPFLAGS := $(PY_INCLUDESPEC) $(PG_CPPFLAGS)
override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
endif
PYTHON_TEST_VERSION ?= $(python_version)
PG_TEST_VERSION ?= $(MAJORVERSION)
SUPPORTS_WRITE=$(shell expr ${PG_TEST_VERSION} \>= 9.3)
TESTS = $(wildcard test-$(PYTHON_TEST_VERSION)/sql/multicorn*.sql)
ifeq (${SUPPORTS_WRITE}, 1)
TESTS += $(wildcard test-$(PYTHON_TEST_VERSION)/sql/write*.sql)
endif
REGRESS = $(patsubst test-$(PYTHON_TEST_VERSION)/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test-$(PYTHON_TEST_VERSION) --load-language=plpgsql
$(info Python version is $(python_version))
The best practice is to run make as
PYTHON=python2.7 make
If you take a look at line 26 of your Makefile, you'll see that compilation is handled by setup.py script that is invoked by executable specified in $(PYTHON) variable which you can override by setting it from environment. Another way to do this (e.g. if you want to do multiple builds) is this one:
export PYTHON=python2.7
make
Changing script behavior by enviroment variables or command line arguments is more reasonable and often more simple than patching script source itself.
More about Makefile variables: http://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_6.html#SEC68

How to correct a compile/build issue with quickfix (v1.13.3) with Python support (... "_quickfix" import exception)

It took the equivalent of a 1/2 day for me to figure this out, so I want to share the Quickfix Engine compile problem I encountered and the solution.
I didn't get a reply from the "Quickfix Engine" help resources pointed to here:
"http://quickfixengine.org/help"... thus another reason I am providing this.
Environment: Fedora 18 -and- CentOS6 (64bit).
After successfully compiling quickfix with Python support (i.e. configure [opts]; make; make install), I got the following python import exception indicating that the python module, "_quickfix", could not be found:
==============================================
user$ python -c "import quickfix"
Traceback (most recent call last):
File " ", line 1, in
File "/home/user/APPS.d/ENTHOUGHT-PYTHON-IDE.d/x86_64.d/latest/lib/python2.7/site-packages/quickfix.py", line 7, in
import _quickfix
ImportError: No module named _quickfix
==============================================
The problem appears to be in the install script invoked by "make install".
The python interpreter is saying that the "_quickfix" module does not exit. As can be seen from the list of files install by "make install" below, there is no "_quickfix.py" file, but there is a reference to a "_quickfix.so" file and a "_quickfix.dylib" file:
/home/user/.local/lib/python2.7/site-packages/_quickfix.dylib -> /home/user/APPS.d/QUICKFIX.d/latest/lib/python/_quickfix.dylib
/home/user/.local/lib/python2.7/site-packages/_quickfix.so -> /home/user/APPS.d/QUICKFIX.d/latest/lib/python/_quickfix.so
/home/user/.local/lib/python2.7/site-packages/quickfix40.py
/home/user/.local/lib/python2.7/site-packages/quickfix41.py
/home/user/.local/lib/python2.7/site-packages/quickfix42.py
/home/user/.local/lib/python2.7/site-packages/quickfix42.pyc
/home/user/.local/lib/python2.7/site-packages/quickfix43.py
/home/user/.local/lib/python2.7/site-packages/quickfix44.py
/home/user/.local/lib/python2.7/site-packages/quickfix50.py
/home/user/.local/lib/python2.7/site-packages/quickfix50sp1.py
/home/user/.local/lib/python2.7/site-packages/quickfix50sp2.py
/home/user/.local/lib/python2.7/site-packages/quickfix.py
/home/user/.local/lib/python2.7/site-packages/quickfix.pyc
/home/user/.local/lib/python2.7/site-packages/quickfixt11.py
/home/user/APPS.d/QUICKFIX.d/latest/lib/libquickfix.la
/home/user/APPS.d/QUICKFIX.d/latest/lib/libquickfix_python.la
/home/user/APPS.d/QUICKFIX.d/latest/lib/libquickfix_python.so.10.0.0
/home/user/APPS.d/QUICKFIX.d/latest/lib/libquickfix_python.so.10 -> libquickfix_python.so.10.0.0
/home/user/APPS.d/QUICKFIX.d/latest/lib/libquickfix_python.so -> libquickfix_python.so.10.0.0
/home/user/APPS.d/QUICKFIX.d/latest/lib/libquickfix.so.14.0.0
/home/user/APPS.d/QUICKFIX.d/latest/lib/libquickfix.so.14 -> libquickfix.so.14.0.0
/home/user/APPS.d/QUICKFIX.d/latest/lib/libquickfix.so -> libquickfix.so.14.0.0
/home/user/APPS.d/QUICKFIX.d/latest/lib/pkgconfig/quickfix.pc
SOLUTION:
The problem is that the first two entries above, which are symbolic links, are broken.
First, the destination directory is incorrect:
/home/user/APPS.d/QUICKFIX.d/latest/lib/python/...
should actually be:
/home/user/APPS.d/QUICKFIX.d/latest/lib/...
So we fix that first:
user$ cd /home/user/.local/lib/python2.7/site-packages
user$ rm _quickfix.so _quickfix.dylib
user$ ln -s /home/user/APPS.d/QUICKFIX.d/latest/lib/_quickfix.so _quickfix.so
user$ ln -s /home/user/APPS.d/QUICKFIX.d/latest/lib/_quickfix.dylib _quickfix.dylib
Next, with destination directory location corrected, the symbolic links are still broken; this time because the file names that they point to in that (just corrected) destination directory don't exist (i.e. "_quickfix.so" and "_quickfix.dylib" don't exist).
After playing around a little, I got things to work by creating those missing files like so:
user$ cd /home/user/APPS.d/QUICKFIX.d/latest/lib
user$ ln -s libquickfix_python.so _quickfix.so
user$ ln -s <???> _quickfix.dylib # Actually I didn't create this one yet. It's not yet clear to me what it should point to. I Will update this post later.
-
Note: Because I compiled QuickFix so that it does not install to the traditional "/usr/local/" directory structure, I had to append my "LD_LIBRARY_PATH" to include: "/home/user/APPS.d/QUICKFIX.d/latest/lib"
With minimal testing, things seem to work now (or at least in the right direction):
user$ python -c "import quickfix"; echo ${?}
0
user$ python -c "import quickfix42"; echo ${?}
0
When I figure out what the second link should be (if it is necessary), or if I should encounter any run-time errors with the corrections I implemented, I'll update/edit this post.
I hope this helps someone.
Noel
Had the same problem in Ubuntu 13.04. configured with python support and used the default destination (/usr/local/...). After successful compilation then worked out a similar solution with the following steps;
Create missing files/symlinks;
cd /usr/local/lib
sudo ln -s libquickfix_python.so _quickfix.so
sudo ln -s _quickfix.so _quickfix.dylib
Change/update existing symlinks to new location:
cd /usr/lib/python2.7/dist-packages/
sudo ln -s /usr/local/lib/_quickfix.so _quickfix.so
sudo ln -s /usr/local/lib/_quickfix.so _quickfix.dylib
Add new library path
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH${LD_LIBRARY_PATH:+:}/usr/local/lib
You do not need to create multiple symlinks - you only need to remove the bad symlinks and create one new symlink for _quickfix.so for everything to work:
rm /usr/local/lib/python2.7/site-packages/_quickfix.dylib
rm /usr/local/lib/python2.7/site-packages/_quickfix.so
ln -s /usr/local/lib/libquickfix_python.dylib /usr/local/lib/python2.7/site-packages/_quickfix.so
This is on OS X. For Linux you will need to use the following (as the dylib extension is OS X specific)
ln -s /usr/local/lib/libquickfix_python.so /usr/local/lib/python2.7/site-packages/_quickfix.so

How can I check the syntax of Python script without executing it?

I used to use perl -c programfile to check the syntax of a Perl program and then exit without executing it. Is there an equivalent way to do this for a Python script?
You can check the syntax by compiling it:
python -m py_compile script.py
You can use these tools:
PyChecker
Pyflakes
Pylint
import sys
filename = sys.argv[1]
source = open(filename, 'r').read() + '\n'
compile(source, filename, 'exec')
Save this as checker.py and run python checker.py yourpyfile.py.
Here's another solution, using the ast module:
python -c "import ast; ast.parse(open('programfile').read())"
To do it cleanly from within a Python script:
import ast, traceback
filename = 'programfile'
with open(filename) as f:
source = f.read()
valid = True
try:
ast.parse(source)
except SyntaxError:
valid = False
traceback.print_exc() # Remove to silence any errros
print(valid)
Pyflakes does what you ask, it just checks the syntax. From the docs:
Pyflakes makes a simple promise: it will never complain about style, and it will try very, very hard to never emit false positives.
Pyflakes is also faster than Pylint or Pychecker. This is largely because Pyflakes only examines the syntax tree of each file individually.
To install and use:
$ pip install pyflakes
$ pyflakes yourPyFile.py
python -m compileall -q .
Will compile everything under current directory recursively, and print only errors.
$ python -m compileall --help
usage: compileall.py [-h] [-l] [-r RECURSION] [-f] [-q] [-b] [-d DESTDIR] [-x REGEXP] [-i FILE] [-j WORKERS] [--invalidation-mode {checked-hash,timestamp,unchecked-hash}] [FILE|DIR [FILE|DIR ...]]
Utilities to support installing Python libraries.
positional arguments:
FILE|DIR zero or more file and directory names to compile; if no arguments given, defaults to the equivalent of -l sys.path
optional arguments:
-h, --help show this help message and exit
-l don't recurse into subdirectories
-r RECURSION control the maximum recursion level. if `-l` and `-r` options are specified, then `-r` takes precedence.
-f force rebuild even if timestamps are up to date
-q output only error messages; -qq will suppress the error messages as well.
-b use legacy (pre-PEP3147) compiled file locations
-d DESTDIR directory to prepend to file paths for use in compile-time tracebacks and in runtime tracebacks in cases where the source file is unavailable
-x REGEXP skip files matching the regular expression; the regexp is searched for in the full path of each file considered for compilation
-i FILE add all the files and directories listed in FILE to the list considered for compilation; if "-", names are read from stdin
-j WORKERS, --workers WORKERS
Run compileall concurrently
--invalidation-mode {checked-hash,timestamp,unchecked-hash}
set .pyc invalidation mode; defaults to "checked-hash" if the SOURCE_DATE_EPOCH environment variable is set, and "timestamp" otherwise.
Exit value is 1 when syntax errors have been found.
Thanks C2H5OH.
Perhaps useful online checker PEP8 : http://pep8online.com/
Thanks to the above answers #Rosh Oxymoron. I improved the script to scan all files in a dir that are python files. So for us lazy folks just give it the directory and it will scan all the files in that directory that are python. you can specify any file ext. you like.
import sys
import glob, os
os.chdir(sys.argv[1])
for file in glob.glob("*.py"):
source = open(file, 'r').read() + '\n'
compile(source, file, 'exec')
Save this as checker.py and run python checker.py ~/YOURDirectoryTOCHECK
for some reason ( I am a py newbie ... ) the -m call did not work ...
so here is a bash wrapper func ...
# ---------------------------------------------------------
# check the python synax for all the *.py files under the
# <<product_version_dir/sfw/python
# ---------------------------------------------------------
doCheckPythonSyntax(){
doLog "DEBUG START doCheckPythonSyntax"
test -z "$sleep_interval" || sleep "$sleep_interval"
cd $product_version_dir/sfw/python
# python3 -m compileall "$product_version_dir/sfw/python"
# foreach *.py file ...
while read -r f ; do \
py_name_ext=$(basename $f)
py_name=${py_name_ext%.*}
doLog "python3 -c \"import $py_name\""
# doLog "python3 -m py_compile $f"
python3 -c "import $py_name"
# python3 -m py_compile "$f"
test $! -ne 0 && sleep 5
done < <(find "$product_version_dir/sfw/python" -type f -name "*.py")
doLog "DEBUG STOP doCheckPythonSyntax"
}
# eof func doCheckPythonSyntax

Categories

Resources