Python with openCV on MAC crashes - eclipse

My final goal is to use Python scripts with SciPy, NumPy, Theano and openCV libraries to write code for a machine learning application. Everything worked so far apart from the openCV.
I am trying to install openCV 2.4.8 to use in Python projects in my Eclipse Kepler installation on my MBA running Mac OSX 10.9.2. I have the PyDef plugin v2.7 and a installation of Anaconda v1.9.1.
Here is what I did to install opencv:
sudo port selfupdate
sudo port upgrade outdated
sudo port install opencv
Then I realized that I can't use it that way in Python and did another:
sudo port install opencv +python27
Ok, then I had another Python installation and I added it to my PYTHONPATH in Eclipse>Preferences>PyDev>Interpreter-Python>Libraries.
Before the installation I got an error in the line import cv2, and everything else looked promising. Now this error disappeared but I get other errors when using any functions or variables of cv2. For example I get two errors in this line: cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
Also Python crashes and has to be restarted when I run a simple test program which worked fine before.
With this PYTHONPATH everything works but I have no openCV:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pyObjC
/Library/Python/2.7/site-packages/
/Users/xxx/anaconda/lib/python2.7/site-packages
When I add this new folder to the PYTHONPATH...
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
... openCV seems to work but I have the crashes and the other issue described above.
So, can anyone tell me what the problem is and what I can do to make this work?
Thanks for reading this so far and any help/hint you can provide! Please don't be too harsh, I am, as you can probably easily see just a beginner.

Ok, it's working now. Here is what I did:
Install Python and every package I need for it with Macports
Set the Macports version as standard
Adjust PATH and PYTHONPATH
Reboot (not sure if needed)
Remove old interpreter and libs in Eclipse
Choose the new Python installation as Interpreter in Eclipse
Confirm the new libs in Eclipse
Restart Eclipse
Done

Related

WinPython Spyder can't see spyder-kernels in virtual environment

I have installed WinPython and want to use Spyder. I use pip and virtual environments. I have followed the instructions here modular approach. Everything works just dandy until the very last instruction "Start a new IPython console (in Spyder). All packages installed in your venv environment should be available there.".
It get error Your Python environment or installation doesn't have the spyder‑kernels module or the right version of it installed (>= 1.9.0 and < 1.10.0). Without this module is not possible for Spyder to create a console for you.
But I installed spyder-kernals in my venv, I can literally see them there, I set the path the the python installed in the venv, everything should work, but it doesn't!
Any thoughts?
I asked CAM Gerlach as suggested, and he spotted my error very quickly. The instructions at modular approach are correct except they say pip install spyder-kernels==0.* which I took literally. In fact as per the error message you need to use later versions, so I used pip install spyder-kernels==1.10 and it fixed it.
You may have to ask to "C.A.M. Gerlach" if he has an update on the procedure: Spyder has evolved a bit with Spyder-4.

Python defaults to wrong version; can't find scipy

I am new to python, hoping to use it for scientific computation, data acquisition, etc. My ignorance is near total.
I am using a macbook pro, running OSX 10.9.5.
I first installed python 2.7, numpy, and matplotlib; can't remember where they came from. They seem to sit in /Library/Frameworks/Python.framework....
All was OK, until I realized I need scipy also. So, I installed the entire scipy stack from scipy.org, using 'sudo port install py27-numpy py27-scipy py27-matplotlib py27-ipython +notebook py27-pandas py27-sympy py27-nose', after having first installed xcode and the developer tools.
This new installation is located in \opt\local\var\macports\software...
Here's the question: When I run python in a terminal, it always defaults to the original installation. scipy, in particular, cannot be found. I suppose this is a path problem, but I am out of my depth here. Can someone help?

Symbol not found: _PQbackendPID with Django project

