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

Created on 7 Mar 2019  Â·  7Comments  Â·  Source: pypa/pipenv

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"}

Status Needs More Information

Most helpful comment

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.

All 7 comments

@kimiagharib How did you get all those garbage characters in your Pipfile(marked in red background)?

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.

Can confirm the problem is a malformed Pipfile. Just remove any listed packages.

@kimiagharib can this be closed? It appears that the issue was a malformed Pipfile.

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?

I had a similar issue

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
chardet = "3.0.4"
Click = "7.0"
idna = "2.8"
itsdangerous = "1.1.0"
Jinja2 = "2.10.1"
python-dotenv = "0.10.3"
requests = "2.22.0"
stripe = "2.29.3"
toml = "0.9.6"
urllib3 = "1.25.3"
Werkzeug = "0.15.4"


[requires]
python_version = "3.8"

I used to get this

Traceback (most recent call last):
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/bin/pipenv", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/cli/command.py", line 235, in install
    retcode = do_install(
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/core.py", line 1751, in do_install
    pre = project.settings.get("allow_prereleases")
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/project.py", line 557, in settings
    return self.parsed_pipfile.get("pipenv", {})
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/project.py", line 509, in parsed_pipfile
    parsed = self._parse_pipfile(contents)
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/project.py", line 531, in _parse_pipfile
    return toml.loads(contents)
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/lib/python3.8/site-packages/pipenv/vendor/toml/decoder.py", line 458, in loads
    raise TomlDecodeError(str(err), original, pos)
toml.decoder.TomlDecodeError: Invalid date or number (line 9 column 1 char 103)

Then I solve it by not identifying the package version like this with a star in between the quotation the Github fails to show it :

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
certifi="*"
chardet="*"
Click="*"
Flask="*"
idna="*"
itsdangerous="*"
Jinja2="*"
MarkupSafe="*"
python-dotenv="*"
requests="*"
stripe="*"
toml="*"
urllib3="*"
Werkzeug="*"

[requires]
python_version = "3.8"

For the record: the garbage at the beginning of the OP's Pipfile is RTF formatting.

Was this page helpful?
0 / 5 - 0 ratings