Cannot install python-weka-wrapper/javabridge on Google Colab - python

I am trying to install the python-weka-wrapper on Google Colab using
!pip install python-weka-wrapper
And I am seeing the following output:
Collecting python-weka-wrapper
Using cached https://files.pythonhosted.org/packages/2a/41/19c7bc2e177371cc273cc8aa17d66bd3ef9a6192160eecc56566ea31d959/python-weka-wrapper-0.3.15.tar.gz
Collecting javabridge>=1.0.14 (from python-weka-wrapper)
Using cached https://files.pythonhosted.org/packages/a6/a0/c59bccabed99b1d4ac68166c59c679b375bfca75b78688b52c541b711578/javabridge-1.0.18.tar.gz
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-24j9c0j5/javabridge/
I have successfully checked/installed all Python packages needed:
numpy
pillow
matplotlib
pygraphviz

I faced exactly the same error. Error is due to javabridge (a dependency) installation failing. In my case the error was due to the fact that I did not have JDK installed on my Google Colab Runtime.
Note: Even though JDK folders might be present in your machine (and similarly in Google Colab), doesn't necessarily mean that javac is present or works. Usually most machines have JRE running even though the JDK folders might seem to be present in the /usr/lib/jvm/ directory. That's what confounded me for a long time. So you have to apt install openjdk .
So, after installing openjdk properly and setting the JAVA_HOME properly, javabridge and python-weka-wrapper3 smoothly installed.
I'm summarizing all the commands I used to install python-weka-wrapper3 on Google Colab
import os
import sys
sys.path
sys.path.append("/usr/lib/jvm/java-11-openjdk-amd64/bin/")
os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-11-openjdk-amd64/"
!apt-get install build-essential python3-dev
!apt-get install python3-pil python3-pygraphviz
!apt install openjdk-11-jdk
!pip3 install javabridge --no-cache-dir
!pip3 install python-weka-wrapper3 --no-cache-dir
import weka.core.jvm as jvm
jvm.start()
So, I hope this helps! Feel free to ask me any more questions related to this.
Also note while trying to rectify the issue, I came across some posts stating Oracle JDK might be necessary. Complete nonsense. weka-wrapper3 works just fine with openjdk.
The comments from this question helped me in understand the issue to resolve the error when I faced it.

Related

Meeting a pip requirement using an alternative module

I'm trying to install a python module, 'pyAudioProcessing' (https://github.com/jsingh811/pyAudioProcessing) on my Linux Mint distribution, and one of the items in requirements.txt is causing issues: python-magic-bin==0.4.14. When I run pip3 install -e pyAudioInstaller, I get an error:
ERROR: Could not find a version that satisfies the requirement python-magic-bin==0.4.14 (from pyAudioProcessing==1.1.5) (from versions: none)
ERROR: No matching distribution found for python-magic-bin==0.4.14 (from pyAudioProcessing==1.1.5)
The same error appears if I try to manually install the module using pip3 install python-magic-bin. The module installs without issues on my windows machine.
pypi.org lets me download files for it manually, however only Windows and MacOS .whl files are available. I tried simply removing the requirement from the list, but that resulted in a large number of other errors to appear, so I assume the module is legitimately required.
Thee is another module called python-magic-debian-bin that I can download. Is there a simple way to convince pyAudioInstaller to use this other module instead of the original? Like can I somehow rename python-magic-debian-bin to python-magic-bin and hope it works out?
python-magic-bin 0.4.14 provides wheels for OSX, w32 and w64, but not for Linux. And there is no source code at PyPI.
You need to install it from github:
pip install git+https://github.com/julian-r/python-magic.git
As for pyAudioProcessing I can see 2 ways to install it:
Clone the repository and edit requirements/requirements.txt, replace python-magic-bin==0.4.14 with pip install git+https://github.com/julian-r/python-magic.git#egg=python-magic;
Install requirements manually and then install pyAudioProcessing without dependencies:
pip install --no-deps pyAudioProcessing
or
pip install --no-deps git+https://github.com/jsingh811/pyAudioProcessing.git
The library has updated the requirements very recently for it to work on Linux.
pip install -U pyAudioProcessing
Should get it all set up for you.
Alternatively, https://github.com/jsingh811/pyAudioProcessing the readme describes other getting started methods as well.

