Anaconda can't import installed package matplotlib-venn - python

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!

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

Related

Upgrading Python 2.7.16 libraries on MacOS Big Sur 11.3

To confirm results of a colleague who has coded an interpolation with Cubicspline from scipy with python2 , I have to import CubicSpline function. I know python2 is deprecated but this is just for a validation.
But when i do a :
from scipy.interpolate import CubicSpline
I have systematically the error message :
ImportError: cannot import name CubicSpline
So, I tried to install it with pip-2.7 by doing :
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python2.7 get-pip.py
and after from the directory ~/Library/Python/2.7/bin :
./pip2.7 install scipy
but same error, CubicSpline is not found
I have the version :
$ which python2.7
/usr/bin/python2.7
So python2.7 is the default python2 of the system.
How to install CubicSpline library on the default installation of python2.7 in the OS ?
Have I got to reinstall all the python2.7 framework ? and if yes, how to perform it ?
Update 1
The situation has become worse :
After doing $ python2.7 -m pip install scipy numpy I get now :
$ python2.7
Python 2.7.16 (v2.7.16:413a49145e, Mar 2 2019, 14:32:10)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(.startup.py)
Traceback (most recent call last):
File "/Users/fab/.startup.py", line 3, in <module>
import numpy as np
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py", line 71, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
1. Check that you are using the Python you expect (you're using /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python),
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy versions you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/_multiarray_umath.so, 2): Symbol not found: ___addtf3
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/../.dylibs/libquadmath.0.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/../.dylibs/libquadmath.0.dylib
Finally, I decided to use Macport, but there is yet a problem when I do :
$ /opt/local/bin/python2.7
Original error was: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/_multiarray_umath.so, 2): Symbol not found: ___addtf3
Referenced from: /opt/local/lib/libgcc/libquadmath.0.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /opt/local/lib/libgcc/libquadmath.0.dylib
On Big Sur, I saw that file libSystem.B.dylib didn't exist anymore.
How to circumvent all these issues ?
Update 2
Things are better but not all is done.
I removed python2.7 from MacPorts and useless binaries of kind python2* located into /usr/local/bin/.
Now, I have only the binary python2.7 coming from /usr/bin/python2.7 :
WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.
Python 2.7.16 (default, Feb 28 2021, 12:34:25)
[GCC Apple LLVM 12.0.5 (clang-1205.0.19.59.6) [+internal-os, ptrauth-isa=deploy on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> from scipy.interpolate import CubicSpline
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name CubicSpline
>>>
As you can see, numpy and scipy are well loaded but there is still this problem with this line : from scipy.interpolate import CubicSpline
I would like to know where is located this library CubicSpline. Indeed, Recently, I could make run a "python2.7" code version and there were no problems for the loading and using of this function CubicSpline.
Where are stored numpy and scipy for the OS System version of python2.7
Update 3
I have finally found where the issue comes from. CubicSpline seems to be only available for scipy > 0.18. But on my MacBook, if I do :
$ import scipy
scipy.version.version
I get :
>>> scipy.version.version
'0.13.0b1'
Is there a way to upgrade the scipy of MacOS Big Sur Python 2.7 default system (I mean without using Brew/Macports) ?
Update 4
I don't understand anything, on a similar MacBook Pro with Big Sur 11.3, if I do :
/usr/bin/python2.7
I get :
Python 2.7.16 (default, Feb 28 2021, 12:34:25)
[GCC Apple LLVM 12.0.5 (clang-1205.0.19.59.6) [+internal-os, ptrauth-isa=deploy on darwin
Type "help", "copyright", "credits" or "license" for more information.
(.startup.py)
(imported numpy as np)
(imported matplotlib.pyplot as plt)
(imported scipy.interpolate CubicSpline)
(imported scipy.interpolate interp1d)
(imported os)
(imported sys)
(imported glob)
and if look at the version of scipy in the python2.7 shell, I get :
>>> import scipy
>>> scipy.version.version
'1.2.2'
Where are installed the numpy and scipy libraries for the default python 2.7 on Big Sur 11.3 ? : I tried to look for (with sudo grep -riIHn cubicspline) in /System/Library, and ~/Library/, and in /Library/, but found nothing.

Unable to load matplotlib in Jupyter Notebook

I'm Unable to load matplotlib in Jupyter Notebook but woking fine in python command line shell,
Is there anything I need to configure to make it working?
Following is the error I'm getting in Jupyter Notebook
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-99ba79ecbbfb> in <module>()
----> 1 from matplotlib import pyplot as plt
ImportError: No module named matplotlib
And in command line I can access it like the following:
Python 3.7.3 (default, Mar 27 2019, 23:47:09)
[Clang 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from matplotlib import pyplot as plt
>>>
Seems like it's working now I ran the following command as specified here
python3 -m pip install ipykernel
python3 -m ipykernel install --user
Thanks.
One way is to check if you installed matplotlib using pip3 (if you used pip3 to install jupyter notebook, which looks like is your case).
Another way is to add the path of site-wide packages (where of course matplotlib is installed). In your Jupyter notebook console:
import sys
PATH = '/usr/lib64/python3.7/site-packages/'
sys.path.append(PATH)
Notebook is launched from another virtual python environment.
You can check paths to python interpreters, that run your notebook and interactive shell:
import sys
print(sys.executable)
I'm sure, they will be different.

OpenCV 3.4.1 on Mac through Anaconda - - package not found

I'm running an Anaconda virenv that has successfully installed OpenCV ver.3.4.1. From the python prompt I can import cv2 and can confirm it's version per the command line below:
Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:07:29)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.1'
However, in VSCode I run the following simple program and get an error:
import numpy as numpy
import argparse
import cv2
pass
The error is:
Traceback (most recent call last):
File "detect_faces.py", line 3, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
I don't understand why the command line import works, but the program from VSCode fails to import the same package.
There are multiple SO Q&A on this topic but they are all incredibly time/date sensitive and platform specific -- most deal with the situation where the package itself isn't recognized anywhere. The closest question is this one which is from 2015 and deals with the Android platform. Any thoughts?
Update
The version installed should be 3.5.5, but I noticed that in the command prompt launched from anaconda it's shown as Python 3.5.5 :: Anaconda, Inc. while the version shown within VSCode is Python 3.6.5 :: Anaconda, Inc.. When I look at the available env in VSCode it shows some 2.7s and several 3.6 versions - including the one I'm using which is 3.6.5.
I've just done a new install of a fresh Python 3.6 env and noticed that the command prompt reports Python 3.6.6 while the output from a sys check reports Python 3.6.5 -- again, both have the same executable path.
Although I was unable to replicate this same error, I did determine that it had to do with the installation of numpy. For whatever reason, it originally installed and downgraded the Python version within the venv. Then later when upgrading python it created a mismatch. The fix was to recreate the venv with a pip install of all three packages in the same command line. When installing all three at once the packages all reconcile - - I don't know if there was another variable - I couldn't recreate the original error.

ImportError for packages in my current environment

I am trying to revive some old IPython notebooks and update them to Python 3. I am trying to get them working first in the old environment and finding an intractable difficulty, getting ImportErrors for packages in my current environment. I am working on an Anaconda Python installation.
I start my notebook by first navigating to the folder of my project:
cd /folder/of/project
and then:
jupyter notebook
I create a new notebook and here is an extract from !conda list inside the notebook and the errors I am getting:
# packages in environment at /anaconda2:
#
...
Delorean 0.6.0 <pip>
...
pylint 1.7.2 py27h718c7e7_0
pymongo 3.4.0 py27_0
pyodbc 4.0.17 py27hc9de18c_0
...
Clearly, the packages of interest, Delorean and pymongo, are in the environment. pymongo was installed via conda natively, but Delorean can only be installed via pip.
[1] import pymongo
ImportError Traceback (most recent call last)
<ipython-input-2-ec8fdd1cd630> in <module>()
----> 1 import pymongo
ImportError: No module named pymongo
[2] from delorean import Delorean
ImportError Traceback (most recent call last)
<ipython-input-3-2b02cbe45080> in <module>()
----> 1 from delorean import Delorean
ImportError: No module named delorean
I have tried this on various virtual environments created using conda as well as in the default environment. I have looked at various questions on StackOverflow and still getting no solution.
In response to a comment, here are the paths to jupyter and python:
$ which jupyter
/anaconda2/bin/jupyter
$ which python
/anaconda2/bin/python
To compound the mystery, trying to import the packages from python shell as suggested by #Sraw, works perfectly.
$ python
Python 2.7.13 |Anaconda custom (x86_64)| (default, Sep 21 2017, 17:38:20)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> from delorean import Delorean
>>>
The issue therefore is limited to inside the jupyter notebook.
I have resolved this issue. It was created by my trying to juggle different Python 2 and 3 versions and multiple trial virtual environments. I had ended up with an old user-specific anaconda installation and a new anaconda root for all users. The discovery was made by finding that
import sys
sys.path
gave different reports when I ran these from Python shell and from inside the notebook.
I cleared the user-specific anaconda installation, re-installed the latest anaconda version, added the relevant packages, and installed parallel ipython kernels (as described here).
The issue is resolved and serves as a lesson in the importance of keeping the root python install clean and properly using virtual environments.

Cannot import matplotlib into Python 3

I am attempting to teach myself programming and keep running into problems downloading modules I need for basic tutorials.
My latest attempt has been to get the matplotlib module into my Python 3 environment. I have tried so many different install packages and so many advice I found on the internet that I cannot remember how I originally got the module. But it seemed that everything went well with the installation process.
I am using a Raspberry Pi2 throughout all of this with the Raspbian OS installed.
Python 3.2.3 (default, Mar 1 2013, 11:53:50)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import matplotlib
ImportError: No module named matplotlib
It may be possible that you actually installed the library for python 2. I would use pip to install the modules that you need. If you don't already have it installed, run this first command in the shell:
sudo apt-get install python3-pip
This program can be called with "pip3" or maybe "pip-3.2" in the shell.
To install mathplotlib with it, try running:
pip3 install matplotlib
or
pip-3.2 install matplotlib
That should install the Python 3 module for you.

Categories

Resources