Trouble using Javabridge with Python - python

I successfully installed javabridge using $pip3 install javabridge on my Mac's virtual environment. But when I tried to import javabridge in my python3 code, this is what I get:
import javabridge
Failed to run /usr/libexec/java_home, defaulting to best guess for Java
Traceback (most recent call last):
File "/Users/puifai/Documents/data_science/venv/venv3/lib/python3.6/site-packages/javabridge/locate.py", line 45, in find_javahome
os.path.join(os.path.dirname(path), "Libraries"),
File "/Users/puifai/Documents/data_science/venv/venv3/bin/../lib/python3.6/posixpath.py", line 92, in join
genericpath._check_arg_types('join', a, *p)
File "/Users/puifai/Documents/data_science/venv/venv3/bin/../lib/python3.6/genericpath.py", line 151, in _check_arg_types
raise TypeError("Can't mix strings and bytes in path components") from None
TypeError: Can't mix strings and bytes in path components
Any ideas on how to fix this? It looks like a problem with Python rather than javabridge?

Pardon the less-than-complete answer, but it has to do with the difference in strings between Python2 and Python3. Working in Python2.7 will at least get you around the problem for the moment. See this post for more background.

Related

No Python IDE will start and it will not start in the Command Prompt

When I click on my Python IDE's (IDEL, PyScripter) they will not even open. I tried typing python in the command prompt and this is what happened:
C:\>python
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.5\lib\site.py", line 548, in <module>
main()
File "C:\Python27\ArcGIS10.5\lib\site.py", line 537, in main
aliasmbcs()
File "C:\Python27\ArcGIS10.5\lib\site.py", line 469, in aliasmbcs
codecs.lookup(enc)
File "C:\Python27\ArcGIS10.5\lib\encodings\__init__.py", line 85, in search_function
norm_encoding = normalize_encoding(encoding)
File "C:\Python27\ArcGIS10.5\lib\encodings\__init__.py", line 57, in normalize_encoding`enter code here`
encoding = str(encoding, "ascii")
TypeError: str() takes at most 1 argument (2 given)
Did you recently install ArcGIS? It looks to me like ArcGIS installed a few libraries, and overwrote your site.py, but it's using code that's meant for Python3 rather than Python2.7. The str function is capable of taking in 2 arguments in Python3 but not in Python2.
To get your Python to work again, you could try deleting the entire ArcGIS10.5 directory from your computer (or temporarily moving it to your desktop and seeing if that helps). You can also try running python -S in Command Prompt to run Python without importing site.py.
To try to get ArcGIS working, you might be able to install Python3, and reinstall ArcGIS using that.
Hopefully that helps!

Base65536 in Python?

i've just installed base65536 in python, found Here
As a test to see if it works, i've made this script here:
import base65536
a = base65536.encode("Hello World")
print a
i'm using python2.7. When i run it, i get this error:
Traceback (most recent call last):
File "test.py", line 3, in <module>
a = base65536.encode("Hello World")
File "C:\Python27\lib\site-packages\base65536\core.py", line 118, in encode
stream.write(unichr(code_point))
ValueError: unichr() arg not in range(0x10000) (narrow Python build)
Any idea what to do here?
Python2 has two builds: one "narrow" and one "wide", depending on Unicode support. It looks like that library doesn't support the "narrow" build. You should install a "wide" build or hope the library gets updated. It looks like someone filed an issue on it: https://github.com/Parkayun/base65536/issues/4
Or you can use a recent version of Python3, which doesn't have this problem.

PIL with Centos 7 and Python 3.4

