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

Python venv (virtualenv) not working #1038

Closed
clo4 opened this issue Mar 7, 2022 · 7 comments
Closed

Python venv (virtualenv) not working #1038

clo4 opened this issue Mar 7, 2022 · 7 comments
Labels
codebase:shell-integrations Shell integrations type:bug Something isn't working
Milestone

Comments

@clo4
Copy link
Contributor

clo4 commented Mar 7, 2022

Need more info. If you're having this issue please let us know and give some relevant info, like:

  • Python version
  • What tools are you using to create/use your venvs? (python -m venv, pipenv, virtualenvwrapper, poetry, VSCode, etc)
  • Fig version (fig --version)
@clo4 clo4 added type:bug Something isn't working codebase:_UNSURE_ labels Mar 7, 2022
@mzeeb
Copy link

mzeeb commented Mar 8, 2022

Ran into this issue where the venv does not work properly in combination with PyCharm Professional 2021.3.2. When opening the "Terminal" Tab the venv will not automatically be activated when Fig is installed. But the venv itself works!

image

  • macOS Montery 12.2.1 - Python 3.9.10 (Ignore 3.8 In the Screenshot this is just the Interpreter name)
  • python3 -m venv
  • fig version 1.0.55 B383

Hit me up if you need more information

@chrisgrande
Copy link

chrisgrande commented Mar 9, 2022

I've hit this issue as well:

  • macOS Monetary 12.2.1
  • Python 3.9.10
  • Creation via virtualenv by hand or via PyCharm's UI
  • fig version 1.0.55 B383

@clo4
Copy link
Contributor Author

clo4 commented Mar 11, 2022

Hmmm.... thank you for that information! @mzeeb @chrisgrande

I can confirm this behavior locally too.

Got a suspicion that this is #446 in disguise - it would make sense that it's launching the shell with the activate command, but the fig shell integration is eating it.

@duongleh
Copy link

duongleh commented Mar 18, 2022

Got the same issue

  • Python 3.9.10, 3.8.12, 3.7.12
  • Create venv via PyCharm's UI
  • fig --version returns 1.3.0 but the menu bar displays 1.0.56 (B414)

When starts a new shell session in Pycharm, the vevn is not activated although the setting is already enabled.
Screen Shot 2022-03-19 at 12 18 43 AM

@overcat
Copy link

overcat commented Mar 25, 2022

It looks like the _jedi_precmd_hook in .zshenv is not being executed, a temporary solution is to copy the contents of .zshenv to the bottom of ~/.zshrc, .zshenv is located at /Users/username/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-1/213.7172.26/PyCharm.app/Contents/plugins/terminal/.zshenv (MacOS)

.zshenv content:

# Injecting code in user Zsh rc files is a delicate business.
# We prefix all builtins to avoid accidentally calling into
# user-defined functions. Up until we disable alias expansion
# we also quote every word to prevent accidental alias
# expansion. We also clean up after ourselves so that no
# temporary parameters or functions are left over once we are
# done.
#
# According to http://zsh.sourceforge.net/Doc/Release/Files.html, zsh startup configuration files are read in this order:
# 1. /etc/zshenv
# 2. $ZDOTDIR/.zshenv
# 3. /etc/zprofile (if shell is login)
# 4. $ZDOTDIR/.zprofile (if shell is login)
# 5. /etc/zshrc (if shell is interactive)
# 6. $ZDOTDIR/.zshrc (if shell is interactive)
# 7. /etc/zlogin (if shell is login)
# 8. $ZDOTDIR/.zlogin (if shell is login)
#
# If ZDOTDIR is unset, HOME is used instead.

# This file is read, because IntelliJ launches zsh with custom ZDOTDIR.
# Restore ZDOTDIR original value to load further zsh startup files correctly.
if [[ -n "$_INTELLIJ_ORIGINAL_ZDOTDIR" ]]; then
  ZDOTDIR="$_INTELLIJ_ORIGINAL_ZDOTDIR"
  'builtin' 'unset' '_INTELLIJ_ORIGINAL_ZDOTDIR'
else
  # defaults ZDOTDIR to HOME
  'builtin' 'unset' 'ZDOTDIR'
fi

# Source original $ZDOTDIR/.zshenv manually
if [[ -f "${ZDOTDIR:-$HOME}"/.zshenv ]]; then
  'builtin' 'source' '--' "${ZDOTDIR:-$HOME}"/.zshenv
fi

# Bind Ctrl+Left and Ctrl+Right in the main keymap (usually emacs)
# to cursor movement by words.
'builtin' 'bindkey' '^[^[[C' 'forward-word'
'builtin' 'bindkey' '^[^[[D' 'backward-word'

# Stop right here if this is not interactive shell.
[[ -o 'interactive' ]] || 'builtin' 'return' '0'

'builtin' 'typeset' '-i' '_jedi_restore_aliases'
if [[ -o 'aliases' ]]; then
  'builtin' 'setopt' 'no_aliases'
  # No need to quote everything after this point because aliases
  # are disabled. We didn't do this earlier because we must source
  # the user's .zshenv with the default shell options.
  _jedi_restore_aliases=1
fi

# This function will be called after all rc files are processed
# and before the first prompt is displayed.
function _jedi_precmd_hook() {
  builtin setopt local_options unset # to treat unset JEDITERM_SOURCE as empty
  if [[ -n "$JEDITERM_SOURCE" ]]; then
    # TODO: Is it correct to split JEDITERM_SOURCE_ARGS on IFS and
    # drop empty arguments? Bash integration does it and it looks
    # intentional.
    builtin source -- "$JEDITERM_SOURCE" ${=JEDITERM_SOURCE_ARGS}
  fi
  builtin unset JEDITERM_SOURCE JEDITERM_SOURCE_ARGS

  # Enable native zsh options to make coding easier.
  builtin emulate -L zsh
  builtin zmodload zsh/parameter 2>/dev/null

  builtin local var
  # For every _INTELLIJ_FORCE_SET_FOO=BAR run: export FOO=BAR.
  for var in ${parameters[(I)_INTELLIJ_FORCE_SET_*]}; do
    builtin export ${var:20}=${(P)var}
    builtin unset $var
  done
  # For every _INTELLIJ_FORCE_PREPEND_FOO=BAR run: export FOO=BAR$FOO.
  for var in ${parameters[(I)_INTELLIJ_FORCE_PREPEND_*]}; do
    builtin local name=${var:24}
    builtin export $name=${(P)var}${(P)name}
    builtin unset $var
  done

  # Remove the hook and the function.
  builtin typeset -ga precmd_functions
  precmd_functions=(${precmd_functions:#_jedi_precmd_hook})
  builtin unset -f _jedi_precmd_hook
}

builtin typeset -ga precmd_functions
precmd_functions+=(_jedi_precmd_hook)

(( _jedi_restore_aliases )) && builtin setopt aliases
'builtin' 'unset' '_jedi_restore_aliases'

@mschrage
Copy link
Member

Related to #1069

@mschrage
Copy link
Member

PS. @overcat @duong-le @chrisgrande @mzeeb I think I've figured out what's going wrong here. Thank you for all of the debugging information you've provided. It was really helpful.

This should be fixed in the next release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codebase:shell-integrations Shell integrations type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants