Unable to install Scipy latest version 1.9.3 on python3.8-alpine image - docker

Trying to install Scipy latest version (1.9.3) on python3.8-alpine image
tiangolo/uwsgi-nginx-flask:python3.8-alpine
is not successful.
Scipy tries to install numpy 1.8.5 and it fails with following error.
ImportError: cannot import name 'Log' from 'distutils.log' (/tmp/pip-build-env-28q9f6x4/overlay/lib/python3.8/site-packages/setuptools/_distutils/log.py)
I can goahead and install lower version of scipy. But I am having issue with Sklearn
While trying to install sklearn, it tries to install latest scipy and it fails.
Is there a way i can enforce scipy version to be installed for sklearn

I had the same problem with alpine and python.
This article shows that alpine images should not be used with python as it:
Make your builds much slower.
Make your images bigger.
On occassion, introduce obscure runtime bugs.
I think that your problem comes from the fact that alpine image does not handle wheels files properly.
I would recommend you to switch from python:3.8-alpine to python:3.8-slim.

The problem comes from setuptools. Pin to a version less than 65. Scipy should build on Alpine from source without issue. One of the scipy continuous integration tests checks this. https://github.com/scipy/scipy/blob/main/ci/cirrus_general_ci.yml#L40.

Related

installing old versions of cv2 using pip

i've been trying to download older versions of cv2 as an easy way to get around not being able to use SIFT.
I've tried the following:
pip install opencv-contrib-python==3.4.2.17
however I get this error:
ERROR: Could not find a version that satisfies the requirement opencv-contrib-python==3.4.2.17 (from versions: 3.4.8.29, 3.4.9.31, 3.4.9.33, 4.1.2.30, 4.2.0.32, 4.2.0.34)
ERROR: No matching distribution found for opencv-contrib-python==3.4.2.17
All the advice I've seen on the site so far tells me to either download these older versions of opencv or to build it myself (which seems like an absolute nightmare)
Anyone have any suggestions on how to install these older versions of cv2?
opencv-contrib-python 3.4.2.17 provides wheels for Pythons up to 3.7. Probably you use Python 3.8.
Use Python 3.7 (or lower). Or compile from sources for 3.8.

Conda does not install latest available version

On Ubuntu in a Conda environment with Python 3.7.3, when I run
conda install -c conda-forge opencv
I get OpenCV 3.4.2 (checked with import cv2 and then cv2._version__) even though https://anaconda.org/conda-forge/opencv indicates version 4.11. Why?
Note that I didn't have OpenCV installed previously (I ran conda uninstall opencv and it got completely removed)
tl;dr You likely have previously installed dependencies that need updating. If you require a specific version, say 4.1, then express this to Conda:
conda install -c conda-forge opencv=4.1
Explanation
How Conda Interprets Specifications
A literal translation of the command
conda install -c conda-forge opencv
would go something like
With the conda-forge channel included, ensure that some version of the package opencv is installed in the currently active environment.
The logic here implies that any version it can install would be a valid solution. It also doesn't tell it that it must come from Conda Forge, only that that channel should be included.1
Two-Stage Solve Strategy
Starting with v4.7, Conda uses a two-stage dependency solving strategy. The two stages are
Solve with an implicit --freeze-installed|--no-update-deps flag. This attempts to find the newest version of the requested package that has no conflicts with installed packages. That is, it considers any installation of the package, no matter the version, to be a satisfactory solution. If it works, then it's done. Otherwise, move on to...
An unrestricted solve (what used to be default in Conda < 4.7). This frees up dependencies to be updated and will often result in the latest versions being installed unless there are previous explicit specifications on those packages.2
This strategy aims to provide a faster solve and install experience, by avoiding having to change anything in your environment. It also helps keep the environment stable by avoiding unnecessary version changes.
Specific Failure in Question
What happened in OP's case? One of the dependencies requirements of OpenCV was likely newer in v4.1.1 than what was already installed, but that dependency's version was compatible with installing OpenCV 3.4.2. Hence, the only thing that would change was adding opencv plus missing dependencies. Technically, this is a valid solution since one only asked for some version of opencv to be installed.
Getting the Latest Version
Option: Specifying the Version
If you know you want a specific version then you can always specify it
conda install -c conda-forge opencv=4.1.1
and since Conda can't install this without updating something in your env, the first round of solve will fail, and the full solve will get it for you.
Option: Skip the Freeze
Of course, you may not always know what the latest version number is and don't want to have to look this up on Anaconda Cloud every time. Fortunately, there is the --update-deps flag that essentially skips over the first solve stage and goes straight to the full solve. This will install the latest version for your system, as well as update any of the dependencies.
conda install --update-deps -c conda-forge opencv
Important Note: The --update-deps flag has a side-effect of converting dependencies to explicit specifications. While this is an internal environment state (managed through <env>/conda-meta/history), it does have some behavioral consequences (bugs!):
the result of the conda env export --from-history command will subsequently include all packages, instead of just the ones the user explicitly requested in the past
conda remove will not be able to prune dependencies; e.g., if scipy was installed, it would pull in numpy; if only scipy depended on numpy and scipy was removed, normally numpy would also get removed. This wouldn't work after using the --update-deps flag.
[1]: The behavior here depends on the channel_priority configuration option. With the strict setting, conda-forge would be prioritized over other channels; with the flexible setting, it is simply added to the list and the latest compatible version from any channel is selected.
[2]: One can check the explicit specifications of an environment with conda env export --from-history.

