2

I don't understand this...

I want to install this https://gist.github.com/sixtenbe/1178136.

It is a peak detection script for python.

Everywhere I look I am told to use pip with the .git extension.

All I see is how to download the .zip, but from there I am lost.

How can I install this?

Thanks.

PseudoAj
  • 5,234
  • 2
  • 17
  • 37
sci-guy
  • 2,394
  • 4
  • 25
  • 46
  • What do you mean by install? it's a collection of python scripts; do you want to be able to run it from command line. Also, what operating system are you using? – PseudoAj May 08 '16 at 00:33
  • ubuntu -- clearly I am missing something basic. I want to use this script as in 'import.....' in my script – sci-guy May 08 '16 at 00:35
  • 1
    Download and put them where your python script is; you will be able to import. – PseudoAj May 08 '16 at 00:38

3 Answers3

2

Let's give it another look.
By "installing a package" we might mean that the package should be available via import.
For that the package directory should reside either in the current directory or in one of the other directories in the import search path.
One such directory is the "user-specific site-packages directory, USER_SITE":

python -c "import site; print(site.getusersitepackages())"

Git URL

First we might need a Git URL. Going to https://gist.github.com/sixtenbe/1178136 we can click on the Embed pop-up and switch it to Clone via HTTPS:

enter image description here

in order to obtain the GIT URL: https://gist.github.com/1178136.git.

git and bash

Having the Git URL and the Unix shell (bash) we can install the package manually into the USER_SITE.

Let's go into the USER_SITE first:

cd $(python -c "import site; print(site.getusersitepackages())")
pwd

Now that we are in the USER_SITE, let's download the Gist:

git clone https://gist.github.com/1178136.git analytic_wfm

Finally, let's verify that the package is now available:

cd && python -c "import analytic_wfm.analytic_wfm; print(analytic_wfm.analytic_wfm.__all__)"

If numpy is installed, it prints

['ACV_A1', 'ACV_A2', 'ACV_A3', 'ACV_A4', 'ACV_A5', 'ACV_A6', 'ACV_A7', 'ACV_A8']

pip

Let's try to install a Gist package with pip.
For pip install we should prefix the Git URL with git+:

pip install --user git+https://gist.github.com/1178136.git

This gives us the error:

ERROR: git+https://gist.github.com/1178136.git does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.

Looks like the package we've picked is missing the necessary pip configuration!

Let's try another one:

pip install --user git+https://gist.github.com/bf91613a021a536c7ce16cdba9168604.git

Installs NP:

Successfully built llog
Installing collected packages: llog
Successfully installed llog-1.0

Particularly because it has the setup.py.

Note also that Gist does not support subfolders, and pip seems to depend on them in handling the packages argument, but the code in setup.py can workaround this by creating the package subfolder on the fly and copying the Python files there!

Hence if you want to import that Gist, https://gist.github.com/sixtenbe/1178136, with the rest of the requirements.txt dependencies, - you can fork it and add setup.py to the effect.

pypi

Given that the analytic-wfm can also be found at the Python Package Index, https://pypi.org/project/analytic-wfm/, you can install it with

pip install analytic-wfm
ArtemGr
  • 11,684
  • 3
  • 52
  • 85
1

You can get the individual files in the Gist (or download the Gist as an ZIP and extract) and put them in your source code folder.

Then you will be able to import them as modules in your own scripts:

import analytic_wfm as AW
AW.ACV_A6( ... )

import peakdetect as PK
PK.peakdetect_parabola( ... )
musically_ut
  • 34,028
  • 8
  • 94
  • 106
  • Where you say source code folder, you mean where my .py script is that I am running? – sci-guy May 08 '16 at 00:37
  • But everytime I want to use this function, I have to put this script in the same folder? Isn't there a global folder where I can store it? – sci-guy May 08 '16 at 00:39
  • @renegade You can put it in a directory which is present in the environment variable PYTHONPATH. – musically_ut May 08 '16 at 01:02
  • @renegade on Ubuntu, use `sudo` to move the scripts to `/usr/local/lib/python2.7/dist-packages` after downloading them. They'll then be available for import into any Python 2 program. – MattDMo May 08 '16 at 02:12
0

Here's a 4-liner that I sometimes use:

import urllib.request
url = 'https://gist.github...'
with open('package_name.py', 'w') as file: file.write(urllib.request.urlopen(url).read().decode())
import package_name

It's basically the same as @musically_ut's approach, except in the script you're running

Matt
  • 460
  • 6
  • 9