Repository: ipython/ipython

Issue:
IPython-8 warns about virtualenv created by pyenv
Hi, is there a way to disable the virtualenv warning?

I use pyenv, and every time IPython-8.0 starts from a virtual environment that's based on pyenv's miniconda, it shows this warning:

```bash
# Activate virtualenv via 'pyenv activate my_project_env' or 'pyenv activate my_base_python_env/envs/my_project_env'.
...

# Then, start ipython (installed in that virtual env).
$ ipython
/Users/xxx/.pyenv/versions/rubix-mds/lib/python3.9/site-packages/IPython/core/interactiveshell.py:802: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
  warn(
Python 3.9.7 (default, Sep 16 2021, 08:50:36) 
Type 'copyright', 'credits' or 'license' for more information
IPython 8.0.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import sys
   ...: 
   ...: sys.executable
Out[1]: '/Users/xxx/.pyenv/versions/rubix-mds/bin/python'

In [2]: import os
   ...: 
   ...: os.environ["VIRTUAL_ENV"]
Out[2]: '/Users/xxx/.pyenv/versions/miniconda3-latest/envs/rubix-mds'
```

This only happens for virtualenv based on another pyenv's miniconda3-latest. No warning shown with virtualenv based on another pyenv's "python version".

```bash
$HOME
`-- versions
    |-- miniconda3-latest
    |   `-- envs
    |       `-- rubix-mds
    `-- rubix-mds -> $HOME/.pyenv/versions/miniconda3-latest/envs/rubix-mds
```

I'd like to know if there's a way to silent this particular warning?

Thank you.


Discussion:
Hum, I would have to try, but see if you can use `warnings.filterwarnings` in one of the [startup files](https://ipython.readthedocs.io/en/stable/interactive/tutorial.html?highlight=startup#startup-files).

I'f not we can add a flag/config option to silence it.
I have the same problem as @verdimrc. Note that the IPython that is executed is actually installed in the virtualenv. I started noticing this problem with IPython 7.28.0.
+1 for a config option to silence this warning. I'm using IPython via pipx, precisely because I didn't want to install it in every venv.

Edit: I added the following lines to `~/.ipython/profile_default/startup/00-startup.py`, but the warning still shows up:

```python
from warnings import filterwarnings

filterwarnings("ignore", "Attempting to work in a virtualenv")
```

Besides, this would make `filterwarnings` available in the global namespace, so I'd prefer a config option to hide the warning.

Resolving patch:
diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py
--- a/IPython/core/interactiveshell.py
+++ b/IPython/core/interactiveshell.py
@@ -479,6 +479,11 @@ def input_splitter(self):
         """
     ).tag(config=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)
+
     # TODO: this part of prompt management should be moved to the frontends.
     # Use custom TraitTypes that convert '0'->'' and '\\n'->'\n'
     separate_in = SeparateUnicode('\n').tag(config=True)
@@ -847,11 +852,11 @@ def init_virtualenv(self):
                     p_ver = re_m.groups()
 
             virtual_env = str(virtual_env_path).format(*p_ver)
-
-        warn(
-            "Attempting to work in a virtualenv. If you encounter problems, "
-            "please install IPython inside the virtualenv."
-        )
+        if self.warn_venv:
+            warn(
+                "Attempting to work in a virtualenv. If you encounter problems, "
+                "please install IPython inside the virtualenv."
+            )
         import site
         sys.path.insert(0, virtual_env)
         site.addsitedir(virtual_env)


Test patch: