jpype startJVM crashes ipython notebook - python-2.7

I'm trying to use JPype within ipython notebook in order to use JIDT (I don't know Java). I'm following the instructions here: https://code.google.com/p/information-dynamics-toolkit/wiki/PythonExamples.
I import jpype and start the java virtual machine with:
from jpype import *
startJVM(getDefaultJVMPath())
This makes the ipython notebook kernel crash due to the following error:
python(490,0x7fff7a99e310) malloc: *** error for object 0x104d90720: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
However, it works fine in the ipython shell.
How can I know where the error comes from and how can I fix it?
I use:
OSX 10.9.5
Python 2.7.10,Anaconda 2.2.0,IPython 3.1.0
Any help will be greatly appreciated.

I think it has to do with the C compiler used to install JPype. Try setting C compiler to clang and install JPype like this:
$env CC=clang python setup.py install

Related

Import Error with certain modules in pyoptsparse

Hello everyone,
I have installed Openmdao, pyOpt and pyoptsparse on my computer. As my program works with the Scipy optimizer, I tried it with a random optimizer of pyoptsparse (that was 'ALPSO'). It worked and I was happy. But it turns out it seems to be the only one working.
Every time I try to use another one (like 'SLSQP', which is the default optimizer !), i get this message "pyOptSparse Error : There was an error importing the compiled SLSQP module", inside a frame made of '-' and '+'.
Does anybody know what to do ? I am using Ubuntu if it changes something.
Thanks to swryan for the link, i found the answer.
One of the possible answer was to put libgfortran.so.3 in anaconda2/lib, but i already had it.
They were also saying the problem was solved when installing anaconda 4.0+ but i also had the latest version.
What worked for me was to run : conda update libgfortran --force
Doing it without the --force retrogrades the scipy, which seems to disable scipy.optimize.least_squares. If you did that, you can then run conda update scipy --force
Did you get any errors when you ran 'python setup.py install' for pyoptsparse? I looked at the setup.py file for pyoptsparse and there are some instructions in there that you could try:
print("\nTo install, run: python setup.py install --user\n\n"
"To build, run: python setup.py build_ext --inplace\n\n"
"For help on C-compiler options run: python setup.py build --help-compiler\n\n"
"For help on Fortran-compiler options run: python setup.py build --help-fcompiler\n\n"
"To specify a Fortran compiler to use run: python setup.py install --user --fcompiler=<fcompiler name>\n\n"
"For further help run: python setup.py build --help"
)

rpy2 on pycharm generates segmentation fault error

I am using (osx) pycharm as ide and anaconda as python (2.7.10) distribution.
Recently I have installed rpy2 which works quite well on notebook e.g.
In [5]:import rpy2.robjects as robjects
In [7]:robjects.r.pi[0]
Out[7]:3.141592653589793
But on pycharm I get a segmentation fault error.
import rpy2.robjects as robjects
/Users/xxx/anaconda/envs/analytics3/bin/python.app: line 3: 695 Segmentation fault: 11 /Users/xxx/anaconda/envs/analytics3/python.app/Contents/MacOS/python "$#"
PYcharm support claims that this is a bug in the code.
any ideas what that might be?
many thanks
Reinstalling rpy2 from
conda install -c conda.anaconda.org/rpy2
solved the issue.
If you install rpy2 via conda, and also have a system installation of R on the same machine (e.g with RStudio), the system's R installation will be used. Since this R version doesn't match the one that rpy2 needs, segmentation faults occur.
1) remove any existing system installations of R (see here). Verify that you don't have any installations of R:
$>which R
R not found
2) define R_HOME env variable, either in your .rc file:
export R_HOME=/Users/<your user>/anaconda3/envs/<env name>/lib/R
or dynamically in the python project:
import os
os.environ['R_HOME'] = '/Users/<your user>/anaconda3/envs/<env name>/lib/R'

Error importing theano "cannot import name gof"

