Skip to content

'pipenv clean' fails when running in an existing virtualenv #3231

@rectalogic

Description

@rectalogic

Issue description

I create and activate my own virtualenv, pipenv reports it is running in an existing virtualenv. I install a package and then run pipenv clean which fails (it attempts to decode an empty string as JSON).

Expected result

pipenv should clean the existing virtualenv

Actual result

Raises exception.

I set a breakpoint where it loads the json, and it looks like it created it's own virtualenv instead of using the active one:

(env) cureatr@cureatr-vm /tmp/testing> ~/.local/bin/pipenv clean
> /home/cureatr/.local/lib/python2.7/site-packages/pipenv/environment.py(198)sys_path()
-> path = json.loads(path.strip())
(Pdb) p path
''
(Pdb) p self.python
'/home/cureatr/.local/share/virtualenvs/testing-OQkenIEh/bin/python'
(Pdb) p sys.executable
'/usr/bin/python'
(Pdb) p self.is_venv
True
(Pdb) p self.prefix
PosixPath('/home/cureatr/.local/share/virtualenvs/testing-OQkenIEh')

However /home/cureatr/.local/share/virtualenvs directory is empty.

Steps to replicate

cureatr@cureatr-vm /tmp/testing> pip install --user pipenv
Collecting pipenv
  Using cached https://files.pythonhosted.org/packages/f0/7a/b890abdae65a505d3a49caacfdd14525c4ad747e6ecb57b23710150eea82/pipenv-2018.11.14-py2-none-any.whl
Requirement already satisfied: enum34; python_version < "3" in /usr/lib/python2.7/dist-packages (from pipenv) (1.1.6)
Requirement already satisfied: virtualenv in /usr/local/lib/python2.7/dist-packages (from pipenv) (16.0.0)
Collecting typing; python_version < "3.5" (from pipenv)
  Using cached https://files.pythonhosted.org/packages/cc/3e/29f92b7aeda5b078c86d14f550bf85cff809042e3429ace7af6193c3bc9f/typing-3.6.6-py2-none-any.whl
Requirement already satisfied: certifi in /usr/local/lib/python2.7/dist-packages (from pipenv) (2018.8.24)
Collecting virtualenv-clone>=0.2.5 (from pipenv)
  Using cached https://files.pythonhosted.org/packages/16/9d/6419a4f0fe4350db7fdc01e9d22e949779b6f2d2650e4884aa8aededc5ae/virtualenv_clone-0.4.0-py2.py3-none-any.whl
Requirement already satisfied: pip>=9.0.1 in /usr/local/lib/python2.7/dist-packages (from pipenv) (18.1)
Collecting setuptools>=36.2.1 (from pipenv)
  Using cached https://files.pythonhosted.org/packages/e7/16/da8cb8046149d50940c6110310983abb359bbb8cbc3539e6bef95c29428a/setuptools-40.6.2-py2.py3-none-any.whl
Installing collected packages: typing, virtualenv-clone, setuptools, pipenv
  The script virtualenv-clone is installed in '/home/cureatr/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  The scripts pipenv and pipenv-resolver are installed in '/home/cureatr/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pipenv-2018.11.14 setuptools-40.6.2 typing-3.6.6 virtualenv-clone-0.4.0

cureatr@cureatr-vm /tmp/testing> virtualenv env
New python executable in /tmp/testing/env/bin/python
Installing setuptools, pip, wheel...done.
cureatr@cureatr-vm /tmp/testing> source env/bin/activate

(env) cureatr@cureatr-vm /tmp/testing> ~/.local/bin/pipenv --venv
Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
No virtualenv has been created for this project yet!
Aborted!

(env) cureatr@cureatr-vm /tmp/testing> ~/.local/bin/pipenv install six
Creating a Pipfile for this project...
Installing six...
Adding six to Pipfile's [packages]...
✔ Installation Succeeded
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
✔ Success!
Updated Pipfile.lock (060c30)!
Installing dependencies from Pipfile.lock (060c30)...
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 1/1 — 00:00:00

(env) cureatr@cureatr-vm /tmp/testing> ~/.local/bin/pipenv clean
Traceback (most recent call last):
  File "/home/cureatr/.local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/cli/command.py", line 620, in clean
    do_clean(ctx=ctx, three=state.three, python=state.python, dry_run=dry_run)
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/core.py", line 2619, in do_clean
    in project.environment.get_installed_packages()
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/environment.py", line 281, in get_installed_packages
    workingset = self.get_working_set()
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/environment.py", line 390, in get_working_set
    working_set = pkg_resources.WorkingSet(self.sys_path)
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/vendor/cached_property.py", line 35, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/home/cureatr/.local/lib/python2.7/site-packages/pipenv/environment.py", line 197, in sys_path
    path = json.loads(path.strip())
  File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

$ pipenv --support

Pipenv version: '2018.11.14'

Pipenv location: '/home/cureatr/.local/lib/python2.7/site-packages/pipenv'

Python location: '/usr/bin/python'

Python installations found:

  • 3.6.6: /usr/bin/python3.6
  • 3.6.6: /usr/bin/python3.6m
  • 2.7.15rc1: /usr/bin/python2.7

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '0',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '4.15.0-36-generic',
 'platform_system': 'Linux',
 'platform_version': '#39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018',
 'python_full_version': '2.7.15rc1',
 'python_version': '2.7',
 'sys_platform': 'linux2'}

System environment variables:

  • PYTHONDONTWRITEBYTECODE
  • LESSOPEN
  • SSH_CLIENT
  • LOGNAME
  • USER
  • PATH
  • HOME
  • PS1
  • LANG
  • TERM
  • SHELL
  • SHLVL
  • PWD
  • CUREATR_SERVER
  • PYTHONFINDER_IGNORE_UNSUPPORTED
  • PROCESSOR_CONFIG
  • XDG_RUNTIME_DIR
  • PYTHONPATH
  • S_COLORS
  • TMUX
  • PIP_PYTHON_PATH
  • XDG_SESSION_ID
  • _
  • LS_COLORS
  • LESSCLOSE
  • CUREATR_EXTMSG
  • SSH_TTY
  • OLDPWD
  • CUREATR_HOME
  • CUREATR_WEB
  • PIP_SHIMS_BASE_MODULE
  • PIP_DISABLE_PIP_VERSION_CHECK
  • MAIL
  • SSH_CONNECTION
  • TMUX_PANE

Pipenv–specific environment variables:

Debug–specific environment variables:

  • PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
  • SHELL: /bin/bash
  • LANG: en_US.UTF-8
  • PWD: /tmp/testing

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: Possible BugThis issue describes a possible bug in pipenv.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions