1

I use it on my windows machine by downloading its binary. I also use it in Heroku from its herokus build pack. I don't know what operating system replit use. But I try every possible commed like.

!pip install ta-lib

!pip install talib-binary

It's not working with replit. I thought it work like google co-lab but its not the same.

can anyone use TA-LIB with replit. if so. How you install it?

Sushen Biswas
  • 522
  • 1
  • 6
  • 24
  • I just tried replit and was able to build ta-lib library and python package for it from sources. It's quite tricky but I'll try to compose a working step-by-step guide – truf Sep 08 '22 at 10:45

2 Answers2

1

Getting TA-Lib work on Replit (by installing it from sources)

Create a new replit with Nix toolset with a Python template. In main.py write:

import talib
print (talib.__ta_version__)

This will be our test case. If ta-lib is installed the python main.py (executed in Shell) will return something like:

$ python main.py 
b'0.6.0-dev (Jan  1 1980 00:00:00)'

We need to prepare a tools for building TA-Lib sources. There is a replit.nix file in your project's root folder (in my case it was ~/BrownDutifulLinux). Every time you execute a command like cmake the Nix reports that:

cmake: command not installed. Multiple versions of this command were found in Nix.
Select one to run (or press Ctrl-C to cancel):

cmake.out
cmakeCurses.out
cmakeWithGui.out
cmakeMinimal.out
cmake_2_8.out

If you select cmake.out it will add a record about it into the replit.nix file. And next time you call cmake, it will know which cmake version to launch. Perhaps you may manually edit replit.nix file... But if you're going to add such commands in a my way, note that you must execute them in Shell in your project root folder as replit.nix file is located in it. Otherwise Nix won't remember your choice.

After all my replit.nix file (you may see its content with cat replit.nix) content was:

{ pkgs }: {
  deps = [
    pkgs.libtool
    pkgs.automake
    pkgs.autoconf
    pkgs.cmake
    pkgs.python38Full
  ];
  env = {
    PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
      # Needed for pandas / numpy
      pkgs.stdenv.cc.cc.lib
      pkgs.zlib
      # Needed for pygame
      pkgs.glib
      # Needed for matplotlib
      pkgs.xorg.libX11
    ];
    PYTHONBIN = "${pkgs.python38Full}/bin/python3.8";
    LANG = "en_US.UTF-8";
  };
}

Which means I executed libtool, autoconf, automake and cmake in Shell. I always choose a generic suggestion from Nix, without a specific version. Note: some commands may report errors as we executing them in a wrong way just to add to a replit.nix.

3. Once build tools are set up we need to get and build TA-Lib C library sources. To do that execute in Shell:

git clone https://github.com/TA-Lib/ta-lib.git

then

cd ta-lib/

libtoolize
autoreconf --install

./configure

If configure script is completed without any problems, build the library with:

make -j4

It will end up with some compilation errors, but they are related to some additional tools which are used to add new TA-Lib indicators and build at the end, but not the library itself. The library will be successfully compiled and you should be able to see it with:

$ ls ./src/.libs/
libta_lib.a   libta_lib.lai  libta_lib.so.0
libta_lib.la  libta_lib.so   libta_lib.so.0.0.0

Now we have our C library built, but we can't install it to a system default folders. So we have to use the library as is from the folders where it was build. All we need is just one more additional preparation:

mkdir ./include/ta-lib
cp ./include/*.h ./include/ta-lib/

This will copy a library headers to a subfolder, as they are designed to be used from a such subfolder (which they don't have due to impossibility to perform the installation step).

4. Now we have TA-Lib C library built and prepared to be used locally from its build folders. All we need after that - is to compile the Python wrapper for it. But Python wrapper will look for a library only in system default folders, so we need to instruct it where our library is.
To do this, execute pwd and remember the absolute path to your project's root folder. In my case it was:
/home/runner/FormalPleasedOffice

Then adjust the paths (there are two) in a following command to lead to your project path: TA_INCLUDE_PATH=/home/runner/FormalPleasedOffice/ta-lib/include/ TA_LIBRARY_PATH=/home/runner/FormalPleasedOffice/ta-lib/src/.libs/ pip install ta-lib

This is one line command, not a two commands.If the paths would be shorter it would look like:
TA_INCLUDE_PATH=/path1/ TA_LIBRARY_PATH=/path2/ pip install ta-lib.

After execution of this command the wrapper will be installed with two additional paths where it will look for a library and its header files.

That's actually all. An alternative way would be to clone the wrapper sources, edit its setup.py and install wrapper manually. Just for the record this would be:

cd ~/Your_project
git clone https://github.com/mrjbq7/ta-lib.git ta-lib-wrapper
cd ta-lib-wrapper

Here edit the setup.py. Find the lines include_dirs = [ and library_dirs = [ and append your paths to these lists. Then you just need to:

python setup.py build
pip install .

Note the dot at the end.

5. Go to the project's folder and try our python script:

$python main.py
b'0.6.0-dev (Jan  1 1980 00:00:00)'

Bingo!

truf
  • 2,843
  • 26
  • 39
  • its say " [-Werror=format-security] " and its say " make: *** [Makefile:457: all-recursive] Error 1 " after make "make -j4". – Sushen Biswas Sep 12 '22 at 02:06
  • 1
    that means nothing. Copy as much of output as you can and paste at https://pastebin.com/ It also will be helpful to take a look on output of `./configure` – truf Sep 12 '22 at 09:50
  • https://pastebin.com/3v15zDZx this is the error. – Sushen Biswas Sep 13 '22 at 08:01
  • 1
    At step 3 after `make -j4` I explained why the build process ends up with error and why it can be ignored. In particular this is it: `make[2]: *** [Makefile:386: gen_code-gen_code.o] Error 1` - error which may be ignored. You just need to continue instructions. – truf Sep 13 '22 at 08:42
  • https://pastebin.com/xmB74FMv its say faild to build ta-lib – Sushen Biswas Sep 14 '22 at 00:17
  • 1
    `TA_INCLUDE_PATH=/home/runner/FormalPleasedOffice/ta-lib/include/ TA_LIBRARY_PATH=/home/runner/FormalPleasedOffice/ta-lib/src/.libs/ pip install ta-lib` - is a one line command, not two commands.If the paths would be shorter it would look like `TA_INCLUDE_PATH=/path1/ TA_LIBRARY_PATH=/path2/ pip install ta-lib`. I'll add a note about this to the instructions. – truf Sep 14 '22 at 09:39
1

The @truf answer is correct.

after you add the

pkgs.libtool
pkgs.automake
pkgs.autoconf
pkgs.cmake

in the replit.nix dippendancies.

  1. git clone https://github.com/TA-Lib/ta-lib.git

  2. cd ta-lib/

  3. libtoolize

  4. autoreconf --install

  5. ./configure

  6. make -j4

  7. mkdir ./include/ta-lib

  8. cp ./include/*.h ./include/ta-lib/

  9. TA_INCLUDE_PATH=/home/runner/FormalPleasedOffice/ta-lib/include/ TA_LIBRARY_PATH=/home/runner/FormalPleasedOffice/ta-lib/src/.libs/ pip install ta-lib

Note : FormalPleasedOffice should be your project name

Done.

Here is the youtube video : https://www.youtube.com/watch?v=u20y-nUMo5I

Sushen Biswas
  • 522
  • 1
  • 6
  • 24