1

I am currently scratching my head on differing behavior for python and ipython.

Background: I want to play with tensorflow, and following the instructions of some online resources, I installed anaconda3 which would take care about everything. I am not particularly familiar with anaconda and just followed the instructions.

Now, I created a virtual environment (xyzzy in the example below). Then, within this environment, I invoked an interactive python shell and tried to import numpy, pandas and tensorflow.

(xyzzy) countermode@peppermint:~$ python
Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 17:14:51) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
>>> import numpy as np
>>> import tensorflow as tf
>>> 

Well, ok, it seems that pandas is somehow not accessible, although it actually is installed.

Anyway, now the same with ipython:

(xyzzy) countermode@peppermint:~$ ipython
Python 3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 17:14:51) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import pandas as pd

In [2]: import numpy as np

In [3]: import tensorflow as tf
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-64156d691fe5> in <module>()
----> 1 import tensorflow as tf

ModuleNotFoundError: No module named 'tensorflow'

So now the pandas import works fine while tensorflow appears to be gone.

Ummm... what is going on here? Why do I see this behavior? And how can I resolve it?

Supplementary information

This all happens on Linux Mint, the system is updated, anaconda and all packages maintained by it are updated, all packages within the environment are updated. I did not meddle with anything.

Conclusion

After installing ipython in the virtual environment both shells "agreed" on their behavior.

6
  • I would recommend running which python and which ipython . I'm guessing you'll find, that one of them is exectued from the venv folder and the other isn't.
    – MTTI
    Commented Sep 7, 2018 at 9:14
  • @MTTI excellent. What can I do to resolve it? I installed ipython into the virtual environment, but the result remains the same. Commented Sep 7, 2018 at 9:26
  • python is in your transports_ml environment and ipython is not. So source activate transports_ml and run ipython Commented Sep 7, 2018 at 9:31
  • 1
    Please run import sys; print(sys.executable); print(sys.path) in both cases. Commented Sep 7, 2018 at 9:31
  • 1
    @MTTI wrap this up as an answer and I'll accept it. Commented Sep 7, 2018 at 9:49

1 Answer 1

1

This question is possibly a duplicate of/relates to this .

You probably installed ipython globally and are therefor not using the virtual environment. To fix this:

  1. activate venv
  2. install ipython within the venv using pip

If the venv is activated, it should now use the ipython version within the venv.

2
  • I just want to add, since I just went through this, that at command shell level something like hash -r (for bash) is in order to clear the shell's cache. Commented Sep 7, 2018 at 10:10
  • This is correct, only you should install IPython with Conda, not Pip
    – darthbith
    Commented Sep 7, 2018 at 12:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.