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.

pipenv only works in an activated shell

See original GitHub issue

Reproducible example:

$ python3 -m venv env
$ env/bin/pip install pipenv
<snip>
$ env/bin/pipenv install pyramid
Creating a Pipfile for this project...
Creating a virtualenv for this project...
Traceback (most recent call last):
  File "env/bin/pipenv", line 11, in <module>
    load_entry_point('pipenv==4.1.4', 'console_scripts', 'pipenv')()
  File "/Users/michael/work/oss/pipenv/env/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Users/michael/work/oss/pipenv/env/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Users/michael/work/oss/pipenv/env/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/michael/work/oss/pipenv/env/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/michael/work/oss/pipenv/env/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/michael/work/oss/pipenv/env/lib/python3.6/site-packages/pipenv/cli.py", line 801, in install
    ensure_project(three=three, python=python)
  File "/Users/michael/work/oss/pipenv/env/lib/python3.6/site-packages/pipenv/cli.py", line 155, in ensure_project
    ensure_virtualenv(three=three, python=python)
  File "/Users/michael/work/oss/pipenv/env/lib/python3.6/site-packages/pipenv/cli.py", line 135, in ensure_virtualenv
    do_create_virtualenv(three=three, python=python)
  File "/Users/michael/work/oss/pipenv/env/lib/python3.6/site-packages/pipenv/cli.py", line 388, in do_create_virtualenv
    c = delegator.run(cmd, block=False)
  File "/Users/michael/work/oss/pipenv/env/lib/python3.6/site-packages/pipenv/vendor/delegator.py", line 247, in run
    c.run(block=block, binary=binary)
  File "/Users/michael/work/oss/pipenv/env/lib/python3.6/site-packages/pipenv/vendor/delegator.py", line 146, in run
    s = PopenSpawn(self._popen_args, **pexpect_kwargs)
  File "/Users/michael/work/oss/pipenv/env/lib/python3.6/site-packages/pipenv/vendor/pexpect/popen_spawn.py", line 45, in __init__
    self.proc = subprocess.Popen(cmd, **kwargs)
  File "/Users/michael/.pyenv/versions/3.6.1/lib/python3.6/subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "/Users/michael/.pyenv/versions/3.6.1/lib/python3.6/subprocess.py", line 1326, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'pew'

Expected: A new pipenv virtualenv is created with pyramid installed and the pipfile updated similar to how things work if I run:

$ python3 -m venv env
$ env/bin/pip install pipenv
$ source env/bin/activate
(env) $ pipenv install pyramid

This is a common problem with programs that shell out without activating the virtualenv but it does make things a bit more difficult for people who do not need to activate 99% of the time and prefer being explicit about what python they are using. There are several workarounds but one is to prepend the virtualenv’s bin/scripts folder to the path before shelling out via os.path.join(os.environ('VIRTUAL_ENV'], bin_or_scripts).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
mmerickelcommented, Sep 7, 2017

As someone who has contributed to pipsi and watches its repo and uses / maintains a fork I can tell you that it’s almost entirely unmaintained… I’m not sure that’s a great installation method to recommend to people. It hasn’t had a release in over 2 years and the get-pipsi.py script installs the version from pypi, not the one from the repository. On top of that those installation instructions are currently semi-broken if you don’t have the virtualenv command on your path. It’s of course installed into the python that I’m using to run pipenv, but the virtualenv command should again be found relative to the python that’s running, not the system command (similar issue as this one with pew).

Note below the usage of .local/bin/pew from pipsi. I know it’s hard to get this all isolated when using subprocesses but I maintain that it’s an important thing to do to make a tool that’s easily installable without a bunch of assumptions on the installed environment. pipsi is able to find virtualenv but later pipenv/pew cannot

$ pipsi install pew
$ pipsi install pipenv
$ pipenv install
Creating a virtualenv for this project...
⠋Traceback (most recent call last):
  File "/Users/michael/.local/bin/pew", line 11, in <module>
    sys.exit(pew())
  File "/Users/michael/.local/venvs/pew/lib/python3.6/site-packages/pew/pew.py", line 737, in pew
    return command(sys.argv[2:])
  File "/Users/michael/.local/venvs/pew/lib/python3.6/site-packages/pew/pew.py", line 253, in new_cmd
    args.requirements, rest)
  File "/Users/michael/.local/venvs/pew/lib/python3.6/site-packages/pew/pew.py", line 215, in mkvirtualenv
    check_call(["virtualenv", envname] + rest, cwd=str(workon_home))
  File "/Users/michael/.pyenv/versions/3.6.1/lib/python3.6/subprocess.py", line 286, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/Users/michael/.pyenv/versions/3.6.1/lib/python3.6/subprocess.py", line 267, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/Users/michael/.pyenv/versions/3.6.1/lib/python3.6/subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "/Users/michael/.pyenv/versions/3.6.1/lib/python3.6/subprocess.py", line 1326, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'virtualenv'

Virtualenv location:
Traceback (most recent call last):
  File "/Users/michael/.local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/Users/michael/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Users/michael/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Users/michael/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/michael/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/michael/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/michael/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/cli.py", line 1057, in shell
    with open(activate_this) as f:
FileNotFoundError: [Errno 2] No such file or directory: '/bin/activate_this.py'
1reaction
kennethreitzcommented, Sep 7, 2017

@mmerickel patches welcome!

Read more comments on GitHub >

github_iconTop Results From Across the Web

pipenv: only works in a installed folder? - Stack Overflow
To easily activate a virtual environment anywhere with pipenv, ... Yes, Pipenv only works in the directory that the Pipfile is in (or...
Read more >
Frequently Encountered Pipenv Problems - Read the Docs
This is usually a result of mixing Pipenv with system packages. We strongly recommend installing Pipenv in an isolated environment. Uninstall all existing ......
Read more >
How to Manage your Python Projects with Pipenv and Pyenv
Another important thing to remember is to activate the created virtual environment, which you do by running: pipenv shell.
Read more >
Advanced Usage of Pipenv - Python Packaging Authority
Starting in release 2022.3.23 all packages are mapped only to a single package ... To activate this project's virtualenv, run the following: $...
Read more >
Python Environment 101 - Towards Data Science
You can activate the project's virtualenv by running pipenv shell , and deactivate it by running exit . pipenv shell to upgrade a...
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