I am current getting the error
ImportError: cannot import name gof
when importing theano.
>>> import theano
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import theano
File "C:\Python27\lib\site-packages\theano\__init__.py", line 63, in <module>
from theano.compile import (
File "C:\Python27\lib\site-packages\theano\compile\__init__.py", line 9, in <module>
from theano.compile.function_module import *
File "C:\Python27\lib\site-packages\theano\compile\function_module.py", line 16, in <module>
from theano import gof
ImportError: cannot import name gof
I am using python 2.7.10 (). Theano is installed using pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git.
Hope to get you suggestion to solve this problem
Most of the time, when I see this error, it is caused by those 2 errors:
1) A syntax error in Theano. Update Theano and make sure to have no local modifcation. I nerver saw this error in the master of Theano, but just in case.
2) When there is multiple version of Theano that are installed.
In both case, remove all version of Theano. Do it multiple time to be sure there is none left. Then install again.
From memory, this always solved the problem when it wasn't a syntax error during development (but not in the master version of Theano that you use)
This ImportError can be caused because Theano is unable to compile the gof module itself. If this is the case, you will see an error message that looks like "Exception: Compilation Failed (return status=1): C:\Long\Path\...\mod.cpp:1: sorry, unimplemented: 64-bit mode not compiled in".
Fixing With Conda
If you are installing theano into a conda environment, make sure that you have a C compiler available to that environment.
The command
conda install m2w64-toolchain
will provide a C compiler to your environment that's isolated from the rest of the machine.
After the m2w64-toolchain package is installed, import theano should work
Fixing Manually
If you are installing Theano yourself, two points from these threads may help:
Install the bleeding edge version of Theano
Install libpython from http://www.lfd.uci.edu/%7Egohlke/pythonlibs/
I assume you're using Windows 7 or later.
If you have installed Python Anaconda, then open Windows Powershell or Command Prompt and type conda install mingw libpython before typing pip install theano
Alternatively, if you don't have Anaconda, download those packages from
anaconda.org/anaconda/mingw/files
anaconda.org/anaconda/libpython/files
github.com/Theano/Theano
Then open Command Prompt, navigate to each folder and type python setup.py install
Now run Python and import theano
Possible errors:
If you get the RuntimeError: "To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environement" then
Go to Control Panel > System > Advanced system settings and select "Environment Variables".
In the "System variables" section, make a new variable name MKL_THREADING_LAYER and set its value to GPU
If you get other kinds of errors, then try the following:
Make an empty file called .theanorc (a file extension without a file name) in your home folder C:\Users\<username>. If you get the error "You must type a file name" then see stackoverflow.com/q/5004633
Open .theanorc and write this:
[global]
cxx=C:\<path to Anaconda>\Anaconda3\MinGW\bin\g++.exe
Run Python again and import theano. If it works, then you can probably delete .theanorc
In my case, the fix was to install a python build that's callable as a shared library:
PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 2.7.15

mvpa2.suite: Runtime warning and erro in Python 2.7.6

I just installed mvpa2 module on my ubuntu 14.04, Python 2.7.6. following the instruction at http://www.pymvpa.org/installation.html using sudo aptitude install python-mvpa2
Command import mvpa2 works well, but when I run from mvpa2.suite import * , I get the followin warning in my terminal:
/usr/local/lib/python2.7/dist-packages/sklearn/pls.py:7: DeprecationWarning: This module has been moved to cross_decomposition and will be removed in 0.16
"removed in 0.16", DeprecationWarning)
And also fallowing error:
TypeError: __init__() got an unexpected keyword argument 'rho'
Appreciate your help!
actually this warning comes from the import done by mdp, which PyMVPA optionally uses... you can safely ignore it (no upgrade of PyMVPA would help anyhow), because even if it gets completely removed, then mdp would simply skip that import and you would remain 'golden'.
That problem is due to an incompatibility of the python-mvpa2 and scikit-learn versions. You can check more details on that in this page, because depends on which scikit-learn version you have what will be the parameters to call a given function.
A short solution is to uninstall your python-mvpa2 and scikit-learn, and install them directly from their github repos:
[python-mvpa2] https://github.com/PyMVPA
[scikit-learn] https://github.com/scikit-learn/scikit-learn
I just did it and now the example doc/examples/som.py (for my case) is working perfectly.

WinPdb Error (Debugging Django) :CTimeoutHTTP instance has no attribute 'getresponse'

I am trying to learn winpdb to debug django scripts. I have a very simply django web site that runs find if I start it from the command line, but when I try to launch it from winpdb it gives me this error message:
RPDB2 - The Remote Python Debugger, version RPDB_2_4_6,
Copyright (C) 2005-2009 Nir Aides.
Type "help", "copyright", "license", "credits" for more information.
*** NEW: Use CTRL-N for auto completion in the following commands: launch,
*** eval and exec.
*** Password has been set to a random password.
*** Starting debuggee...
*** Command returned the following error:
*** <type 'exceptions.AttributeError'>, CTimeoutHTTP instance has no
*** attribute 'getresponse'.
*** Please check stderr for stack trace and report to support.
*** Failed to find script.
I don't even know where to start fixing this. It CTimeoutHTTP looks like an MFC thing. I installed wxpython with the ANSI version, then when it complained, I installed the unicode version (without removing the ANSI version.) That is the only unusual thing I can think of. Any help would be appreciated.
I should say, running on Windows XP.
Fixed in Winpdb 1.4.8
This seems to be a bug with rpdb2 in Python 2.7. Try downloading Python 2.6 and running winpdb against that. You'll need the appropriate wxPython library and you'll need to re-run:
python setup.py install -f
to install winpdb.
I also had this exact same error. I upgraded from Winpdb 1.4.6 to 1.4.8 as suggested by nir above and no longer see it (can't vote his answer up as I'm a new user).