Does anyone have a working implementation of PIL with Centos 7 and Python 3.4?
I tried to install the tarball from here, but when running "make" or "make test" got a lot of errors.
If anyone has a working implementation, could you please post the commands and configuration needed i.e. yum packages to get it to work?
I also found this blog post but it didn't help.
Here is one error that I am seeing when trying to convert a jpeg's size:
Traceback (most recent call last):
File "<console>", line 2, in <module>
File "/var/www/deploy/myproject/myproject-django/venv/lib/python3.4/site-packages/PIL/Image.py", line 1557, in resize
self.load()
File "/var/www/deploy/myproject/myproject-django/venv/lib/python3.4/site-packages/PIL/ImageFile.py", line 203, in load
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File "/var/www/deploy/myproject/myproject-django/venv/lib/python3.4/site-packages/PIL/Image.py", line 420, in _getdecoder
raise IOError("decoder %s not available" % decoder_name)
OSError: decoder jpeg not available
Make sure you install the dependencies first, and then reinstall Pillow. Looks like you're missing libjpeg. See here for details.
http://pillow.readthedocs.org/en/3.0.x/installation.html

Installing Scipy Error in Windows 7

In a round about way, I corrupted my scipy/numpy installation on my IntelX64/Windows 7/Python 2.7 computer. I did this by trying to play around with some neural network libraries (lasagne/theano).
To fix this, I completely removed/reinstalled python 2.7.9. After that, I went to http://www.lfd.uci.edu/~gohlke/pythonlibs/ to download and install numpy and scipy with commands:
pip install C:\Users\me\Documents\numpy-1.9.2+mkl-cp27-none-win_amd64.whl
This went well and succeeded. (I can import numpy from python)
pip install C:\Users\me\Documents\scipy-0.15.1-cp27-none-win_amd64.whl
This appeared to go well too. Except the error occurs in the python console:
>>> from scipy import stats
Gives:
Traceback (most recent call last):
File "<stdin>", line1, in <module>
File "C:\Python27\lib\site-packages\scipy\stats\__init__.py", line 338, in <module>
from .stats import *
File "C:\Python27\lib\site-packages\scipy\stats\stats.py", line 184, in <module>
import scipy.special as special
File "C:\Python27\lib\site-packages\scipy\special\__init__.py", line 586, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
I read up on the DLLs required and ran the 'dependency walker' (http://www.dependencywalker.com/) on "c:\python27\lib\site-packages\scipy\special_UFUNCS.PYD" and it seems there are a few DLL files not found.
libifcoremd.dll
libiomp5md.dll
libmmd.dll
msvcr90.dll
dcomp.dll
ieshims.dll
and a 6 files that look like 'api-ms-win-....dll'
From my looking around, people have solved this by reinstalling numpy, then scipy. I have tried that and the same thing occurs.
Has anyone else run into this issue and solved it?
I fixed this by a complete removal of everything (python and packages) and then installing everything again.
Just reinstalling the offending packages did not work. Neither did system restore. I will not accept this answer, because removing/installing is a work around to the real problem. I just want to post this to help anyone else in this position.
Simply install 'NumPy-1.9+MKL' from this page, it should work fine.
Acknowledgement: Another post here :)

Python - Zero length field name in format

I'm using Python on my Centos machine and when I try to run my program I have this error displayed :
Running setup.py egg_info for package pyepr
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/tmp/pip-build-root/pyepr/setup.py", line 68, in <module>
print('using EPR C API sources at "{}"'.format(eprsrcdir))
ValueError: zero length field name in format
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/tmp/pip-build-root/pyepr/setup.py", line 68, in <module>
print('using EPR C API sources at "{}"'.format(eprsrcdir))
ValueError: zero length field name in format
I have already checked the other questions about this subject and I already installed Python 2.7.6 and set it as my default configuration as shown below....
$ python -V
Python 2.7.6
Something must have gone wrong, but I don't know what.
Anybody has an idea?
Thanks
That error can only be raised if you run that code with Python 2.6 or older. In those versions, you must explicitly number the format fields for str.format (starting at 0):
print('using EPR C API sources at "{0}"'.format(eprsrcdir))
Of course, this is only a temporary fix. It would be better to investigate why your code is not being run with Python 2.7 in the first place and then fix that instead.
If you run an install using sudo, you are going to end up using the sudo path's Python interpreter. Not sure if you are using sudo or not for installing, but there is a good chance you are.

Categories