Best way to install OpenCV on Windows with Enthought Canopy Python? - python

I've got the Enthought Canopy Python distribution on Windows, and I'd
like to add the OpenCV python bindings.
I have downloaded the latest OpenCV from
http://sourceforge.net/projects/opencvlibrary/
but I don't see any setup.py file.
So I'm wondering:
What is the best way to install OpenCV on windows to have it working
under Enthought Canopy Python?

I stumbled on this same issue. Here's what I did:
Unpack the OpenCV distribution into a folder, for example: C:\RPS\python\epd32
Open a text editor and create a one line file that contains the full path where you installed OpenCV + the subdirectory where the python binding lives, for example: C:\RPS\python\epd32\opencv\build\python\2.7.
Save this .pth file in your Enthought Canopy user site packages folder, for example: C:\Users\rsignell\AppData\Local\Enthought\Canopy32\User\Lib\site-packages\opencv.pth
Open Enthought Canopy and try typing import cv2. It should now work!
I do it this way because I like having the whole OpenCV distro on my system, with the examples and other stuff.
But if you don't want the whole OpenCV distro hanging around, you could also just copy <opencv>\build\python\2.7\cv2.pyd into your site-packages directory and then delete the directory that OpenCV unpacked everything into.
Or to avoid extracting everything, you could open the opencv.exe using with something like 7-zip (open inside) and extract just <opencv>\build\python\2.7\cv2.pyd into your site-packages directory.

