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

Annoying venv warning #13875

Open
jamilraichouni opened this issue Dec 23, 2022 · 7 comments
Open

Annoying venv warning #13875

jamilraichouni opened this issue Dec 23, 2022 · 7 comments

Comments

@jamilraichouni
Copy link

jamilraichouni commented Dec 23, 2022

Hi!

Using ipython 8.7.0 I just identified that the block below always triggers the annoying warning when I run ipython within a pyenv venv.

if self.warn_venv:
warn(
"Attempting to work in a virtualenv. If you encounter problems, "
"please install IPython inside the virtualenv."
)

The instance variable warn_venv occurs two times in the whole module (here both locations in the snippets cutout) and seems to be always true.

warn_venv = Bool(
True,
help="Warn if running in a virtual environment with no IPython installed (so IPython from the global environment is used).",
).tag(config=True)

I see no point to always get that message although I clearly run the ipython executable in the currently active venv.

Maybe my symlink setup causes that?

Here you see something in my neovim session.

Top pane: the module where above code listings come from
Middle pane: vars in a debug session in pdb
Bottom pane: my symlink of $HOME/.pyenv and the env var VIRTUAL_ENV

Maybe someone wants to look deeper into that scenario. For now it looks like a warning that should not appear in this case and I disable it.

I wish a Merry Christmas,
Jamil

image

@cbrnr
Copy link
Contributor

cbrnr commented Dec 23, 2022

Is your IPython installed in the venv or do you use a global IPython? The latter will cause the warning to appear, and the solution is to disable it in your config.

@jamilraichouni
Copy link
Author

The stuff runs in a Docker container. There I have a global Python 3.10.8 and a venv created via pyenv.
Both (globally and venv) have IPython installed.
I have the venv activated using a .python-version file and oh-my-zsh with the python plugin installed also indicates that in parallel to a set env var VIRTUAL_ENV.
When I then execute the command ipython in the root dir of my Python project/ repo I get that warning.

I can try to provide a Dockerfile that will hopefully give everything to be able to reproduce that scenario.
Would that help?

@cbrnr
Copy link
Contributor

cbrnr commented Dec 23, 2022

Both (globally and venv) have IPython installed.

Maybe that's the problem. It might be that you start the global ipython even when your venv is activated. That's when you see the warning.

So either you start ipython installed in your venv, or you set c.InteractiveShell.warn_venv = False in your config.

Do these solutions not work for you? I found the warning also very annoying, and that's why I added the config option to suppress it.

@jamilraichouni
Copy link
Author

Well the following screenshot tells (at least) me, that the IPython installed in the venv is being executed while I get the mentioned warning:

image

Thanks for the pointer to the cfg option. That is a better solution than commenting the warning. Nevertheless I assume that the warning is not supposed to appear anyway when I run the ipython executable that has been installed in the venv which is currently active.

@cbrnr
Copy link
Contributor

cbrnr commented Dec 23, 2022

Yes, it looks like you are running ipython from your env. To be sure, can you also activate your venv and then run python -m IPython? If the warning still appears, there might indeed be something wrong (maybe venv detection is not working in your case).

@jamilraichouni
Copy link
Author

jamilraichouni commented Dec 23, 2022

Doing so with the warning not disabled via my profile cfg I get the same warning:

image

@RazerM
Copy link
Contributor

RazerM commented Oct 9, 2023

I am using pyenv and pyenv-virtualenv

If I stop my debugger on this line:

if any(p_venv == p.parents[1] for p in paths):

and print the variables, we get

In [1]: p_venv
Out[1]: PosixPath('/Users/<username>/.pyenv/versions/3.10.6/envs/foo')
In [2]: paths
Out[2]: 
[PosixPath('/Users/<username>/.pyenv/versions/foo/bin/python'),
 PosixPath('/Users/<username>/.pyenv/versions/foo/bin/python3.10'),
 PosixPath('/Users/<username>/.pyenv/versions/3.10.6/bin/python3.10')]

So the issue seems to be that VIRTUAL_ENV is used literally to check if it's a parent of sys.executable, when that is not the case here. /Users/<username>/.pyenv/versions/foo is a symlink to /Users/<username>/.pyenv/versions/3.10.6/envs/foo.

In [3]:os.path.realpath(p_venv / "bin/python3")
Out[3]: '/Users/<username>/.pyenv/versions/3.10.6/bin/python3.10'
In [4]:os.path.realpath(sys.executable)
Out[4]: '/Users/<username>/.pyenv/versions/3.10.6/bin/python3.10'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants