Show More
@@ -898,9 +898,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
898 | virtualenv was built, and it ignores the --no-site-packages option. A |
|
898 | virtualenv was built, and it ignores the --no-site-packages option. A | |
899 | warning will appear suggesting the user installs IPython in the |
|
899 | warning will appear suggesting the user installs IPython in the | |
900 | virtualenv, but for many cases, it probably works well enough. |
|
900 | virtualenv, but for many cases, it probably works well enough. | |
901 |
|
||||
902 | Adapted from code snippets online. |
|
901 | Adapted from code snippets online. | |
903 |
|
||||
904 | http://blog.ufsoft.org/2009/1/29/ipython-and-virtualenv |
|
902 | http://blog.ufsoft.org/2009/1/29/ipython-and-virtualenv | |
905 | """ |
|
903 | """ | |
906 | if 'VIRTUAL_ENV' not in os.environ: |
|
904 | if 'VIRTUAL_ENV' not in os.environ: | |
@@ -931,17 +929,27 b' class InteractiveShell(SingletonConfigurable):' | |||||
931 | # Our exe is inside or has access to the virtualenv, don't need to do anything. |
|
929 | # Our exe is inside or has access to the virtualenv, don't need to do anything. | |
932 | return |
|
930 | return | |
933 |
|
931 | |||
934 | warn("Attempting to work in a virtualenv. If you encounter problems, please " |
|
|||
935 | "install IPython inside the virtualenv.") |
|
|||
936 | if sys.platform == "win32": |
|
932 | if sys.platform == "win32": | |
937 |
virtual_env = Path(os.environ["VIRTUAL_ENV"]) |
|
933 | virtual_env = str(Path(os.environ["VIRTUAL_ENV"], "Lib", "site-packages")) | |
938 | "Lib", "site-packages" |
|
|||
939 | ) |
|
|||
940 | else: |
|
934 | else: | |
941 |
virtual_env = Path( |
|
935 | virtual_env_path = Path( | |
942 |
"lib", "python{}.{}" |
|
936 | os.environ["VIRTUAL_ENV"], "lib", "python{}.{}", "site-packages" | |
943 | ) |
|
937 | ) | |
944 |
|
938 | p_ver = sys.version_info[:2] | ||
|
939 | ||||
|
940 | # Predict version from py[thon]-x.x in the $VIRTUAL_ENV | |||
|
941 | re_m = re.search(r"\bpy(?:thon)?([23])\.(\d+)\b", os.environ["VIRTUAL_ENV"]) | |||
|
942 | if re_m: | |||
|
943 | predicted_path = Path(str(virtual_env_path).format(*re_m.groups())) | |||
|
944 | if predicted_path.exists(): | |||
|
945 | p_ver = re_m.groups() | |||
|
946 | ||||
|
947 | virtual_env = str(virtual_env_path).format(*p_ver) | |||
|
948 | ||||
|
949 | warn( | |||
|
950 | "Attempting to work in a virtualenv. If you encounter problems, " | |||
|
951 | "please install IPython inside the virtualenv." | |||
|
952 | ) | |||
945 | import site |
|
953 | import site | |
946 | sys.path.insert(0, virtual_env) |
|
954 | sys.path.insert(0, virtual_env) | |
947 | site.addsitedir(virtual_env) |
|
955 | site.addsitedir(virtual_env) |
General Comments 0
You need to be logged in to leave comments.
Login now