2

I have two different python virtual environment systems, one is anaconda and the other is virtualenv. (I need to keep both to suit different develop environment).

I installed separate ipython for each virtual env. The problem is that ipython seems to be virtual environment aware, it will automatically load libs from $VIRTUAL_ENV.

For example, here are my two different virtual environments

  1. venv, created by virtualenv: virtualenv /home/<user>/venv. And I set $VIRTUAL_ENV by adding export VIRTUAL_ENV='/home/shao/venv' in .bashrc. Also I installed some required package in this environment by pip
  2. p2, created by anaconda: conda create -n p2 python=2.

The $PATH after activating p2 is:

(p2) shao@T420s:~$ echo $PATH
/home/shao/anaconda3/envs/p2/bin:/home/shao/anaconda3/bin:/home...

I am definitely sure that ipython binaray is at /home/shao/anaconda3/envs/p2/bin.

However, the ipython sys.path for p2 is:

(p2) shao@T420s:~$ ipython
/home/shao/anaconda3/envs/p2/lib/python2.7/site-packages/IPython/core/interactiveshell.py:724: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
  warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 2.7.12 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:42:40) 
Type "copyright", "credits" or "license" for more information.

...

In [1]: import sys
In [2]: sys.path
Out[2]: 
['/home/shao/venv/lib/python2.7/site-packages/pandas-0.18.1-py2.7-linux-x86_64.egg',
 '/home/shao/venv/lib/python2.7/site-packages/tika-1.13.1-py2.7.egg',
 '/home/shao/venv/lib/python2.7/site-packages/superlance-0.11-py2.7.egg',
 '/home/shao/venv/lib/python2.7/site-packages/pytz-2016.6.1-py2.7.egg',
 ...
 '/home/shao/venv,
 '/home/shao/anaconda3/envs/p2/bin',
 '/home/shao/anaconda3/envs/p2/lib/python27.zip',
 ...
 '/home/shao/.ipython']

As you can see, ipython interpreter gives me warnings and the sys.path contains libs from venv, which are prior libs from p2.

After some google searches, I noticed that recent ipython version is virtual environment aware, so that it will automatically load these libs from venv.

I noticed two things:

  1. python interpreter of p2 will not be affected by venv
  2. If I RESET $VIRTUAL_ENV, ipython interpreter of p2 will not be affected by venv.

Now the question is that is there any graceful way (keep $VIRTUAL_ENV) to disable ipython's initialization behavior, so that $VIRTUAL_ENV libs will not be loaded?

Thanks.

Community
  • 1
  • 1
rojeeer
  • 1,991
  • 1
  • 11
  • 13

0 Answers0