5

I want to use tensorflow through a virtual environment. However, the Python script I want to run requires me to use a separate virtual environment that does not include tensorflow.

Is it possible to activate these simultaneously? If not, can I merge the two virtual environments somehow?

1arnav1
  • 187
  • 2
  • 3
  • 9
  • maybe you can create a third virtuanenv with packages from initial two. Activate virtual env and use command pip freeze > req_venv1 and the same for second. Then init a new virtual env and to pip install -r req_venv1 and pip install -r req_venv2 – Alex Nikiforov Jun 21 '18 at 00:45

2 Answers2

4

Check this out.

You could also activate different virtual environments on different terminal sessions

  • While I find your answer helpful, please remember: link only answers are discouraged. You should always take a bit of time and explain where that link is going and what exactly it is doing for you. You see, links break at some point. Open source projects move from one service to another ... so just linking to the current place of that service doesn't help in the long run. – GhostCat Feb 16 '23 at 08:56
2

You could try adding the site-packages dir of the other virtualenv to your PYTHONPATH variable. Your mileage may vary, but I think it would work for the majority of the packages.

export PYTHONPATH=<other-env>/lib/python3.6/site-packages:$PYTHONPATH 

(or the equivalent variable setting statement for your OS/Shell)

jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • Thanks this works! As a note, The path separator is `:` on Linux and `;` on Windows – xjcl Sep 01 '21 at 11:46