-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Make better prediction of the virtualenv site-packages version #12752
Conversation
Try to make prediction of the Python's site-package version used by virtualenv. If predicted path doesn't exist, continue with previous behaviour. This can be useful while working with different Python versions in virtual environments other than system-used (previously provided via `sys.version_info`). Note that this *only* updates $PYTHONPATH, so 3rd-libraries installed in virtualenv will be avialable. However the Python interpreter contiunues to be other than the bundled in the virtualenv (see `init_virtualenv()` docstring).
This is interesting fix at 62e6c27. This bug also existed in the current diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py
index 1770b4f67..ded20f975 100644
--- a/IPython/core/interactiveshell.py
+++ b/IPython/core/interactiveshell.py
@@ -932,7 +932,7 @@ def init_virtualenv(self):
return
if sys.platform == "win32":
- virtual_env = Path(os.environ["VIRTUAL_ENV"], "Lib", "site-packages")
+ virtual_env = str(Path(os.environ["VIRTUAL_ENV"], "Lib", "site-packages"))
else:
venv_path_prefix = Path(os.environ["VIRTUAL_ENV"], "lib")
venv_path_suffix = Path("site-packages") On the other hand, AppVeyor build passes. Strange. I don't have access to Windows to test it myself. |
OK. The PR is ready to review. I can also add a commit proposed in the #12752 (comment) Let me know what do you think. Thanks. |
Thanks, and apologies for the delay. This looks good to me and I'll trust you a s virtualenv user. |
This PR improves virtualenv integration.
Current implementation assumes that the Python used in virtualenv is in the same version as the Python that is being used to run IPython. This is definitely not truth in most cases. In fact, one of the purpose of using virtualenv is to run different Python's interpreter versions. So the assumption is in opposite of the one of principal goals of the virtualenv idea.
This PR predicts a proper path to the virtualenv's libraries by looking-up at
$VIRTUAL_ENV
environmental variable againstpythonX.Y
orpyX.Y
substrings. The$VIRTUAL_ENV
usually contains Python's version in the name, e.g.project-name-py3.7
,project-name-py3.8
. If predicted path doesn't exist, the previous functionality is proceed.Example:
Results:
$VIRTUAL_ENV/lib/python3.9/site-packages
$VIRTUAL_ENV/lib/python3.7/site/packages