TA-Lib / ta-lib-python

Python wrapper for TA-Lib (http://ta-lib.org/).
http://ta-lib.github.io/ta-lib-python
Other
9.78k stars 1.77k forks source link

Need help with installing TA-Lib on Windows 11 through pip in Python virtual environment #652

Closed furballcoder closed 6 months ago

furballcoder commented 6 months ago

I have been trying to install TA-Lib through pip install ta-lib from an environment created through Python venv for a while and the installation keeps failing with the following:

(sdtrade4) PS C:\Users\ljfong\Repos\simfin-screener> pip install ta-lib
Collecting ta-lib
  Using cached TA-Lib-0.4.29.tar.gz (368 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in c:\py_envs\sdtrade4\lib\site-packages (from ta-lib) (1.26.4)
Building wheels for collected packages: ta-lib
  Building wheel for ta-lib (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for ta-lib (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [19 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-311
      creating build\lib.win-amd64-cpython-311\talib
      copying talib\abstract.py -> build\lib.win-amd64-cpython-311\talib
      copying talib\deprecated.py -> build\lib.win-amd64-cpython-311\talib
      copying talib\stream.py -> build\lib.win-amd64-cpython-311\talib
      copying talib\__init__.py -> build\lib.win-amd64-cpython-311\talib
      running build_ext
      building 'talib._ta_lib' extension
      creating build\temp.win-amd64-cpython-311
      creating build\temp.win-amd64-cpython-311\Release
      creating build\temp.win-amd64-cpython-311\Release\talib
      "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -Ic:\ta-lib\c\include -IC:\Users\ljfong\AppData\Local\Temp\pip-build-env-ia_6qng7\normal\Lib\site-packages\numpy\core\include -IC:\py_envs\sdtrade4\include -IC:\Users\ljfong\AppData\Local\Programs\Python\Python311\include -IC:\Users\ljfong\AppData\Local\Programs\Python\Python311\Include "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tctalib/_ta_lib.c /Fobuild\temp.win-amd64-cpython-311\Release\talib/_ta_lib.obj
      _ta_lib.c
      talib/_ta_lib.c(1222): fatal error C1083: Cannot open include file: 'ta-lib/ta_defs.h': No such file or directory
      error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for ta-lib
Failed to build ta-lib
ERROR: Could not build wheels for ta-lib, which is required to install pyproject.toml-based projects

I have been following the steps outlined in https://github.com/TA-Lib/ta-lib-python?tab=readme-ov-file#windows

  1. Downloaded and unzipped ta-lib-0.4.0-msvc.zip.
  2. Created C:\ta-lib with content of the zip file downloaded.
  3. Change directory to C:\ta-lib\c\make\cdr\win32\msvc
  4. Ran nmake successfully through x64 Native Tools Command Prompt for VS 2022. I did not notice any error here.
  5. pip install ta-lib was unsuccessful due to not being able to open include file: ta-lib/ta_defs.h.

My system:

Feels like I am missing something very basic here?

mrjbq7 commented 6 months ago

OMG, somehow when I updated the C bindings, I lost the windows #include.

Fixed in fce1e555e76471376feefd87db9a07069ff978a8 and made a 0.4.30 release to hopefully fix that asap.

Can you try?

mrjbq7 commented 6 months ago

It's late but I should find out why the windows github builder didn't catch this

furballcoder commented 6 months ago

Tried, success this time! This is super fast fix, thanks.

(sdtrade4) PS C:\Users\ljfong\Repos\simfin-screener> pip install ta-lib
Collecting ta-lib
  Downloading TA-Lib-0.4.30.tar.gz (368 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 368.3/368.3 kB 1.1 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in c:\py_envs\sdtrade4\lib\site-packages (from ta-lib) (1.26.4)
Building wheels for collected packages: ta-lib
  Building wheel for ta-lib (pyproject.toml) ... done
  Created wheel for ta-lib: filename=TA_Lib-0.4.30-cp311-cp311-win_amd64.whl size=559086 sha256=d55444ef96e05817150e17566b8b9b5081ae34604723e4989aeb20193731222f
  Stored in directory: c:\users\ljfong\appdata\local\pip\cache\wheels\26\54\61\5f594a7d12dbb4a2e4f33e00e9a1951f46d42ae03d37e33d6a
Successfully built ta-lib
Installing collected packages: ta-lib
Successfully installed ta-lib-0.4.30