Unable to use TA-Lib from python program

Unable to use TA-Lib from python program

Postby MGTHEBOSS » Wed Apr 10, 2013 3:55 pm

I am currently developing an investment consultant website
where I want to use TA-Lib(http://ta-lib.org/).
I also want to use Python wrapper for TA-Lib
(http://mrjbq7.github.io/ta-lib/index.html).
I am on Windows 7 Professional 32-bit.
But the problem is I am unable to use TA-Lib
from my python programs.
I have installed python 3.2 and numpy.
Installation instructions on this page
(http://mrjbq7.github.io/ta-lib/install.html)
are not good enough.
So, what do I have to do in order to successfully
import TA-Lib from my programs?
This is my first post in this forum.Please help me.
MGTHEBOSS
 
Posts: 9
Joined: Wed Apr 10, 2013 3:36 pm

Re: Unable to use TA-Lib from python program

Postby setrofim » Wed Apr 10, 2013 4:20 pm

What do you mean when you say that you are unable to use TA-lib? Be more specific. What exact error are you getting when you import talib in python console (or when you try to install it)?
setrofim
 
Posts: 285
Joined: Mon Mar 04, 2013 7:52 pm

Re: Unable to use TA-Lib from python program

Postby MGTHEBOSS » Wed Apr 10, 2013 5:52 pm

setrofim wrote:What do you mean when you say that you are unable to use TA-lib? Be more specific. What exact error are you getting when you import talib in python console (or when you try to install it)?



Thanks for your reply.

I have downloaded TA-Lib from http://prdownloads.sourceforge.net/ta-l ... 0-msvc.zip .
I have unzipped it to C:\ta-lib
[These installation directions were provided in this page:
http://mrjbq7.github.io/ta-lib/install.html]

This is the output I am getting in python prompt:

>>> import talib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named talib
>>>

I want to run the first example program from this page:
http://mrjbq7.github.io/ta-lib/index.html
MGTHEBOSS
 
Posts: 9
Joined: Wed Apr 10, 2013 3:36 pm

Re: Unable to use TA-Lib from python program

Postby setrofim » Wed Apr 10, 2013 6:04 pm

OK, so Python can't find talib. Check if there is a talib.py or a talib folder in "C:\PythonXX\LIb\site-packages' (where XX is the version of python you're using). If it isn't then something went wrong during the install -- try re-running 'python setup.py install' in the unzipped directory. If it is in there, then you may be invoking a different version of Python (if you have more than one on the system) -- in this case, try invoking python with full path, i.e. "C:\PythonXX\python.exe your_script.py".
setrofim
 
Posts: 285
Joined: Mon Mar 04, 2013 7:52 pm

Re: Unable to use TA-Lib from python program

Postby MGTHEBOSS » Wed Apr 10, 2013 6:27 pm

setrofim wrote:OK, so Python can't find talib. Check if there is a talib.py or a talib folder in "C:\PythonXX\LIb\site-packages' (where XX is the version of python you're using). If it isn't then something went wrong during the install -- try re-running 'python setup.py install' in the unzipped directory. If it is in there, then you may be invoking a different version of Python (if you have more than one on the system) -- in this case, try invoking python with full path, i.e. "C:\PythonXX\python.exe your_script.py".



There is no talib.py or a talib folder in "C:\Python32\LIb\site-packages"
There is no setup.py in the unzipped directory.
I am not invoking a different version of Python because I have only version 3.2 installed in my PC.

One thing I must mention is there was no standard installation procedure.
In this link(http://mrjbq7.github.io/ta-lib/install.html) they have only
mentioned to unzip.

So, what should I do in order to successfully import talib?
MGTHEBOSS
 
Posts: 9
Joined: Wed Apr 10, 2013 3:36 pm

Re: Unable to use TA-Lib from python program

Postby setrofim » Wed Apr 10, 2013 6:34 pm

MGTHEBOSS wrote:One thing I must mention is there was no standard installation procedure.
In this link(http://mrjbq7.github.io/ta-lib/install.html) they have only
mentioned to unzip.

OK, I see. You have misunderstood the docs. Read the first part. What you've done is download and install TA-Lib iteself. You still need to download and install the Python module to interface with it. Todo that, either run easy_install, or download the module (click on one of the blue folders near the top of the page), unzip it and run 'python setup.py install' in that unzipped location.
setrofim
 
Posts: 285
Joined: Mon Mar 04, 2013 7:52 pm

Re: Unable to use TA-Lib from python program

Postby MGTHEBOSS » Wed Apr 10, 2013 6:49 pm

setrofim wrote:
MGTHEBOSS wrote:One thing I must mention is there was no standard installation procedure.
In this link(http://mrjbq7.github.io/ta-lib/install.html) they have only
mentioned to unzip.

OK, I see. You have misunderstood the docs. Read the first part. What you've done is download and install TA-Lib iteself. You still need to download and install the Python module to interface with it. Todo that, either run easy_install, or download the module (click on one of the blue folders near the top of the page), unzip it and run 'python setup.py install' in that unzipped location.


You are right.
I have done what you have told me to do.
Now I am getting this:

C:\mrjbq7-ta-lib-TA_Lib-0.4.5-6-g283236b\mrjbq7-ta-lib-283236b>python setup.py i
nstall
Traceback (most recent call last):
File "setup.py", line 3, in <module>
from Cython.Distutils import build_ext
ImportError: No module named Cython.Distutils


I think I have to install Cython.
MGTHEBOSS
 
Posts: 9
Joined: Wed Apr 10, 2013 3:36 pm

Re: Unable to use TA-Lib from python program

Postby setrofim » Wed Apr 10, 2013 6:51 pm

MGTHEBOSS wrote:I think I have to install Cython.

Yup.
setrofim
 
Posts: 285
Joined: Mon Mar 04, 2013 7:52 pm

Re: Unable to use TA-Lib from python program

Postby MGTHEBOSS » Wed Apr 10, 2013 7:05 pm

I have installed Cython from here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#cython

Here is the output I got(See the error on the last line please.):

C:\mrjbq7-ta-lib-TA_Lib-0.4.5-6-g283236b\mrjbq7-ta-lib-283236b>python setup.py i
nstall
running install
running build
running build_py
creating build
creating build\lib.win32-3.2
creating build\lib.win32-3.2\talib
copying talib\deprecated.py -> build\lib.win32-3.2\talib
copying talib\test_abstract.py -> build\lib.win32-3.2\talib
copying talib\test_data.py -> build\lib.win32-3.2\talib
copying talib\test_func.py -> build\lib.win32-3.2\talib
copying talib\__init__.py -> build\lib.win32-3.2\talib
running build_ext
skipping 'talib\common.c' Cython extension (up-to-date)
building 'talib.common' extension
error: Unable to find vcvarsall.bat

What is the solution?

I have found vcvarsall.bat on my C:\ drive.
Where should I copy it to?
MGTHEBOSS
 
Posts: 9
Joined: Wed Apr 10, 2013 3:36 pm

Re: Unable to use TA-Lib from python program

Postby setrofim » Wed Apr 10, 2013 7:07 pm

Which Visual Studio version do you have (you need to be running the install inside VS command prompt but there're a couple of things you might need to do)?
setrofim
 
Posts: 285
Joined: Mon Mar 04, 2013 7:52 pm

Re: Unable to use TA-Lib from python program

Postby MGTHEBOSS » Wed Apr 10, 2013 7:10 pm

setrofim wrote:Which Visual Studio version do you have (you need to be running the install inside VS command prompt but there're a couple of things you might need to do)?


VS 2010.

I found the file in this location:
C:\Program Files\Microsoft Visual Studio 10.0\VC
MGTHEBOSS
 
Posts: 9
Joined: Wed Apr 10, 2013 3:36 pm

Re: Unable to use TA-Lib from python program

Postby setrofim » Wed Apr 10, 2013 7:21 pm

OK, do the following

  1. Start a VS Command Prompt. Either from your start menu if it's there, or just start a regular CMD.exe and run "C:\Program Files\Microsoft Visual Studo 10.0\Common\Tools\vsvars32.bat" in it (yes, vsvars32.bat, not vcvarsall.bat). It should tell you that it's setting up the environment.
  2. Copy (not move!) "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" to "C:\Program Files\Microsoft Visual Studio 10.0\Common\Tools" (the same location as vsvars32.bat).
  3. Run this in the command prompt:
    Code: Select all
    set VS90COMNTOOLS=%VS100COMNTOOLS%
  4. In the same prompt navigate to your cython directory and re-run setup.py; it should hopefully compile now...
setrofim
 
Posts: 285
Joined: Mon Mar 04, 2013 7:52 pm

Re: Unable to use TA-Lib from python program

Postby MGTHEBOSS » Thu Apr 11, 2013 5:32 am

I have installed Cython already from here(I mentioned that in a previous post):
http://www.lfd.uci.edu/~gohlke/pythonlibs/#cython
I was getting the errors while installing the Python module to interface with TA-Lib.

After following your instructions the previous problem is solved but now I am getting a new error
(see the red part).

C:\mrjbq7-ta-lib-TA_Lib-0.4.5-6-g283236b\mrjbq7-ta-lib-283236b>python setup.py i
nstall
running install
running build
running build_py
running build_ext
skipping 'talib\common.c' Cython extension (up-to-date)
building 'talib.common' extension
creating build\temp.win32-3.2
creating build\temp.win32-3.2\Release
creating build\temp.win32-3.2\Release\talib
C:\Program Files\Microsoft Visual Studio 10.0\VC\BIN\cl.exe /c /nologo /Ox /MD /
W3 /GS- /DNDEBUG -IC:\Python32\lib\site-packages\numpy\core\include -Ic:\ta-lib\
c\include -IC:\Python32\include -IC:\Python32\PC /Tctalib\common.c /Fobuild\temp
.win32-3.2\Release\talib\common.obj
common.c
talib\common.c(255) : fatal error C1083: Cannot open include file: 'ta_libc.h':
No such file or directory
error: command '"C:\Program Files\Microsoft Visual Studio 10.0\VC\BIN\cl.exe"' f
ailed with exit status 2
MGTHEBOSS
 
Posts: 9
Joined: Wed Apr 10, 2013 3:36 pm

Re: Unable to use TA-Lib from python program

Postby setrofim » Thu Apr 11, 2013 5:39 am

Heve you run this setup.py in a command prompt configured as described in my previous post? Where is cl.exe on your system? Also it seems it cannot find the ta lib headers. Check that "C:\ta-lib\c\include" directory exists and that it has ta_libc.h in it.

*sigh* I hate dealing with C extensions on Windows...
setrofim
 
Posts: 285
Joined: Mon Mar 04, 2013 7:52 pm

Re: Unable to use TA-Lib from python program

Postby MGTHEBOSS » Thu Apr 11, 2013 5:58 am

After carefully observing the error (See my last post please)
I made a little change in the directory hierarchy in the
TA-Lib installation directory.
It was:
C:\ta-lib\ta-lib
It is now:
C:\ta-lib

The installation ran without any error.But I got a lot of warnings like this:

talib\func.c(71055) : warning C4133: '=' : incompatible types - from 'PyArrayObj
ect *' to 'PyObject *'


Should I ignore those warnings?

Now I can import talib successfully.

Here is an example:

>>> import talib
>>> import numpy
>>> close = numpy.random.random(100)
>>> output = talib.SMA(close)
>>> print( output)
[ nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan 0.5711924
0.55111848 0.53833551 0.52087339 0.52819251 0.50945409 0.51555445
0.50020185 0.50896269 0.51791534 0.51122305 0.51363055 0.50282446
0.4778106 0.49580477 0.49492172 0.52516671 0.50804372 0.49411663
0.48427226 0.49938924 0.50211882 0.47257698 0.46766745 0.45550139
0.45361555 0.44103845 0.44007251 0.41565875 0.39624108 0.3925906
0.40560653 0.4222031 0.43824676 0.44991805 0.47257248 0.46686218
0.47091537 0.44517223 0.44501521 0.45566246 0.44855081 0.4553965
0.47442943 0.47313736 0.48865892 0.47090425 0.46984189 0.47896633
0.47763586 0.48351314 0.49124599 0.50776853 0.52399982 0.52240132
0.52574903 0.54655213 0.55134666 0.55191002 0.55717177 0.56032858
0.56283922 0.56585799 0.5483208 0.51811309 0.51867265 0.5171926
0.51096155 0.51214407 0.49411737 0.50089255]
>>>
MGTHEBOSS
 
Posts: 9
Joined: Wed Apr 10, 2013 3:36 pm

Re: Unable to use TA-Lib from python program

Postby setrofim » Thu Apr 11, 2013 6:10 am

MGTHEBOSS wrote:Should I ignore those warnings?

Yes, a lot of C extensions will give you some kind of warnings during compilation and it is usually safe to ignore them. Try using ta-lib to manipulate a know set of inputs, and if you're getting results you'd expect, I wouldn't worry about it.
setrofim
 
Posts: 285
Joined: Mon Mar 04, 2013 7:52 pm

Re: Unable to use TA-Lib from python program

Postby MGTHEBOSS » Thu Apr 11, 2013 6:57 am

setrofim wrote:
MGTHEBOSS wrote:Should I ignore those warnings?

Yes, a lot of C extensions will give you some kind of warnings during compilation and it is usually safe to ignore them. Try using ta-lib to manipulate a know set of inputs, and if you're getting results you'd expect, I wouldn't worry about it.


OK.
MGTHEBOSS
 
Posts: 9
Joined: Wed Apr 10, 2013 3:36 pm


Return to Web Development

Who is online

Users browsing this forum: No registered users and 1 guest