question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot install venv; toml.decoder.TomlDecodeError Found invalid character

See original GitHub issue

Issue description

When creating a virtual environment, I’m able to initially create the venv however there is an error which occurs after it is created. I’m using pyenv to manage my python versions.

✔ Successfully created virtual environment!

Then

toml.decoder.TomlDecodeError: Found invalid character in key name: '\'. Try quoting the key name. (line 1 column 2 char 1)

Expected result

When I run $ pipenv install --three I expect the venv to be created, and then be able to add packages to it.

The things I think it might be are:

  1. When looking at my python versions I see /Users/me/.pyenv/versions/3.7.1/bin/python3.7m and I’m not sure what the m is
  2. When creating the venv it’s looking for a Pipfile that does not exist in the project folder, but rather one directory up. And I’m not sure why it is looking there.

Any help would be appreciated.

Thanks!

Actual result

project git:(master) ✗ pipenv install --three
Creating a virtualenv for this project…
Pipfile: /Users/me/Documents/Pipfile
Using /usr/local/bin/python3.7m (3.7.2) to create virtualenv…
⠦ Creating virtual environment...Using base prefix '/Library/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/me/.local/share/virtualenvs/Documents-3uxKDUNM-“/Users/me/.pyenv/shims/python”/bin/python3.7m
Also creating executable in /Users/me/.local/share/virtualenvs/Documents-3uxKDUNM-“/Users/me/.pyenv/shims/python”/bin/python
Installing setuptools, pip, wheel...
done.
Running virtualenv with interpreter /usr/local/bin/python3.7m

✔ Successfully created virtual environment!
Traceback (most recent call last):
  File "/Users/me/src/pipenv/pipenv/project.py", line 522, in _parse_pipfile
    return tomlkit.parse(contents)
  File "/Users/me/src/pipenv/pipenv/vendor/tomlkit/api.py", line 49, in parse
    return Parser(string).parse()
  File "/Users/me/src/pipenv/pipenv/vendor/tomlkit/parser.py", line 132, in parse
    item = self._parse_item()
  File "/Users/me/src/pipenv/pipenv/vendor/tomlkit/parser.py", line 270, in _parse_item
    return self._parse_key_value(True)
  File "/Users/me/src/pipenv/pipenv/vendor/tomlkit/parser.py", line 339, in _parse_key_value
    raise self.parse_error(EmptyKeyError)
tomlkit.exceptions.EmptyKeyError: Empty key at line 1 col 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/me/.pyenv/versions/3.7.1/bin/pipenv", line 11, in <module>
    load_entry_point('pipenv', 'console_scripts', 'pipenv')()
  File "/Users/me/src/pipenv/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/me/src/pipenv/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/me/src/pipenv/pipenv/vendor/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/me/src/pipenv/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/me/src/pipenv/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/me/src/pipenv/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/Users/me/src/pipenv/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/me/src/pipenv/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/me/src/pipenv/pipenv/cli/command.py", line 251, in install
    editable_packages=state.installstate.editables,
  File "/Users/me/src/pipenv/pipenv/core.py", line 1803, in do_install
    pypi_mirror=pypi_mirror,
  File "/Users/me/src/pipenv/pipenv/core.py", line 554, in ensure_project
    pypi_mirror=pypi_mirror,
  File "/Users/me/src/pipenv/pipenv/core.py", line 486, in ensure_virtualenv
    python=python, site_packages=site_packages, pypi_mirror=pypi_mirror
  File "/Users/me/src/pipenv/pipenv/core.py", line 939, in do_create_virtualenv
    sources = project.pipfile_sources
  File "/Users/me/src/pipenv/pipenv/project.py", line 842, in pipfile_sources
    if "source" not in self.parsed_pipfile:
  File "/Users/me/src/pipenv/pipenv/project.py", line 504, in parsed_pipfile
    parsed = self._parse_pipfile(contents)
  File "/Users/me/src/pipenv/pipenv/project.py", line 526, in _parse_pipfile
    return toml.loads(contents)
  File "/Users/me/src/pipenv/pipenv/vendor/toml/decoder.py", line 227, in loads
    original, i)
toml.decoder.TomlDecodeError: Found invalid character in key name: '\'. Try quoting the key name. (line 1 column 2 char 1)

Steps to replicate

I’m not sure how to recreate this beyond the steps above.


$ pipenv --support

Pipenv version: '2018.11.27.dev0'

Pipenv location: '/Users/me/src/pipenv/pipenv'

Python location: '/Users/me/.pyenv/versions/3.7.1/bin/python3.7'

Python installations found:

  • 3.7.2: /usr/local/bin/python3
  • 3.7.2: /usr/local/bin/python3.7m
  • 3.7.1: /Users/me/.pyenv/versions/3.7.1/bin/python3
  • 3.7.1: /Users/me/.pyenv/versions/3.7.1/bin/python3.7m

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.7.1',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '18.2.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST '
                     '2018; root:xnu-4903.241.1~1/RELEASE_X86_64',
 'python_full_version': '3.7.1',
 'python_version': '3.7',
 'sys_platform': 'darwin'}

System environment variables:

  • LDFLAGS
  • TERM_PROGRAM
  • PIPENV_PYTHON
  • PYENV_ROOT
  • TERM
  • SHELL
  • TMPDIR
  • Apple_PubSub_Socket_Render
  • TERM_PROGRAM_VERSION
  • TERM_SESSION_ID
  • PYENV_VERSION
  • ZSH
  • USER
  • SSH_AUTH_SOCK
  • PYENV_DIR
  • __CF_USER_TEXT_ENCODING
  • PAGER
  • LSCOLORS
  • PATH
  • PWD
  • LANG
  • ITERM_PROFILE
  • PYENV_HOOK_PATH
  • XPC_FLAGS
  • XPC_SERVICE_NAME
  • PYENV_SHELL
  • SHLVL
  • HOME
  • COLORFGBG
  • CFLAGS
  • ITERM_SESSION_ID
  • LESS
  • LOGNAME
  • LC_CTYPE
  • CONFIGURE_OPTS
  • COLORTERM
  • PIP_DISABLE_PIP_VERSION_CHECK
  • PYTHONDONTWRITEBYTECODE
  • PIP_SHIMS_BASE_MODULE
  • PIP_PYTHON_PATH
  • PYTHONFINDER_IGNORE_UNSUPPORTED

Pipenv–specific environment variables:

  • PIPENV_PYTHON: “/Users/me/.pyenv/shims/python”

Debug–specific environment variables:

  • PATH: /Users/me/.pyenv/versions/3.7.1/bin:/Users/me/.pyenv/libexec:/Users/me/.pyenv/plugins/python-build/bin:/usr/local/opt/openssl/bin:/usr/local/bin:/Users/me/.pyenv/shims:/Users/me/.pyenv/shims:/Users/me/.pyenv/bin:/usr/bin:/bin:/usr/sbin:/sbin
  • SHELL: /bin/zsh
  • LANG: en_CA.UTF-8
  • PWD: /Users/me/project/

Contents of Pipfile (‘/Users/me/Documents/Pipfile’):

{\rtf1\ansi\ansicpg1252\cocoartf1671\cocoasubrtf200
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0

\f0\fs24 \cf0 [[source]]\
name = "pypi"\
url = "https://pypi.org/simple"\
verify_ssl = true\
[dev-packages]\
[packages]\
pandas = "*"\
numpy = "*"\
matplotlib = "*"\
sklearn = "*"\
psycopg2 = "*"\
jupyter = "*"\
pystan = "*"\
fbprophet = "*"\
scipy = "*"\
ipykernel = "*"\
autopep8 = "*"\
jupyter-contrib-nbextensions = "*"\
jupyter-nbextensions-configurator = "*"\
[requires]\
python_version = "3.7"}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
michael-burtcommented, Aug 21, 2019

I am having the same issue. It started after I removed my pycache in my package folder. I uninstalled pipenv and I am still hitting the same error. I removed pipenv and all associated venv’s and I still cannot get it to work. Any help would be appreciated.


To close this, I had a malformed Pipfile.

3reactions
adaminfinitumcommented, Mar 14, 2020

I’m new to pipenv and so it’s trying to convert my requirements.txt file but that file includes specific subset libraries in brackets (e.g. django-webserver[pyuwsgi]). How do I make this work?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to solve toml.decoder.TomlDecodeError: Key group not ...
Just delete the config.toml file which can be found in the directory where you have installed streamlit.
Read more >
Python Examples of toml.TomlDecodeError - ProgramCreek.com
This page shows Python examples of toml.TomlDecodeError.
Read more >
alg_final_stuff - .. - toml - decoder.py - Whitgit
raise TomlDecodeError("Found invalid character in key name: '" +. 261. item + "'. Try quoting the key name.",. 262. original, i).
Read more >
Toml docoder error - Deploying Streamlit
As of this evening, I cannot do anything with streamlit, not even run the ... TomlDecodeError: Found invalid character in key name: '#'....
Read more >
pipenv Documentation - Read the Docs
Makefile, direct calls to pip and python -m venv or virtualenv. to create virtual environments and install pack- ages in them. Pipenv uses...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found