Opencv on Windows has been available pre-built on Windows to Canopy subscribers (i.e. in the Canopy repository - https://www.enthought.com/products/canopy/package-index/) since a few days before this question was posted. Sorry that I didn't see this question before.

Related

PyCharm Isn't Autocompleting OpenCV [duplicate]

I cannot get autocomplete working for OpenCV (Python) on Windows.
According to Abid's instructions here, I pasted the cv2.pyd file in the C:\Python27\Lib\site-packages.
In the Python code, I import as follows:
import cv2.cv as cv
I have also installed numpy, and it created its own folder in site-packages unlike OpenCV (which I've pasted directly into site-packages).
With this setup, the code executes without any problems, even when OpenCV methods are called.
But I have not been able to get autocomplete to work. I have tried to get it to work on Sublime Text 2 (with SublimeCodeIntel) and PyCharm. In both IDEs, autocomplete works for the numpy import, but fails for the OpenCV import.
I'm using OpenCV 2.4.6, and Python 2.7 (32 bit).
Any possible solutions?
The reason it's not working is because you're using a .pyd file, which is essentially the same as a compiled .dll. Autocomplete works by reading the source .py files, which are plain text. Try installing the OpenCV and Intel Math Kernel Library optimized NumPy packages from Christoph Gohlke's Python Extension Packages for Windows repository, which is frequently updated and a must-use resource for anyone who does any kind of scientific Python computing on Windows. Make sure you delete the cv2.pyd and numpy directories from site-packages first. These new packages will install the .py source files needed by the autocomplete engine in Sublime Text.
EDIT
OK, so I wrote the above because it worked well for a bunch of other packages. I'm a Python 3 guy, and I never installed OpenCV from Gohlke because it only has Python 2 bindings. After reading #CrazyCoder's comment below, I booted up Win7, and indeed he's absolutely correct (and I should have realized this before) - since OpenCV is written in C/C++, the only .py file included in the Gohlke package is cv.py, whose entire contents are as follows:
from cv2.cv import *
The rest is contained in cv2.pyd and a bunch of .dlls. The full OpenCV Windows distribution from opencv.org is a 291 MB download, which expands to 3 GB, and the few .py files in there are involved in building OpenCV, and aren't any good for autocomplete purposes. So, unfortunately, I don't know if there's a solution to your problem at the moment. Just keep the docs handy, and perhaps check out OpenCV Computer Vision with Python from Packt/O'Reilly, published in April 2013.
I've had the same issue with PyCharm when building a custom version of OpenCV on windows. Here is what I did to fix it:
OpenCV made a folder in Python site-packages like so:
opencv site-packages
So what you need to do is just add the python-3.9 folder to your interpreter.
File
Settings...
Python interpreter
Three dots icon next to your interpreter -> Show all...
Select your interpreter and click on the "Show paths for selected interpreter" icon
Add the folder inside the cv2 site-packages
Now import the cv2 module normally.
The best way to solve all the problems of OPENCV-PYTHON is by uninstalling it and reinstalling it.
Even I faced the same problem.
I fixed it by:
python -m pip uninstall Opencv-python
Then I reinstalled it by using a lower version. But unfortunately, I did not know the versions of opencv; So by using a small trick you can get it by running:
python -m pip install opencv-python==
and you will get an error similar to this:
ERROR: Could not find a version that satisfies the requirement opencv-python== (from versions: 3.4.0.14, 3.4.10.37, 3.4.11.39, 3.4.11.41, 3.4.11.43, 3.4.11.45, 3.4.13.47, 3.4.15.55, 3.4.16.57, 3.4.16.59, 3.4.17.61, 3.4.17.63, 4.3.0.38, 4.4.0.40, 4.4.0.42, 4.4.0.44, 4.4.0.46, 4.5.1.48, 4.5.3.56, 4.5.4.58, 4.5.4.60, 4.5.5.62, 4.5.5.64) ERROR: No matching distribution found for opencv-python==
Here you can see all the versions of opencv-python; choose any one (but not the latest as the error occurs due the latest version of opencv-python. install it by using:
pip install opencv-python==3.4.17.61 (You can choose your version, but this version solved the issue for me)
then enjoy your coding....
Even AUTO-COMPLETE error in opencv-python gets solved.
HAPPY CODING

Python not recognising libraries on Windows machine

I have been having a lot of trouble on my work Windows machine. I cannot get any libraries to work on my python. I use Thonny application for my python scripting.
I have tried setting environmental path to my current directory of python. On my PC its :
C:\Users\petrikas.lu\AppData\Local\Programs\Python\Python38-32\Scripts
Most tutorials say that it should be on C:\Python34\Scripts however thats not the case for my PC.
enter image description here
Python directory:
enter image description here
Can someone suggest me what shall I do next? I have tried many things that I have found online but my script wont compile. I am trying to import pandas library
After running a command:
python -m pip install pandas
It does not return any result. Most certainly did not generate a pandas library in my libs python folder
I would recommend setting up a Conda environment (using Anaconda or Miniconda) for your Windows machine. It's much easier to manage different environments which contain different sets of libraries.

Python: Where do I find packages like "gf" for the Anaconda Navigator and how do I install them? Python Version 3.6

this is my first question here;-)
I am using Python 3.6 via Anaconda Navigator (1.7) and that program shows a list of packages when I click Environments.
Are these packages directly useable or do I have to start any process therefor?
In a script I want to use the import-function for the package "gf", this one is not in the list above.
Where do I find it in a compatible form and how can I make it useable?
Anaconda says it has to be .yaml or .yml (Conda environment files) or .txt (Conda explicit specification files or pip requirement files)
I know the other way with the command line and WHL files, but Anaconda does not seem to have any command line as the kind-of-user-guide says.
First I tried renaming other install files to .txt, but Anaconda just took ages and got a serious problem that I had to restart it several times.
I also tried to check https://anaconda.org/conda-forge for "gf", but it seems not available there.
Best Regards
By GF, do you mean Grammatical Framework (https://www.grammaticalframework.org/)? If so, then you can't install it via Anaconda. Maybe you would be interested in one of the following options?
Jupyter kernel for GF
From https://github.com/kwarc/gf_kernel#readme:
gf_kernel is a Jupyter kernel for the Grammatical Framework (GF) . It allows you to write grammars and using them for parsing/translating/... all in one notebook, which makes it great for demos and teaching, but also for small experiments with GF.
You need to have GF installed: see https://www.grammaticalframework.org/download/index.html for options.
Using GF grammars from an external Python program
Python bindings to the PGF library are included in the GF binary, so if you have Mac or Ubuntu, the easiest way is to download the binary.
For other systems, see this blog post for how to install.

How do my python files get access to installed libraries (Pip)

Sorry in advance if this question has been asked before,
So after some time, I wanted to start a new python project. My previous computer (on which my python files were) died. I had saved my projects in my Dropbox. Now I installed python (3.8, there is also an anaconda installation, but it should not interfere with the python installation) on my new PC, and I cannot import any library to those files.
The python shell can find the imported packages (imported using pip), but even when I move the files to C:\Users\Username\AppData\Local\Programs\Python\Python38-32\Scripts (single user installation). It doesn't work.
I have tried uninstalling and re-installing pygame (in this example. Any library is unusable) using pip, pip3 and even pip3.8, I have added the .whl file by hand, it all didn't work. I have tried a virtual environment, but I can't get that to work either.
I run Windows 10 on a 64-bit computer.
first be sure you know which python installation you use with which import files etc.
you can copy your files not in scripts, but in lib somewhere in site-packages dir.
add your scripts to the python path! sys.path.add(.....) Otherwise python is blind and can't see them

Making pygtksourceview work in windows

So, I'm trying to get gtksourceview python bindings work under windows (I'm developing a cross platform gtk application that shows code, so gtksourceview seemed like a natural choice).
I have pygtk installed and working (I followed the instructions in http://www.pygtk.org/downloads.html)
I tried the instructions in http://projects.gnome.org/gtksourceview/ for gtksourceview.
Here is what I did:
Downloaded and extracted the latest gtksourceview window binaries from: http://ftp.gnome.org/pub/gnome/binaries/win32/gtksourceview/2.10/gtksourceview-2.10.0.zip
The website said gtksourceview needs libxml, so I downloaded and extracted the latest libxml window binaries from:
http://xmlsoft.org/sources/win32/libxml2-2.7.6.win32.zip
Added the folders containing dll files to the PATH (in my computer they were c:\opt\gtksourceview\bin; C:\opt\libxml2-2.7.6.win32\bin)
Installed pygtksourceview with the windows installer:
http://ftp.gnome.org/pub/gnome/binaries/win32/pygtksourceview/2.10/pygtksourceview-2.10.0.win32-py2.6.exe
Renamed the file libxml2.dll to libxml2-2.dll (after running depends on the gtksourceview dll)
Now, the gtksouceview widget seems to work, until I'm trying to set the code's language. When I do that python crashes.
Here is how I crash it in the console (the simplest way i could come up with):
>>>import gtksourceview2
>>>lang = gtksourceview2.language_manager_get_default().get_language('cpp')
>>>lang.get_style_ids()
I'm hoping I'm not the first person to use gtksourceview in python on windows. Any ideas what I should try?
So in case anyone else is wondering -- I grabbed the wrong libxml dll. The right one is in:
http://ftp.gnome.org/pub/GNOME/binaries/win32/dependencies/libxml2_2.7.7-1_win32.zip

Categories

Resources