Search code examples
pythondjangopyjnius

pyjnius not working in virtual environment


I am working with pyjnius in django. I am not able to import it as a module so i am using it like this

os.system("python  home/pyjnius/jnius/run_me.py " + path)

that works normally but in virtual environment it gives error

Traceback (most recent call last):
File "run_me.py", line 11, in <module>
from jnius import autoclass
ImportError: No module named jnius

this is the code i am follwing

please can anyone point some direction here as how to use pyjnius in virtual environment or where i am making mistakes.

in run_me.py this is the code

import os
os.environ['JAVA_HOME'] = '/usr/lib/jvm/java-7-openjdk-amd64/'
os.environ['CLASSPATH'] = "/path/to/tika-app.jar"

from jnius import autoclass

## Import the Java classes we are going to need
Tika = autoclass('org.apache.tika.Tika')
Metadata = autoclass('org.apache.tika.metadata.Metadata')
FileInputStream = autoclass('java.io.FileInputStream')

tika = Tika()
meta = Metadata()
text = tika.parseToString(FileInputStream(filename), meta)

thankyou


Solution

  • I had some trouble getting this to work as well.

    The following worked for me:

    Create a new virtualenv, just in case, and activate it.

    # install pyjnius
    pip install cython
    cd [virtualenv]/src/
    git clone https://github.com/kivy/pyjnius.git
    cd pyjnius
    python setup.py install
    
    # get the tika-app (don't know if this is the latest version)
    wget http://apache.proserve.nl/tika/tika-app-1.5.jar
    mv tika-app-1.5.jar /usr/local/lib/
    
    # put the following in .bashrc
    export CLASSPATH=$CLASSPATH:/usr/local/lib/tika-app-1.5.jar