I would like to install OpenCV with Python support on my Raspberry Pi for multiple versions of Python.
I am using the instructions at http://docs.opencv.org/3.1.0/d7/d9f/tutorial_Linux_install.html. When OpenCV builds, it automatically targets python 3.4. That is OK, but I would also like to also add support to Python 2.7.
I have seen instructions that utilize virtual environments (http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/), but don't want to use virtual environments.
How can I tell the OpenCV build / install to target specific or multiple versions of Python without using virtual environments? I assume there is a way to instruct CMake on what to build, but I know very little about how to use CMake.
I'm not sure if CMake has to do with this, but I first I installed Python 2.7
sudo apt-get install python2.7-dev
Then I targetted python 2 to the virtual environment I made
mkvirtualenv cv -p python2
Afterwards, I checked and verified if it worked
ls -l /usr/local/lib/python2.7/site-packages/
It should display something like this after:
total 1852
-rw-r--r-- 1 root staff 1895772 Mar 20 20:00 cv2.so
Link to the guide I used: http://www.pyimagesearch.com/2016/04/18/install-guide-raspberry-pi-3-raspbian-jessie-opencv-3/
Related
I am facing this error when I start my flask application on Python3 and Mac OS:
OSError: cannot load library 'gobject-2.0-0': dlopen(gobject-2.0-0, 2): image not found. Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0-0'
I am using weasyprint in my project which is causing this issue.
I tried to install glib and it is installed in my system.
I just managed the same issue on my Mac M1.
The problem was that symlinks to the libraries were not created (can't say should it be done by homebrew or weasyprint when installation).
So, I had to do it manually
sudo ln -s /opt/homebrew/opt/glib/lib/libgobject-2.0.0.dylib /usr/local/lib/gobject-2.0
sudo ln -s /opt/homebrew/opt/pango/lib/libpango-1.0.dylib /usr/local/lib/pango-1.0
sudo ln -s /opt/homebrew/opt/harfbuzz/lib/libharfbuzz.dylib /usr/local/lib/harfbuzz
sudo ln -s /opt/homebrew/opt/fontconfig/lib/libfontconfig.1.dylib /usr/local/lib/fontconfig-1
sudo ln -s /opt/homebrew/opt/pango/lib/libpangoft2-1.0.dylib /usr/local/lib/pangoft2-1.0
This solved the problem.
In order to TEST if Python can find the library you may run
from ctypes.util import find_library
find_library('gobject-2.0') # Pass any other lib name as an argument
UPD. There is no such problem if you install python with homebrew.
If you installed weasyprint package in your virtual env but did not installed some required packages for that, then that might be the reason. It was actually, in my case.
If you're mac user you need install pango and libffi, not to mention python as well.
Installation guide on mac
brew install python pango libffi
(venv) pip install weasyprint
To expand on the existing answers on Apple Silicon (M1) Macs:
If you have installed the packages with Homebrew and they are still not found or linked under /usr/local/lib, it is because they are installed on arm64 and found in /opt/homebrew/lib instead.
If you're using Python installed with Homebrew it should work without any extra work, however system Python and any managed Python versions (e.g. installed with Pyenv) will require some configuration.
1. Manual symlinking
Instead of linking each library individually to /usr/local/lib, you can link the /opt/homebrew/lib contents (as long as you don't have an existing /usr/local/lib directory):
sudo ln -s /opt/homebrew/lib /usr/local/lib
This will work as long as the library you're looking for is not from a keg-only formula (those will have to be linked individually).
2. Environment variables
A lot of answers point to setting some environment variable, like LDFLAGS or DYLD_LIBRARY_PATH to add search paths for libraries, but these will not work with Python based on my testing:
macOS comes with System Integrity Protection (SIP) which, among other things, sanitizes your environment variables in subprocesses, for example Python. Anything starting with LD or DYLD will be purged, so setting the environment variables in your terminal profile will not work.
You can Disable SIP to get these working, but Apple recommends only doing it temporarily when needed.
If you decide to go this route, here are a few options:
In Homebrew's Github discussions the question was answered by setting LDFLAGS:
export LDFLAGS=-L/opt/homebrew/lib
Similarly you could add the necessary paths to DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=/opt/homebrew/lib
I had the same issue after the homebrew update. Turned out the issue was because of the older pango lib version.
I did brew install pango
This upgraded pango lib from 1.48.2 -> 1.50.4 which internally installed gobject's latest version as dep. And my issue got resolved.
While setting up supervisor on an Ubuntu machine via apt-get install supervisor, I noticed it setting up python2.7 as part of the installation.
I have 2 questions -
Why supervisor 3.3.1 which is relatively very new still using
python2.7? The old version was not present on my system till apt-get
installed it as a sub-dependency.
What can I do to have supervisor depend on python3.x?
Supervisor currently does not support Python 3. See the platform requirements:
Supervisor is known to work with Python 2.4 or later but will not work under any version of Python 3.
I want to set up a Ubuntu VM with Python 3. All the resources I've seen so far want me to use virtualenv but I don't see the point since I only want one Python (I don't care about 2.7 in other words).
Is there a way to do this where I can just ssh into the VM and my environment is all set up for me?
There are no Ubuntu releases that default to Python 3. Maybe in the future, but as of right now, you will have to workaround the fact that Ubuntu ships with Python 2 as the default, Python 3 is available.
So pick a release of Ubuntu that you like, and then:
Upgrade the system (sudo apt update; sudo apt upgrade -y)
Install the build toolchain (sudo apt install build-essential -y)
Install Python3 (sudo apt install python3 python3-dev -y)
Switch your user to Python3 as the default; I would recommend using pyenv for this.
Once you do this, then for your user Python will default to Python 3, but for other system utilities, Python 2 will still be available.
It might just be easier to use the default Python docker image since its allows you to easily switch versions (it is based on debian).
A friend and I are interested in training the tesseract-OCR engine for a CV project. We tried using some wrappers such as PyTesser and pyocr, but the results are currently not as accurate as we need them to be. As such, we want to try training the tesseract to perform better for our purposes (i.e. identifying text on food labels), but are having some trouble installing the training tools.
What we've tried:
Looking on the google code website, the 'Compiling' page on the tesseract's google code wiki says the training tools are only available on version 3.03. However, the google code 'Downloads' page for tesseract-ocr only has the materials for 3.02. The bottom of the 'Compiling' page also has some comments about installing version 3.03 on Windows and OSX, but no comments yet for Linux users.
There also appears to be some sort of 3.03 source package for Ubuntu but we're not sure how to access it on our computers and the 'Compiling' page says we need to run these commands:
make training
sudo make training-install
We've also found a google group thread about tesseract 3.03 but again it seems like these posts do not include advice for Linux users (unless we missed something during the initial read).
Is this actually a really simple command-line install problem? Or, is there a way train tesseract with 3.02 (which we currently have installed)? Have we been looking at the wrong places for information?
Any advice or links to instructions for installing tesseract-ocr 3.03 for Linux distributions would be greatly appreciated! Thanks.
Tesseract can directly be installed in Ubuntu 14.04 using
sudo apt-get install tesseract-ocr
I don't have any idea if you can do it in older version of Ubuntu because the repo might be updated in later version of Ubuntu.
I had an aws ubuntu 14.04 instance.
when I tried installing Tesseract with
sudo apt-get install tesseract-ocr
It retuned package not found
But this worked for me.
sudo apt-get update
sudo apt-get install tesseract-ocr
Ubuntu is a debian based Linux distribution. The tesseract package you find will most likely be a debian package which will contain tesseract and the required default language files to allow you to run/train tesseract. You do NOT want the source package -- unless you just want to compile it yourself -- no need. You will not have to build tesseract, you just need to install the package. First, it appears you are new to Ubuntu, so please ready InstallingSoftware. It can be as easy as opening up an x-term and issuing the command apt-get install tesseract-pkgname (note: that means whatever the package name is).
There is no shortcut, take the time to understand whether you have a .deb package on your box that need to be installed or whether you are installing from a remote repository. The link above explains how to handle both.
Here is a specific Ubuntu thread dealing with installing tesseract Tesseract 3.0 + Ubuntu 10.04 Installation Guide Hope that helps. Tesseract is very good software.
I don't have any instructions for building Tesseract 3.03 for Linux specifically (I'm on Mac), but here's a link to download the source code for the 3.03 release candidate: https://tesseract-ocr.googlecode.com/archive/3.03-rc1.tar.gz
First run below command
sudo apt-get install tesseract-ocr
It will install tesseract version 3.04
Run below to update the tesseract
sudo apt-get --only-upgrade install tesseract-ocr
It will update tesseract to 4.1.3
I'm currently migrating to new computer and I need to reinstall the software I am using which are:
Python 3.3,
Lighttpd (newest version),
Pymongo (newest version),
Ubuntu 12.04 Desktop (The System I'm using)
I started to install Python 3.3 by downloading it from the its official website (in tar.bz2 file) and by following this tutorial. Afterwards I installed Lighttpd and changed the lighttpd.conf for Python by following this tutorial, too.
I tried several paths for my cgi.assign, none of them worked. Especially /opt/python3.3/bin/python3.3 should be working, but it shows 500 - internal Server error all the time with a "hello world" test script.
Now regardless to this problem I have no clue on installing Pymongo. If I try to intall pip OR easy_install python3.3 I have to manually download it and execute the setup.py with my python3.3 executable, right? Because this always fails with an error:
`Error missing zlib on a bundle called distribute-0.7.3 (is this even the right tool I need, because it seems to be a legacy wrapper !?) or unknown url type: https for pymongo2.6.2 itself.`
I'm getting crazy with this setup. Why is this so difficult to handle? Other programs are just a few clicks to install even on a system like Ubuntu, but these particular development tools seem to be really difficult to install.If anybody has an idea on how to install all three together or has information on a better solution please help me out.
The system is used to program Python scripts in Eclipse and trying them out directly on the system (lighttpd). The database used is MongoDB. Python and MongoDB are communicating over the Pymongo driver. I am planning to use the system on a Server distribution on release and it has to be nicely scalable on a high amount of excecutions.
Thanks for your time,
It's easiest to use the Ubuntu repositories:
sudo apt-get update
sudo apt-get install python3 python3-pip lightppd python-pymongo
Or if that only installs the python2.x pymongo, use pip, which you've just installed:
sudo pip-3.3 install pymongo
Or better yet, use a virtualenv with the help of virtualenvwrapper (docs)
sudo pip install virtualenvwrapper
... # follow instructions for installing virtualenvwrapper
mkvirtualenv --python=/usr/bin/python3 -i pymongo mongoppd
workon mongoppd
... which will segregate the environment I've called 'mongoppd' from the rest of your system so you can't cause any trouble. Then you don't need sudo to pip-3.3 install things, just workon mongoppd then pip-3.3 install [...]. Or after the -i flag when you create the virtualenv to get it installed straight away.
In general, on Ubuntu, you should hardly ever have to install something manually. Your first attempt should be using sudo apt-get install (use tab-complete to see what's available or just google "ubuntu 12.04 packages [...]" and you'll find the list of packages). Then for python use pip install or pip-3.3 install as appropriate. You'll only need to run python setup.py install if you need to install a development version of a package or something obscure that's not on pip. I don't think there's a good reason to ever use easy_install these days.