Running on MAC os 10.6.8
with postgresSQL installed, as well django - using python2.7
Also installed psycopg2 and dj-database-url using pip in my virtual env
And added these two lines to my setting.py:
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
Based on instructions for Heroku in:
https://devcenter.heroku.com/articles/django#database_settings
When running:
python manage.py runserver
I am getting this error:
ImportError: dlopen(/Users.... venv/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID
Referenced from: /Users.... venv/lib/python2.7/site-packages/psycopg2/_psycopg.so
Expected in: dynamic lookup
I kept searching for hours and tried all kind of thing including the advice on:
Mac OS X Lion Psycopg2: Symbol not found: _PQbackendPID
to no avail.
Wonder if anyone had such an issue and had any luck.
I had the same problem. Instead of installing the dependencies as Heroku suggests using
pip install Django psycopg2 dj-database-url
clone whatever repo you're hoping to run in venv, keeping its original settings.py. Then:
source venv/bin/activate
to activate the new environment, cd into your new repo, and python manage.py runserver. Should be set.
Alternatively, you could remake PostGreSQL, and run again, but that's a bit more of a task - it would work for psycopg2, though. As far as I can tell that issue comes from using an 64 or i386 build when you should be using a 32 build - but I'm not sure about this, and the above solution works well to solve the problem and use venv for what you're actually going to be using it for, most likely.
I had the same problem as you guys and I had read many pages and I couldn't find the answer in any of them. Many solution was about installing from source file and don't relate to the virtual environment.
I've found and tested following solution and it solve my problem.
1- Make sure your Postgres is NOT higher than 9.4 version according to psycopg2. Check python version as well. I use Postgres 3.9.9.
2- The problem is behind different version of Python(32/64 bit). It should comply with your operation system's bit architecture which is 64bit. Uninstall all versions of Python and pip from your system. Instruction you can find here but do NOT remove Python2.7 which is Apple-supplied system Python.
3- Install "Mac OS X 64-bit/32-bit" installer from python official website and install it.
After that install pip. Note that you should use the command "python3.5" for using Python version 3.5. You might install virtualenv from the new pip as well.
4- After all that you can go on your virtualenv and type "pip3 install -r requirement.txt" for installing all dependencies on your local machine.
Hope this can help you.

Installing Python Imaging Library on my iPhone's Python interpreter

I've been learning python for some time now. Recently I needed to install in my Mac the Image module for Python, and after a while I achieve this running a mpkg installer specially for my OS, so far everything was ok and I could run my script.
Now I'm in the needing of running my script in my jailbroken iPhone, which already has a python interpreter, and I need to install this Image module again but this time on my phone.
Is there another way to do it? How can I do it manually?
I found out how
I downloaded the PIL 1.1.7 source from http://www.pythonware.com/products/pil/ and untared the Imaging-1.1.7.tar.gz file, then I made the following commands:
cd Imaging-1.1.7/
python setup.py install
You can also follow the instructions on the README file in Imaging-1.1.7/ for building the package on your own.
that's it

How do I fix JavaHL (JNI) Not available after I have changed the logon password on my Mac?

I have installed Eclipse 3.5.2 and the plugin Subversion JavaHL Native Library Adapter 1.6.9.2 and this worked without any problems. However, this morning I was forced to change the password to logon to my Mac and since then I get the message that "Subversion native library not available" when I try to save any changes. Can anyone help? I have tried to add this line (-Djava.library.path=/usr/lib/jni) to the eclipse.ini file but this didn´t seem to make any difference.
Can anyone help?
Install MacPorts or HomeBrew, then run the following command:
For MacPorts, the commands to run are:
sudo port install subversion-javahlbindings +no_bdb +universal
For HomeBrew, the command is:
brew install --universal --java subversion
I was having a similar problem on Mac OS X Snow Leopard. I suspect your libraries are there but just need permissions changed, whereas I didn't have the libs at all.
The directory to check is /opt/subversion/lib, see if it has any libsvnjavahl files. In your case they may be there and just need new permissions.
To get the files I followed the the instructions they give for installing JavaHL on OS X, which is to download and install Open CollabNet. (login required, although it's free)
Then you just need to update your environment variable in .profile, something like:
export PATH=.:/opt/subversion/bin:$HOME/bin:$PATH
Then ran:
. .profile
Then I tested with javahltests.jar as mentioned here.
The easiest thing to do is download and install the OSX package that is provided on openCollabNet.
MacPorts also provides an easy Subversion and JavaHL package, however on Snow Leopard ?MacPorts is still compiling these packages as simple 32-bit binaries. If you use the default Snow Leopard JVM which is 64-bit you will get an error...
Failed to load JavaHL Library.
These are the errors that were encountered:
no libsvnjavahl-1 in java.library.path
no svnjavahl-1 in java.library.path
/opt/local/lib/libsvnjavahl-1.0.0.0.dylib: no suitable image found. Did find: /opt/local/lib/libsvnjavahl-1.0.0.0.dylib: mach-o, but wrong architecture
Note the error about wrong architecture. This is because the 64-bit JVM cannot load a 32-bit native library. The ?CollabNet binaries for OSX do not have this problem because they include both 32-bit and 64-bit versions.
Source: subclipse.tigris.org
Here is a blog entry that gives a solution:
http://blog.mattwoodward.com/getting-rid-of-subversion-native-library-not
I don't know whether this will work in your particular situation, but it's worth a try.
(Edited to fix link that became broken after I posted. The link became broken sometime between May 3 and June 1.)
In case you already have subversion installed I'd recommend performing first a brew uninstall and then the install again. And follow the steps to create the links indicated after the install concludes. This worked for me. Regards
I fixed it installing the SVNKit Client Adapter (not required) package.