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

deactivate command not available in shell scripts or sub-shells (activate script does not export "deactivate") #2654

Closed
geopanther opened this issue Oct 20, 2023 · 1 comment
Labels

Comments

@geopanther
Copy link

Issue

When activating an venv environment, the command "deactivate" is only available in the current instance of the shell and not in a shellscript (a shellscript is always executed in sub-shell (separate instance)) or any subshel

Environment

Provide at least:

  • OS: macOS Big Sur 11.7.10 (20G1427)
  • Using bash version "3.2.57(1)-release" from Homebrew
  • pip list of the host python where virtualenv is installed:
$ pip list
Package    Version
---------- -------
pip        23.2.1
setuptools 56.0.0

Output of the virtual environment creation

Make sure to run the creation with -vvv --with-traceback:

$ python3 --with-traceback -vvv -m venv .venv_py3.11
unknown option --with-traceback
usage: /Library/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.
$ python3 -vvv -m venv .venv_py3.11

-> see attached console-output.txt

Steps to reproduce:

$ source .venv_py3.11/bin/activate
$ bash
$ deactivate
bash: deactivate: command not found
$ exit
exit
$ deactivate
$

Suggested solution:
Add export -f deactivate to <virtual_env_dir>/bin/activate

@geopanther geopanther added the bug label Oct 20, 2023
@gaborbernat
Copy link
Contributor

That will still keep the activation in the first shell as it's not possible to change parent shell envs, so this would cause more confusion than benefit.

@gaborbernat gaborbernat closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants