[Troubleshooting]

Diagnose pynescript install, parse, lint, evaluation, LSP, data providers, and Pro API failures with concrete checks.

Troubleshooting

Abstract

Failures cluster by layer: environment, parse, lint, evaluation, data I/O, LSP, HTTP. Work top-down: confirm the binary/module, then a minimal script, then full strategy complexity. This page is a runbook; deep protocol and runtime docs are linked per section.

Conceptual model

Interface surface (diagnostic commands)

python -c "import pynescript; from pynescript import __about__; print(__about__.__version__)"
python -c "from pynescript.ast import parse, unparse; print(unparse(parse('//@version=5\nindicator(\"t\")\nplot(close)\n')))"
pynescript --version
pynescript lint - <<< $'//@version=5\nindicator("t")\nplot(close)\n'
python -c "import pygls"  # LSP extra
python -c "import ccxt"   # data extra
curl -s http://127.0.0.1:5002/ | head

Internals (where errors originate)

LayerPath
CLIsrc/pynescript/__main__.py
Parsesrc/pynescript/ast/helper.py, ANTLR error listener
Lintsrc/pynescript/ast/linter.py
Evalsrc/pynescript/ast/evaluator/, backend/runtime.py
Datasrc/pynescript/util/data.py
LSPsrc/pynescript/langserver/
HTTPbackend/app.py, backend/middleware/schemas.py

Invariants & edge cases

  • Minimal green script for isolation:
//@version=5
indicator("t")
plot(close)
  • Encoding must be UTF-8 unless you pass --encoding.
  • Pine v4 and earlier trigger linter deprecation (W002); parser support may still differ by construct.
  • Recursion limit is raised only during parse; extreme generated scripts can still fail.

Worked examples (by symptom)

1. pynescript: command not found

which python
python -m pynescript --help
# If module works but script does not:
python -m pip show pynescript
ls "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')"

Fix: activate the venv used for install; reinstall pip install pynescript.

2. ModuleNotFoundError: pynescript

Wrong interpreter (IDE using system Python). Point the IDE at the venv; reinstall editable from repo root: pip install -e ..

3. Parse / SyntaxError

pynescript parse-and-dump broken.pine

Checks:

  • //@version=5 or 6 present
  • Balanced parentheses / indentation (Pine uses line structure)
  • Multiline strings / v6 features need a package version that includes them
  • Binary/null bytes in file

Reduce to a minimal repro; if TV accepts it and PYNE does not, consult missing features and file a grammar issue.

4. Round-trip looks “wrong”

unparse normalizes formatting. Compare dumps:

pynescript parse-and-dump a.pine > /tmp/a.ast
pynescript parse-and-unparse a.pine | pynescript parse-and-dump /dev/stdin
# stdin may not work for parse-and-dump (file path required) — use a temp file:
pynescript parse-and-unparse a.pine --output-file /tmp/a2.pine
pynescript parse-and-dump /tmp/a2.pine > /tmp/a2.ast
diff -u /tmp/a.ast /tmp/a2.ast

Structural diff empty ⇒ cosmetic only.

5. Lint noise / CI red

CodeAction
E001Fix syntax first
W001Add //@version=5
W002Upgrade version pragma
C001C004Style; use --fail-on errors if style should not gate CI
pynescript lint script.pine --fail-on errors

6. literal_eval fails

  • Use mode="eval"-compatible expressions, not full strategy() scripts
  • Pass series as Python lists inside the expression or via context
  • Missing builtin → incomplete implementation

Escalate to Runtime.run for multi-bar scripts.

7. Runtime / /run execution error

curl -s -X POST http://127.0.0.1:5002/run -H 'Content-Type: application/json' -d '{"script":"//@version=5\nindicator(\"t\")\nplot(close)","data":[{"time":1,"open":1,"high":1,"low":1,"close":1,"volume":1}]}'

If minimal works but strategy fails: remove request.*, drawings, then strategy entries until isolated. Check mode; try "interpret".

8. Schema validation errors

UNKNOWN_FIELDS means you sent a key not in the schema — remove it. Do not rely on servers ignoring extras.

9. CORS from AXIS / browser

export ALLOWED_ORIGINS="http://localhost:8081,http://127.0.0.1:8081"

Restart Flask after changing env.

10. LSP will not start

pip install "pynescript[lsp]"
python -c "import pygls, lsprotocol"
command -v pynescript-lsp
# Run with editor logging enabled; check stderr for import traces

Ensure the editor’s command matches the venv. For Neovim, confirm filetypes include your buffer’s filetype.

11. Data provider failures

ProviderChecklist
mockShould always work offline
yahooNetwork; symbol format
alphavantageAPI key; demo limits
ccxtpip install "pynescript[data]"; exchange id; symbol BTC/USDT
pynescript data AAPL --provider mock

12. Version / parity confusion

PYNE is independent of TradingView®. Behavioral gaps are expected for edge builtins, broker emulators, and UI-only calls. Use compatibility and implementation status.

Failure modes (quick matrix)

SymptomLayerFirst check
Command not foundenvpython -m pynescript
Import error pyglsextra[lsp]
Import error ccxtextra[data]
SyntaxErrorparseminimal script + version
Lint CI faillint--fail-on level
Empty plotsevalplot() present; enough bars
400 UNKNOWN_FIELDSHTTPschema
403 create_keyHTTPADMIN_TOKEN
413HTTPbody size
Squiggles missingLSPdiagnostics enabled + filetype
Numerical driftevalwarmup / parity docs

See also