sift = cv2.xfeatures2d.SIFT_create() not working even though have contrib installed

So I am trying to use:
sift = cv2.xfeatures2d.SIFT_create()
and it is coming up with this error:
cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1207: error: (-213:The function/feature is not implemented)
This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake
option and rebuild the library in function 'cv::xfeatures2d::SIFT::create'
I am using Python 3.5.0 and opencv(3.4.3) and I am just using idle. This occured after I tried to install TensorFlow and I have tried looking around and have installed opencv-contrib-python but I am still getting the same error. Thank you in advance and I apologise if I have not included enough info
I had the same problem. It seems that SIRF and SURF are no longer available in opencv > 3.4.2.16. I chose an older opencv-python and opencv-contrib-python versions and solved this problem. Here is the history version about opencv-python, and I use the following code :
pip install opencv-python==3.4.2.16
pip install opencv-contrib-python==3.4.2.16
Edit
For Anaconda User just this instead of pip
conda install -c menpo opencv
this will install cv2 3.4.1 and everything you need to run SIFT
Since SIFT patent expired, SIFT has been moved to the main repo.
To use SIFT in Opencv, You should use cv2.SIFT_create() instead of cv2.xfeatures2d.SIFT_create() now. (xfeatures2d only exists in the contrib package, but sift is part of the main package now.)
Below link will be helpful.
https://github.com/opencv/opencv/issues/16736
Edit: The opencv-contrib-python-nonfree was removed from pypi.
On Linux/ MacOS, I've found a better solution! To access nonfree detectors use:
pip install opencv-contrib-python-nonfree
It may be due to a mismatch of opencv version and opencv-contrib version.
If you installed opencv from the source using CMake, and the source version is different from the version of opencv-contrib-python, uninstall the current opencv-contrib-python and do pip install opencv-contrib-python==<version of the source>.X or an another compatible version.
One version setup that I have running is opencv source (3.2), opencv-python (3.4.0.14) and opencv-contrib-python (3.4.2.17)

When i import parse in ipython , computer say 'parse' it not defined

I think i don't have parse library. So, Where can i get it?
As beginner, I need your help.
I wrote from lxml.html import parse , Computer say name 'parse' is not defined
You actually probably need the lxml package, which was in the comment by cel. It seems to me like your question is concerning how to actually install the package. Everything at PyPi (the Python package index) can be installed in several ways. For me, the easiest is using pip, which is a tool for installing Python packages. Here are some links for how to get pip on your machine for different operating systems: Windows, Mac OSX, or in general.
Once you have pip installed, you go to your command line and type
pip install ['package_name']
where, in your case, package_name would be lxml. Once you do that, your import should work just fine. The full pip documentation is here.
If you prefer to manually install the package, you can download the source and install it according to the Python docs for Python 2.x or 3.x.

Installing open cv and python to run together

I have already installed Open CV 2.4.0 beta in (D:/BACKUP/install/opencv) and installed python 2.7.2, scipy and numpy fpr 2.7 in (D:/BACKUP/install/python). Now I want to know what should I do to make it work fine. Help me with clear and step by step guide to set up my environmental variables and other settings that i should make so that i can start using it.
What about a small slice a googling/reading the doc ?
http://opencv.willowgarage.com/wiki/InstallGuide
http://luugiathuy.com/2011/02/setup-opencv-for-python/
I find this compilation of pre-compiled binaries extremely useful.
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Every time i have problems installing anything with pip, these always seem to do the trick.

Resources