5

My ipython works okay, but when I try to open ipython console from venv I am getting:

Traceback (most recent call last):
  File "/usr/bin/ipython3", line 4, in <module>
    from IPython import start_ipython
ImportError: No module named 'IPython'

Any ways to do this?

7
  • 1
    that's using your system ipython - you sure you have activated the virtualenv? Commented Aug 24, 2015 at 13:10
  • @scytale, yes. Do I need to install ipython for each venv somehow? Commented Aug 24, 2015 at 13:13
  • 1
    in python 2, yes, you'd need to do pip install ipython - I'm not familiar with python3 but I imagine the same applies Commented Aug 24, 2015 at 13:14
  • If you installed ipython from Anaconda, you can create and manage virtual environments with conda. Commented Aug 24, 2015 at 13:14
  • @pythad You need to active the virtualenv before running pip install X Commented Aug 24, 2015 at 13:14

3 Answers 3

1

Did you by any chance create the venv with the --system-site-packages flag and install ipython with pip? This combination is broken in my experience (Python 3.6.2, pip 9.0.1).

Two workarounds are:

  1. Use virtualenv instead of venv,
  2. Or use easy_install instead of pip.

With pip, scripts get the wrong shebang pointing to system python.

Sign up to request clarification or add additional context in comments.

2 Comments

😱What is this I don't even. Well, this fixes it. But I am terrified that changing the name of the virtualenv from venv to virtualenv can have any effect at all.
It's more than a name change. These are two separate packages (that work slightly differently) for creating virtual environments.
1

It seems that now it works. You should be able to achieve that:

user@host:~/ source path/to/venv/bin/activate
(venv) user@host:~/ python3 -m pip install ipython
(venv) user@host:~/ ipython
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.31.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import sys

In [2]: sys.executable
Out[2]: '/path/to/env/bin/python3'

In [3]:

Note that I am using python3 -m pip [...] to ensure that the module are installed in the environment and not elsewhere.

Comments

0

have you activated your virtualenv and installed ipython into the virtualenv?

source path/to/venv/bin/activate
pip install ipython

8 Comments

Is ipython a pip package?
@robguinness - the comments aren't the place for asking for help - please open a new question
Seriously? I've been around awhile on SO. I don't think this merits a new question at all. My question is the same as the OP, but when I try the solution in your answer, I get an error. Seems to me like a comment is appropriate.
@robguinness - that's not how SO works - nobody will see your question here except me cause this answer doesn't get much traffic. (I got a notification). I'm not about to provide 1 on 1 help. if you ask a new question it will appear in the appropriate places and will get seen. the comment's aren't the place to ask for new help.
just pointing out that SO doesn't work the way you think it does. anyway good luck with figuring that out.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.