0

I get an ImportError whenever I try to activate a virtual environment, or when I try to launch Spyder.

When trying to activate a virtual environment:

Traceback (most recent call last):
File "/home/pauline/anaconda3/bin/conda", line 3, in <module>
from conda.cli import main
ImportError: No module named conda.cli

When trying to open spyder:

Traceback (most recent call last):
File "/home/pauline/anaconda3/bin/spyder", line 2, in <module>
from spyderlib import start_app
ImportError: No module named spyderlib

I tried to find an answer for that but I could mainly find problems occurring after Anaconda was just installed (mine has been installed previously and was working fine up until yesterday).

I have also tried this answer and this answer but they did not solve the problem.

The only think I can think of which may have provoked this error is that I changed the interpreter used by Spyder yesterday from the default Anaconda Python interpreter to an interpreter from a virtual environment created with virtualenv. Even then, I could close and restart Spyder with no problems, and the errors started after I rebooted my computer.

[edit] I should add that both Anaconda and my virtual environment use the same version of Python which is Python 3.5

Pauline
  • 3,566
  • 8
  • 23
  • 39

1 Answers1

1

If you are using a different python version, whatever packages that you had with anaconda or that you may have installed with conda install will not be there on the new version. You need to install them with pip or conda again.

elelias
  • 4,552
  • 5
  • 30
  • 45
  • They are both using the same Python version which is Python 3.5 – Pauline Jul 25 '16 at 11:43
  • sure, but if you do `which python` the python directory is different, isn't it? – elelias Jul 25 '16 at 11:47
  • Yeah, if I was doing `which python` from my virtual environment I would have `/home/pauline/mybeautifulvenv/bin/python` while anaconda would use its own... So you mean, I should install everything from anaconda in my virtual environment? – Pauline Jul 25 '16 at 11:56
  • yep, you should repeat the `conda install` in your virtaulenv. The previous installation is not seen by `mybeautifulvenv` – elelias Jul 25 '16 at 12:01
  • So I tried `conda install` from my virtual environment, but I get the same error as when trying to open spyder – Pauline Jul 25 '16 at 12:06
  • in your question, the python you are trying do to the import, is *not* the virtualenv one, it says `/home/pauline/anaconda3/bin/conda` which is the regular anaconda one. You need to do the conda install on the same enviroment as you do the import. Either open and import on the virtualenv python `/home/pauline/mybeautifulvenv/bin/python`, or do `conda install` in the non-virtualenv. I think you are mixing the two. – elelias Jul 25 '16 at 12:44
  • `conda install` won't work, I get the same error be it when no environment is activated, or when `mybeautifulvenv` is activated or when an unrelated environment is activated. Likewise, activating environments, be it `mybeautifulvenv` or an unrelated one won't work. They all return the same error, which makes it difficult to fix – Pauline Jul 25 '16 at 13:19
  • 1
    that means that the libraries were not install to begin with. You should try with `pip` instead of `conda install`. Can you try that? – elelias Jul 25 '16 at 13:33
  • Bingo! It worked. Thanks a lot.Bingo! It worked. Thanks a lot. What I did to fix it is: outside the virtual environment `sudo pip install conda` and `conda install spyder` then from inside the environment `conda install spyder`. Just for my general knowledge do you have an idea of what happened which required conda and spyder to be reinstalled? – Pauline Jul 25 '16 at 13:57