Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipenv activate command - activate the virtual environment in the current shell #5007

Closed
ericPrince opened this issue Mar 23, 2022 · 7 comments
Labels
Type: Enhancement 💡 This is a feature or enhancement request. Type: Possible Bug This issue describes a possible bug in pipenv.

Comments

@ericPrince
Copy link

Be sure to check the existing issues (both open and closed!), and make sure you are running the latest version of Pipenv.

Check the diagnose documentation for common issues and the PEEP list before posting! We may close your issue if it is very similar to one of them. Please be considerate and follow the PEEP process, or be on your way.

Make sure to mention your debugging experience if the documented solution failed.

Is your feature request related to a problem? Please describe.

I'd like to be able to use a pipenv command to activate the virtual environment for a project in the current shell. pipenv shell spawns a new shell (and often doesn't work in a containerized environment) and the alternative is to use shell commands, which is fine but less straightforward.

Describe the solution you'd like

A new command pipenv activate that does the equivalent of calling source activate for the virtual environment. Then a user can call the exsting virtualenv deactivate when they want to deactivate the environment.

Describe alternatives you've considered

My current workaround on bash is source $(dirname $(pipenv run which python))/activate. It's fine but not intuitive for someone not experienced with bash. It also breaks due to things like #5003 modifying stdout.

Additional context

Add any other context or screenshots about the feature request here. It may be a good idea to mention that platform and Python version you are on.


Please run $ pipenv --support, and paste the results here. Don't put backticks (`) around it! The output already contains Markdown formatting.

(removed because too long for max issue body)

@matteius matteius added Type: Enhancement 💡 This is a feature or enhancement request. Type: Possible Bug This issue describes a possible bug in pipenv. labels Mar 23, 2022
@oz123
Copy link
Contributor

oz123 commented Mar 23, 2022

This is probably not so straight forward. What I can offer is that we create an alias and inject it to the bash shell together with the bash-completions.
Something like:
pipenv-cur-shell.

@ericPrince
Copy link
Author

@oz123 understood, calling shell-specific commands from the existing shell process just might not be possible (this). I could be interested in having it as a bash-completion made available by pipenv. Also ok if the answer is just, you can't source a file in python, keep using source $(dirname $(pipenv run which python))/activate.

@smac89
Copy link
Contributor

smac89 commented Mar 25, 2022

What about pipenv run $SHELL?

@oz123
Copy link
Contributor

oz123 commented Mar 26, 2022

The run subcommand already creatures a subshell.
Only venue's activate avoids it.

@frostming
Copy link
Contributor

It is very easy to create an alias or shell function that does the following:

source $(pipenv --venv)/bin/activate

we are not going to implement it in pipenv.

@matteius
Copy link
Member

source $(pipenv --venv)/bin/activate

That would be a nice tid-bit to add to the docs at some point.

@ericPrince
Copy link
Author

Yeah, fine by me. For posterity, that command doesn't work in windows since virtual environment exes are placed in the "Scripts" folder. That's why I've been using source $(dirname $(pipenv run which python))/activate, so I can copy/paste the same thing wherever I am.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement 💡 This is a feature or enhancement request. Type: Possible Bug This issue describes a possible bug in pipenv.
Projects
None yet
Development

No branches or pull requests

5 participants