error on installation of opencv does not make sense - python

when I run brew install opencv I get the following error:
Error: undefined local variable or method `which_python' for #<Formula opencv (stable) /usr/local/Library/Formula/opencv.rb>
naturally I went to check this out by opening up /usr/local/Library/Formula/opencv.rb. That showed the following ruby declaration:
def which_python
"python" + `python -c 'import sys;print(sys.version[:3])'`.strip
end
so which_python is clearly defined. Just to check and make sure that works, I opened up ruby to see if there was something wrong:
1.9.3-p194 :005 > def which_python
1.9.3-p194 :006?> "python" + `python -c 'import sys;print(sys.version[:3])'`.strip
1.9.3-p194 :007?> end
=> nil
1.9.3-p194 :008 > which_python
=> "python2.7"
This verifies that which_python is defined correctly. Can somebody please explain why this error is occurring and what I can do to get around this.

I resolved this with:
rm /usr/local/Library/Formula/opencv.rb
brew update
brew doctor
brew install opencv
I'm not sure if removing opencv.rb is needed.

Related

How do I build Python 2.7 with unicode UCS-2 support

I find myself in the unfortunate position of supporting an old application that needs python 2.7. I pulled down the latest 2.7 release (wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz) and installed it, but now I'm getting the dreaded "undefined symbol: PyUnicodeUCS2_AsUTF8String" error from one of the packages in the app.
OK, so back out and run:
./configure --enable-shared --enable-unicode=ucs2
make install
python -c "import sys; print('ucs2' if sys.maxunicode == 65535 else 'ucs4')"
but I still get ucs4 for an answer. Looking at the Makefile the config arguments were passed through:
# configure script arguments
CONFIG_ARGS= '--enable-shared' '--enable-unicode=ucs2'
What am I missing? How do I get UCS-2 supported in my python build? Running this in an amazonlinux:2018.03 docker container, I don't see any other python installs on it.
OK, not positive what python is doing with linked libraries, but after fidgeting with this for quite a few hours, it appears that setting the LD_LIBRARY_PATH will get me what I want. I.e.:
> ./configure --enable-shared --enable-unicode=ucs2 --prefix=/fubar/python
...
> make install
...
> export PATH=/fubar/python/bin:$PATH
> python -c "import sys; print('ucs2' if sys.maxunicode == 65535 else 'ucs4')"
ucs4
> export LD_LIBRARY_PATH=/fubar/python/lib:$LD_LIBRARY_PATH
> python -c "import sys; print('ucs2' if sys.maxunicode == 65535 else 'ucs4')"
ucs2
There's probably something obvious in the way all this works, but I haven't had to worry about setting LD_LIBRARY_PATH in a very long time...

Python BDD Behave allure reports failing with format=allure_behave.formatter:AllureFormatter is unknown

I have installed allure 2.8.17. It is on a pipenv environment. When I am running the below command in terminal:
behave -f allure_behave.formatter:AllureFormatter -o reports/
It is failing with the below error
usage: behave [options] [ [DIR|FILE|FILE:LINE] ]+
behave: error: format=allure_behave.formatter:AllureFormatter is unknown
(behave) sharathkrishnan#sharaths-mbp features %
I think you are missing allure-behave:
pip install allure-behave ?
you need to install using pip install allure-behave and then run the above command
This also commonly happens when you point the file path with a typo.
Mostly case sensitive problems like ./Reports instead of ./reports

make file target to check for installed dependencies

I have a makefile where I have targets that depend on having some external clients installed (python3, libxml2, etc).
Here is my makefile
.PHONY: test install-packages mac-setup checkenv target help
EXTERNALS = python3 pip3 xmllint pytest pipenv
P := $(foreach exec,$(EXTERNALS),$(if $(shell which $(exec)),missing,$(warning "===>>>WARNING: No required `$(exec)` in PATH, run `make mac-setup` + `make install-packages` <<<===")))
test: ## run all tests in test directory
pipenv run pytest -v --ignore=path payload_files .
install-packages: ##install python packages listed in Pipfile
pipenv install
mac-setup: ## setup mac for testing
brew install libxml2
brew install python3
brew install pipenv
# see https://github.mycompany.com/ea/ea_test_player_unified/blob/master/run-feature.sh
help:
#grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help
Notice the line
P := $(foreach exec,$(EXTERNALS),$(if $(shell which $(exec)),missing,$(warning "===>>>WARNING: No required `$(exec)` in PATH, run `make mac-setup` + `make install-packages` <<<===")))
This checks for the binaries required. This works.... however I would rather have a checkenv target that performs this and errors so I can attach it too specific targets like test instead of printing out a WARNING that might be overlooked.
Want:
checkenv: # error if which ${binary} fails or *even better* if if binary --version doesn't return the right version: python3 pip3 xmllint pytest pipenv
I tried various techniques that I found around the web including stackoverflow.... but most use the technique I am using above that don't use a make target or just check for one binary. I tried building a loop through an array of binaries but just couldn't get the syntax correct due to make being a PITA :)
Any suggestions?
Note I'm a python newbie, task is to rewrite some jmeter tests in python....so if you have any thoughts on the above approach feel free to share.
Thanks,
Phil
Don't see what the problem is. It looks very straightforward to me, as make allows using multiple targets on the same line:
EXTERNALS := python3 pip3 xmllint pytest pipenv
python3_version := Python 3.7.3
pip3_version := ...
...
.PHONY: checkenv $(EXTERNALS)
checkenv: $(EXTERNALS)
$(EXTERNALS):
if [ "`$# --version`" != "$($#_version)" ]; then echo "$# check failed"; false; fi

Installing Opencv3 in Python on Mac error

I am trying to install Opencv 3 for Python on Mac using this link (https://www.codingforentrepreneurs.com/blog/install-opencv-3-for-python-on-mac/)
I am using python 3.6.4 and I am currently at step 6 (regarding the link)
I am using Python directly from the Mac terminal and when I slot in the following command this error appears:
$ ln -S /usr/local/Cellar/opencv/3.4.0_1/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so /usr/local/lib/python3.6/site-packages/cv2.so
File "<stdin>", line 1
ln -S /usr/local/Cellar/opencv/3.4.0_1/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so /usr/local/lib/python3.6/site-packages/cv2.so
^
SyntaxError: invalid syntax
You essentially need to run a command like:
ln -s SRC TGT
where SRC is the library you have just built/installed and TGT is where you want it to be visible to Python.
Find the SRC file, independently of the OpenCV versions you have installed, like this:
SRC=$(find /usr/local/Cellar/opencv -name "cv2.cpython*so")
and check it looks correct with:
echo "$SRC"
There should be one line. If there is more than one line, it means you have multiple versions of OpenCV installed, so it may look like:
/usr/local/Cellar/opencv/3.4.0_1/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so
/usr/local/Cellar/opencv/3.3.1_7/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so
In that case, choose the one you want and manually set SRC to that one, e.g.
SRC=/usr/local/Cellar/opencv/3.4.0_1/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so
Find the TGT directory, independently of the Python versions you have installed, like this:
TGT=$(find /usr/local/lib/ -type d -name "site-packages")
and check it looks correct with:
echo "$TGT"
There should be one line. If there is more than one line, it means you have multiple versions of Python installed, and it may look something like:
/usr/local/lib/python3.6/site-packages
/usr/local/lib/python3.5/site-packages
If that is the case, choose the one you want to use and set TGT manually, e.g.:
TGT=/usr/local/lib/python3.6/site-packages
Now make the link:
ln -s "$SRC" "$TGT/cv2.so"
In step 6, you first get the sys path, notice that this is done while running python.
You can tell because of the prompt ">>>" in
>>> print(sys.path)
If you then enter:
ln -s /usr/local/Cellar/opencv/3.4.1_4/....
While in Python, you will get the exact error you mentioned.
In order to finish step 6 you now must exit python by typing
>>> exit()
Now you will see the $ prompt.
I realize the way you stated your problem that you were already at the $ prompt, so this might be moot... but if you typed your question rather than cutting and pasting it, maybe you typed it incorrectly here and you were actually still in Python when you had the error.
$ ln -s /usr/local/Cellar/opencv/3.4.1_4/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so /usr/local/lib/python3.6/site-packages/cv2.so

Having trouble installing newest version of Python: make error?

I have Python 2.7 on my Fedora VM and I want to upgrade to Python 3.3.2. I did this:
wget http://python.org/ftp/python/3.3.2/Python-3.3.2.tar.bz2
tar xf Python-3.3.2.tar.bz2
cd Python-3.3.2
./configure --prefix=/usr/local
And then tried
make
Only to get this error:
Objects/abstract.c:2281:20: error: variable 'countva' is uninitialized when
used here [-Werror,-Wuninitialized]
Py_VA_COPY(countva, va);
~~~~~~~~~~~^~~~~~~~~~~~
Include/pyport.h:875:37: note: expanded from:
#define Py_VA_COPY(x, y) Py_MEMCPY((x), (y), sizeof(va_list))
^
Objects/abstract.c:2278:20: note: initialize the variable 'countva' to
silence this warning
va_list countva;
^
= NULL
1 error generated.
make: *** [Objects/abstract.o] Error 1
...what? How do I fix this? There shouldn't be something wrong with the Python installation file, should there?
There is nothing wrong with the Python archive, it must be your environment.
I reproduced your exact steps on my system and it runs on my system. I think the -Werror switch is to blame. It will turn warnings into errors. What your compiler actually encounters is merely a warning.
Can you type in the same terminal echo $CFLAGS and post the output? On my system, this command will produce an empty line. Maybe you have some CFLAGS set in your ~/.bashrc? Or maybe you do source a file in your ~/.bashrc which sets CFLAGS?

Categories