how to call an ipython within virtualenv?

Question:

Good time of the day, everyone!

The problem is the following:

  1. I create virtualenv using the command python3 -m venv env (my python version 3.8.9)
  2. I activate it . ./env/bin/activate
  3. Install ipython: pip install ipython
  4. Try to run it ipython, but instead of invoking my virtualenv’s ipython, My system ipython open with the following message:
/opt/homebrew/lib/python3.9/site-packages/IPython/core/interactiveshell.py:852: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
  warn(

What should I do to change this behaviour and to be able to call my virtualenv’s ipython?

Thanks in advance!

Asked By: A. Veselev

||

Answers:

You can use alias to indicate ipython in your virtual env. First make sure you have activated your virtualenv source ./env/bin/activate. Then run:

alias ipython="python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'"

This is a great way of always being sure that the ipython instance always belongs to the virtualenv’s python version. And This works only on ipython >2.0.

Source: Link

Answered By: Rafat Hasan
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.