Что означает эта ошибка трассировки при запуске сценария python в Anaconda? - PullRequest
1 голос
/ 15 февраля 2020

Новое в программировании. Установлена ​​Анаконда на Windows 10 автомате. Были некоторые проблемы с запуском обновлений.

Находясь в базовой среде, я успешно установил свое первое репо Git:

(base) C:\Users\samsung\Anaconda3\pkgs>pip install git+git://github.com/json-transformations/jsonflatten.git
Collecting git+git://github.com/json-transformations/jsonflatten.git
  Cloning git://github.com/json-transformations/jsonflatten.git to c:\users\samsung\appdata\local\temp\pip-req-build-zeiezw
  Running command git clone -q git://github.com/json-transformations/jsonflatten.git 'C:\Users\samsung\AppData\Local\Temp\p
Collecting jsoncut
  Downloading jsoncut-0.6-py2.py3-none-any.whl (17 kB)
Requirement already satisfied: click>=6.0 in c:\users\samsung\anaconda3\lib\site-packages (from jsonflatten==0.2) (7.0)
Requirement already satisfied: colorama in c:\users\samsung\anaconda3\lib\site-packages (from jsoncut->jsonflatten==0.2) (0
Requirement already satisfied: pygments in c:\users\samsung\anaconda3\lib\site-packages (from jsoncut->jsonflatten==0.2) (2
Building wheels for collected packages: jsonflatten
  Building wheel for jsonflatten (setup.py) ... done
  Created wheel for jsonflatten: filename=jsonflatten-0.2-py2.py3-none-any.whl size=8116 sha256=029aafde944303cbfe872e86a13
  Stored in directory: C:\Users\samsung\AppData\Local\Temp\pip-ephem-wheel-cache-so8173tt\wheels\8f\02\52\37295acfd1368a3d2
Successfully built jsonflatten
Installing collected packages: jsoncut, jsonflatten
Successfully installed jsoncut-0.6 jsonflatten-0.2

(base) C:\Users\samsung\Anaconda3\pkgs>pip install jsonflatten
Requirement already satisfied: jsonflatten in c:\users\samsung\anaconda3\lib\site-packages (0.2)
Requirement already satisfied: click>=6.0 in c:\users\samsung\anaconda3\lib\site-packages (from jsonflatten) (7.0)
Requirement already satisfied: jsoncut in c:\users\samsung\anaconda3\lib\site-packages (from jsonflatten) (0.6)
Requirement already satisfied: pygments in c:\users\samsung\anaconda3\lib\site-packages (from jsoncut->jsonflatten) (2.5.2)
Requirement already satisfied: colorama in c:\users\samsung\anaconda3\lib\site-packages (from jsoncut->jsonflatten) (0.4.3)

Затем я запустил прогноз jsonflatten. json в качестве теста (как а также jsonflatten C: \ Users \ samsung.spyder-py3 \ прогноз. json), как предполагает readme, и полученный результат приведен ниже. Я бежал с базы, когда myenv (Python) выдавал сообщение о том, что jsonflatten не распознается как команда.

(base) C:\Users\samsung\.spyder-py3>jsonflatten C:\Users\samsung\.spyder-py3\forecast.json
Traceback (most recent call last):
  File "c:\users\samsung\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\samsung\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\samsung\Anaconda3\Scripts\jsonflatten.exe\__main__.py", line 7, in <module>
  File "c:\users\samsung\anaconda3\lib\site-packages\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\samsung\anaconda3\lib\site-packages\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "c:\users\samsung\anaconda3\lib\site-packages\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\samsung\anaconda3\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\users\samsung\anaconda3\lib\site-packages\click\decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\users\samsung\anaconda3\lib\site-packages\jsonflatten\cli.py", line 63, in main
    output(ctx, results, indent=4, is_json=True)
  File "c:\users\samsung\anaconda3\lib\site-packages\jsoncut\cli.py", line 59, in output
    output = highlighter.highlight_json(output)
  File "c:\users\samsung\anaconda3\lib\site-packages\jsoncut\highlighter.py", line 53, in highlight_json
    return pygments.highlight(d, JsonLexer(), formatter)
  File "c:\users\samsung\anaconda3\lib\site-packages\pygments\__init__.py", line 85, in highlight
    return format(lex(code, lexer), formatter, outfile)
  File "c:\users\samsung\anaconda3\lib\site-packages\pygments\__init__.py", line 64, in format
    formatter.format(tokens, realoutfile)
  File "c:\users\samsung\anaconda3\lib\site-packages\pygments\formatters\terminal.py", line 101, in format
    return Formatter.format(self, tokensource, outfile)
  File "c:\users\samsung\anaconda3\lib\site-packages\pygments\formatter.py", line 95, in format
    return self.format_unencoded(tokensource, outfile)
  File "c:\users\samsung\anaconda3\lib\site-packages\pygments\formatters\terminal.py", line 126, in format_unencoded
    outfile.write(ansiformat(color, line.rstrip('\n')))
  File "c:\users\samsung\anaconda3\lib\site-packages\pygments\console.py", line 68, in ansiformat
    result.append(codes[attr])
KeyError: 'darkgray'

В Anaconda есть руководство по устранению неполадок программного обеспечения: https://www.anaconda.com/what-to-do-when-things-go-wrong-in-anaconda/ но это совершенно новая установка.

Похоже ли это на проблему Anaconda, проблему с тем, как я запускаю программное обеспечение, или проблему с самим программным обеспечением?

1 Ответ

3 голосов
/ 15 февраля 2020

Вы получаете сообщение об ошибке в site-packages с модулем, который зависит от того, что вы установили.

Анаконда - это просто дистрибутив, а не среда выполнения.

Проблема в модуле Python pygments\console.py, который, вероятно, отвечает за окрашивание вывода вашего модуля jsonflatten.

Попробуйте проверить, есть ли флаг CLI, чтобы не раскрашивать вещи, или не использовать jsonflatten, а вместо этого использовать python s json.tool или отдельно установить jq вместо этого. (не говоря, что те предлагают то, что вам нужно, но они также анализируют JSON в CLI)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...