Reputation: 105
I have activated the conda environment at first and then I have tried to activate the venv created by python3s' native virtualenv package without deactivating the conda environment. To my surprise both the venv are in running state. But python used by the venv is the one which I have activated recently. Can any one explain what is happening here ?
~$ which python3
/usr/bin/python3
~$ conda activate py369
(py369) ~$ which python
/home/xxx/anaconda3/envs/py369/bin/python
(py369) ~$ source venv/bin/activate
(venv) (py369) ~$ which python
/home/xxx/venv/bin/python
(venv) (py369) ~$
If this is like both the venv's are activated then Am I able to access both the packages from conda env and also the venv?
Upvotes: 0
Views: 620
Reputation: 20600
This is what is happening:
You activate the conda environment. conda
then modifies your PATH such that /home/xxx/anaconda3/envs/py369/bin
is first. You can check this with echo $PATH
. It also modifies your shell prompt such that (py369) is displayed in front
You activate your virtualenv environment. Since virtualenv is oblivious of what conda
does, it simply modifies your PATH
such that /home/xxx/venv/bin/
and puts its own prefix in front of your shell prompt
So now, when you call python
, it will be started from the virtualenv folder. When you import packages, they will be loaded from what is installed inside your virtualenv. So you cannot just import from both the conda and virtualenv environment at the same time.
You also have not mentioned why you would want to have such a set up. My personal opinion is that you should not mix different environment programs, as it will only generate confusion.
Upvotes: 1