Use pipenv to install packages like Keras?

Hi knick,

Yes, this should be possible (in fact, I just tried it myself and it worked :slight_smile:).

Here’s what I did (Linux):

pipenv --three # or --two
pipenv install keras tensorflow pandas
pipenv shell

pipenv shell will output the command to activate its virtual environment. The command should look like this:

Launching subshell in virtual environment…
 . /home/<user>/.local/share/virtualenvs/<project-name>-E4Euwy4K/bin/activate

You can now take the example script from our Python setup guide for conda and replace the line source activate py35_knime (Linux/Mac) or the respective part of the the line @CALL activate py35_knime || ECHO Activating py35_knime failed (Windows) by the command that was output by pipenv shell. You can also remove the line where Anaconda is added to the PATH variable. Then save the script. If you’re on Linux/Mac, you’ll also have to make it executable.

In my case, the script for use with pipenv looks like this:

#! /bin/bash
. /home/marcel/.local/share/virtualenvs/marcel-E4Euwy4K/bin/activate
python "$@" 1>&1 2>&2

All that’s left to do now, is to point to that file via File > Preferences > KNIME > Python > Path to Python (2|3) executable. The preference page should give you immediate feedback on whether the environment was detected.

Please let me know if you experience any problems :slight_smile:.

Marcel

4 Likes