2

I'm about to give up on Anaconda. I never had trouble managing my packages with pip and I just thought I'd try it since now there's one package I can't get with pip and I'd heard so many good things about it.

I can't import a package I just installed with Anaconda, similar to this but on MacOS instead of Windows.

I really don't want multiple environments unless I have to have them. I want to be able to run most/all of my packages from the same scripts. I have a virtual environment named py37 where I've been putting most things. Among other packages:

(py37) jennifers-mbp:~ jenniferlongdiaz$ conda list
#packages in environment at /anaconda3/envs/py37:
#
# Name                    Version                   Build  Channel    
matplotlib-venn           0.11.5                     py_1    conda-forge
numpy                     1.15.3           py37h6a91979_0  
python                    3.7.1                haf84260_3  

Python goes to the right installation:

(py37) jennifers-mbp:~ jenniferlongdiaz$ which python
/anaconda3/envs/py37/bin/python
(py37) jennifers-mbp:~ jenniferlongdiaz$ python
Python 3.7.1 (default, Oct 23 2018, 14:07:42) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.

I can import numpy but not matplotlib-venn:

>>> import numpy as np
>>> import matplotlib_venn as venn

...bunch of stuff and then:

ImportError: cannot import name 'get_backend' from 'matplotlib' (/anaconda3/envs/py37/lib/python3.7/site-packages/matplotlib/__init__.py)

Similiarly:

>>> from matplotlib import get_backend

...bunch of stuff and then:

ImportError: cannot import name 'get_backend' from 'matplotlib' (/anaconda3/envs/py37/lib/python3.7/site-packages/matplotlib/__init__.py)

From within the IDE spyder ((py37) jennifers-mbp:~ jenniferlongdiaz$ spyder), I get:

In [1]: import matplotlib_venn as venn
Traceback (most recent call last):

  File "<ipython-input-9-aafbc15b97e7>", line 1, in <module>
    import matplotlib_venn as venn

ModuleNotFoundError: No module named 'matplotlib_venn'

Please help!

andbeonetraveler
  • 693
  • 3
  • 11
  • 25
  • There are 2 separate problems here. 1 is that `matplotlib_venn` probably relies on an older version of Matplotlib that has that function, but they didn't properly specify that in their setup file (see https://github.com/konstantint/matplotlib-venn/blob/c26796c9925bdac512edf48387452fbd1848c791/setup.py#L48). Second, you need to install Spyder into that environment if you want to be able to import packages from the environment. – darthbith Oct 24 '18 at 20:51
  • spyder is installed in py37 and that's where I'm using it, see above – andbeonetraveler Oct 24 '18 at 20:52
  • Please show the complete output of `conda list` If spyder is installed in the base environment, it will still run **even if not installed in the `py37` environment**! It will just pick up the wrong packages. This is because of how the `PATH` environment variable works. – darthbith Oct 24 '18 at 20:53
  • got it, you're right it was running the base spyder. After restarting terminal and conda install spyder everything works now. Not sure what was going on with matplotlib. If you answer I'll accept – andbeonetraveler Oct 24 '18 at 20:58
  • It seems like @Michael has got the answer, feel free to accept theirs – darthbith Oct 25 '18 at 14:13

1 Answers1

3

According to matplotlib-venn's PyPi page (https://pypi.org/project/matplotlib-venn/), the import should look like this:

import matplotlib_venn as venn

Note that the module is named with an underscore whereas the package is named with a dash; this is a tricky inconsistency


Update for updated question: the issues with spyder were due to spyder not being installed as part of anaconda, resulting in the system's spyder not being aware of the anaconda environment's packages. Being unable to import get_backend from matplotlib would suggest either a missing or borked matplotlib installation. Both just require installing (or reinstalling) the packages using conda

Michael
  • 2,344
  • 6
  • 12
  • you're 100% right, but unfortunately that error is the result of my typo when reproducing the error I got to make the post, but not the error that's giving me trouble. I'll edit. – andbeonetraveler Oct 24 '18 at 20:25
  • Spyder can't find the module now? Is that the same Spyder installed in your Anaconda area? Show us the which – Michael Oct 24 '18 at 20:41
  • Also, are you able to execute `from matplotlib import get_backend` from Python? – Michael Oct 24 '18 at 20:42
  • 1
    Oh, I just double-checked your conda list: matplotlib isn't installed. Try installing that with conda and importing matplotlib_venn again. My other suspicion is that the spyder you have is not aware of your anaconda environment (because your conda list doesn't show it, so it's probably not associated with anaconda), so it doesn't know where any of your packages are. Try running "conda install spyder" to install spyder to your anaconda environment – Michael Oct 24 '18 at 20:57
  • matplotlib is actually there (I didn't paste in the full output of conda list because it's pretty long) but spyder wasn't. restarted terminal and installed spyder, now for some reason it works – andbeonetraveler Oct 24 '18 at 21:00