Pip installing wrong version on win7,

I have a package that I am trying to install via pip install allen-bradley-toolkit. The package is failing with the following reason.
The problem seems to related to the fact that pip is trying to install 1.0a1.post0 instead of the latest release version 2.0.0. Does anyone have any ideas on what to do about this. Perhaps there is something wrong in my deployment script. You can view the Github Library here to see how I am deploying to PyPi.
There is an issue opened on the GitHub Tracker #2 that you can also reference for more info.
NOTE: The package seems to install fine on my win10 machine. But I am unable to get it to install on a win7 VM.
Ive also tried installing with the following commands:
pip install --no-cache-dir allen-bradley-toolkit
pip install allen-bradley-toolkit==2.0.0 -> this ones throws a 'doesnt exist error`
At https://pypi.python.org/pypi/allen-bradley-toolkit/2.0.0 I see that the wheel is only available for Python 3. You're trying to install it with Python 2.7.
To publish a universal wheel (suitable for both Py2 and Py3) you need to set
[bdist_wheel]
universal = 1
in setup.cfg or run
python setup.py bdist_wheel --universal
The 2nd line of the output has a clue to the problem - "Using cached ..."
You can skip the cache using the --skip-cache --no-cache-dir option to pip install or request an upgrade using the -U option
edit: updated comment with the correct option (although, seems like that wasn't the problem in this specific case).

Cannot build wheel error when trying to install openAI gym

I saw that failure to build wheel atari-py, pachi-py was a common problem people ran into when installing openai gym in mac. And the solutions suggested in them was to use export commands export MACOSX_DEPLOYMENT_TARGET=10.11
export SDKROOT=/path/to/Mac10.11SDK before making the build. I tried the given suggestions and yet I am finding the same error when trying to install full openai gym. Can anyone help me in getting around this issue ?
verify if you already installed cmake, if not you can do it with:
$ brew install cmake
and later you can install atari-py:
$ pip install atari-py
Reference in oficial GitHub repo

pycrypto installation: configure error: cannot run C compiled programs

Please be gentle on me. I have searched the site, and I know there is another answer to this exact question, but the answers posted there aren't working for me.
I am trying to install pycrypto, so that I can get paramiko to work. Paramiko is failing because of a missing pycrypto module. I have tried using pip install pycrypto which succeeds, but does not cure the problem.
I have tried installing a binary version of pycrypto and that doesn't solve the problem.
Now I am trying to build pycrypto. I have cygwin64 and mingw installed on my machine. The approach that gets the farthest is
python setup.py build --compiler=mingw32
This gets to an error,
checking whether we are cross compiling... configure: error: in `/cygdrive/c/Python27/pycrypto-2.6.1':
configure: error: cannot run C compiled programs.
The other answer suggests removing spaces in the path. I have tried reducing the path to simply
c:\mingw;c:\python2.7;c:\cygwin64\bin
with no change to the result?
Does anyone have a fix they can point me to? Thank you. The overall goal is to get paramiko to work. The paramiko error is
ImportError: No module named Crypto.PublicKey
In my case, the /tmp mount point was mounted with the noexec flag.
For windows with cygwin, I would check the mount point too, as well as dependencies such as the vcredist packages required for python2 and python3, see also Errors while building/installing C module for Python 2.7.
Two solutions for linux:
remount temporarily with the exec flag (very likely requires root/sudo permissions)
e.g.:
sudo mount -o remount,rw,exec /tmp
change the build path to a local mount point
e.g.:
mkdir -p ~/python/tmp
pip install --build ~/python/tmp pycrypto
Note: it's worth looking at the other answers:
verify autoconf and python2-dev or python3-dev packages are installed.
I had a similar problem:
pip install --upgrade subprocess32
failed with
configure: error: cannot run C compiled programs
on aws after our admins tightened the settings and mounted tmpfs with the noexec option.
The solution was
TMPDIR=/var/tmp pip install --upgrade subprocess32
I had the same error message when installing pycrypto (although nothing to do with paramiko). The solution for me was:
yum install autoconf
TMPDIR=/home/$USER/tmp
TMP=$TMPDIR
TEMP=$TMPDIR
export TMPDIR TMP TEMP
and then install again:
pip install pocrypto
I had this same problem in Chrubuntu 14.04, and solved it by first doing:
apt-get install python-dev
...to fix something to do with header files, and then:
pip install pycrypto
...to solve the actual problem with paramiko. However, then paramiko had a problem with something ecdsa, and 'pip install paramiko' said everything was already installed, no problem, so I did 'pip uninstall paramiko' followed by 'pip install paramiko', and now I can import paramiko in python without a problem.
There is probably a more elegant way to solve that last bit but this worked well enough for me.

Why is pip installing an old version of my package?

I've just uploaded a new version of my package to PyPi (1.2.1.0-r4): I can download the egg file and install it with easy_install, and the version checks out correctly. But when I try to install using pip, it installs version 1.1.0.0 instead. Even if I explicitly specify the version to pip with pip install -Iv tome==1.2.1.0-r4, I get this message: Requested tome==1.2.1.0-r4, but installing version 1.1.0.0, but I don't understand why.
I double checked with parse_version and confirmed that the version string on 1.2.1 is greater than that on 1.1.0 as shown:
>>> from pkg_resources import parse_version as pv
>>> pv('1.1.0.0') < pv('1.2.1.0-r4')
True
>>>
So any idea why it's choosing to install 1.1.0 instead?
This is an excellent question. It took me forever to figure out. This is the solution that works for me:
Apparently, if pip can find a local version of the package, pip will prefer the local versions to remote ones. I even disconnected my computer from the internet and tried it again -- when pip still installed the package successfully, and didn't even complain, the source was obviously local.
The really confusing part, in my case, was that pip found the newer versions on pypi, reported them, and then went ahead and re-installed the older version anyway ... arggh. Also, it didn't tell me what it was doing, and why.
So how did I solve this problem?
You can get pip to give verbose output using the -v flag ... but one isn't enough. I RTFM-ed the help, which said you can do -v multiple times, up to 3x, for more verbose output. So I did:
pip install -vvv <my_package>
Then I looked through the output. One line caught my eye:
Source in /tmp/pip-build-root/ has version 0.0.11, which satisfies requirement <my_package>
I deleted that directory, after which pip installed the newest version from pypi.
Try forcing download the package again with:
pip install --no-cache-dir --upgrade <package>
Thanks to Marcus Smith, who does amazing work as a maintener of pip, this was fixed in version 1.4 of pip which was released on 2013-07-23.
Relevant information from the changelog for this version
Fixed a number of issues (#413, #709, #634, #602, and #939) related to
cleaning up and not reusing build directories. (Pull #865, #948)
I found here that there is a known bug in pip that it won't check the version if there's a build directory with unpacked sources. I have checked this on my troubling package and after deleting its sources from build directory pip installed the required version.
If you are using a pip version that comes with some distribution packages (ex. Ubuntu python-pip), you may need to install a newer pip version:
Update pip to latest version:
sudo pip install -U pip
In case of "virtualenv", skip "sudo":
pip install -U pip
Following command may be required, if your shell report something like -bash: /usr/bin/pip: No such file or directory after pip update:
hash -d pip
Now install your package as usual:
pip install -U foo
or
pip install foo==package.version.here
Got the same issue to update pika 0.9.5 to 0.9.8. The only working way was to install from tarball: pip install https://pypi.python.org/packages/source/p/pika/pika-0.9.8.tar.gz.
In my case the python version used (3.4) didn't satisfy Django 2.1 dependencies requirements (python >= 3.5).
For my case I had to delete the .pip folder in my home directory and then I was able to get later versions of multiple libraries. Note that this was on linux.
pip --version
pip 18.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)
virtualenv --version
15.1.0
Just in case that anyone else hassles with upgrading torchtext (or probably any other torch library):
Although https://pypi.org/project/torchtext/ states that you could run pip install torchtext I had to install it similiar to torch by specifying --find-links aka -f:
pip install torchtext===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
What irritated me was that PyCharm pointed me to the new version, but couldn't find it when attempting to upgrade to it. I guess that PyCharm uses its own mechanism to spot new versions. Then, when invoking pip under the hood, it didn't find the new version without the --find-links option.
In my case I am pip installing a .tar.gz package from Artifactory that I make a lot of updates to. In order to overwrite my cached Python files and always grab/install the latest I was able to run:
pip install --no-cache-dir --force-reinstall <path/to/tar.gz>
You should see this re-download any necessary files and install those, instead of using your local cache.
10 years on and pip still fails to work as expected 😖.
I wasted a couple of hours now banging my head against the wall trying to find out why pip won't install a development version of my package. In my case, there are versions 0.0.4 and 0.0.5.dev1 in a private gitlab.com package registry (hence the --extra-index-url argument below), but I believe that's not relevant to the problem.
Following a lot of the advice on this page, I create a test venv in a far away folder, clear the pip cache, uninstall the package in question, etc. first to rule out the most common problems:
$ pip cache purge && \
pip uninstall --yes my-package && \
pip install --extra-index-url "https://_:${GITLAB_PASSWORD_TOOLS_VAULTTOOLS}#gitlab.com/api/v4/projects/<project-id>/packages/pypi/simple" \
--no-cache-dir \
--pre \
--upgrade my-package
output (using empty lines to separate output for commands):
WARNING: No matching packages
Files removed: 0
Found existing installation: my-package 0.0.4
Uninstalling my-package-0.0.4:
Successfully uninstalled my-package-0.0.4
Looking in indexes: https://pypi.org/simple, https://_:****#gitlab.com/api/v4/projects/<project-id>/packages/pypi/simple
Collecting my-package
Downloading https://gitlab.com/api/v4/projects/<project-id>/packages/pypi/files/f07 ... 397/my_package-0.0.5.dev1-py3-none-any.whl (16 kB)
Downloading https://gitlab.com/api/v4/projects/<project-id>/packages/pypi/files/775 ... 70e/my_package-0.0.4-py3-none-any.whl (16 kB)
...
Successfully installed my-package-0.0.4
So pip does see the dev package version, but chooses the earlier one nonetheless.
In an attempt to figure out what's going on, I published a 0.0.5 version: Error persists, pip sees all three versions, but still installs 0.0.4.
In a further, increasingly desperate attempt, I removed any versions prior to 0.0.5* from the gitlab.com package registry.
Only now, pip would bother to actually display some useful information:
$ (same command as above)
... (similar output as above) ...
ERROR: Cannot install my-package==0.0.5 and my-package==0.0.5.dev1 because these package versions have conflicting dependencies.
The conflict is caused by:
my-package 0.0.5 depends on my-other-package<0.2.5 and >=0.2.4
my-package 0.0.5.dev1 depends on my-other-package<0.2.5 and >=0.2.4
To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
OK, so there is something wrong with my package dependencies. Thanks for letting me know.
Seriously - I tried hard for a couple of hours using all kinds of pip ... -vvv and/or fixed versions such as e.g. my-package==0.0.5.dev1 - but I did not manage to get any useful output out of pip - until I wiped the entire history from my package registry 🤬.
Hope this at least helps someone in the same situation.
I found that if you use microversions, pip doesn't seem to recognize them. For example, we couldn't get version 1.9.9.1 to upgrade.
In my case, someone had published the latest version of a package with python2, so attempting to pip3 install it grabbed an older version that had been built with python3.
Handy things to check when debugging this:
If pip install claims to not be able to find the version, see whether pip search can see it.
Take a look at the "Download Files" section on the pypi repo -- the filenames might suggest what's wrong (in my case i saw -py2- there clear as day).
As suggested by others, try running pip install --no-cache-dir in case pip isn't bothering to ask the internet because it already has your answer locally.
I had hidden unversioned files under the Git tab in PyCharm that were being installed with pip install . even though I didn't see the files anywhere else.
Took a long time to find it for me, posting this in hope that it'll help somebody else.
if you need the path for your package do pip -v list. Example see related post when using pip -e Why is an old version of a package of my python library installing by itself with pip -e?

Categories

Resources