I'm running a Fedora 17 (x64) machine, and I tried installing Mayavi for python via
yum install mayavi
which worked fine, except every time I write a code where I call a mayavi module (like mlab) :
from enthought.mayavi import mlab
it yells with the error
********************************************************************************
WARNING: Imported VTK version (5.8) does not match the one used
to build the TVTK classes (5.6). This may cause problems.
Please rebuild TVTK.
********************************************************************************
I've googled, but I don't know how to rebuild TVTK to match with the version of VTK. I suspect this is causing abnormal behaviour, but I can't be sure. How do you rebuild TVTK?
Looks like the visualization toolkit (http://www.vtk.org/) on your machine is newer than the one used to build the classes that are packaged in mayavi. You'd need to rebuild/install visualization toolkit 5.6 (http://vtk.org/VTK/resources/software.html) or have you tried Mayavi2 (http://docs.enthought.com/mayavi/mayavi/installation.html) - that is probably more up to date, visualization toolkit is currently version 5.10.
As of 4.3.1 do not yet support VTK 6.x. This is being worked on currently on master but is not finished yet.
https://github.com/enthought/mayavi/issues/124
I guess you used yum update but didn't do the trick. You can also check for the version in the repository by doing yum info and looking at the version number it displays.
If that does not satisfies you I'm afraid you will have to "use the source"...
hope this will help
I had the same problem and a simple update of mayavi2 did the trick:
pip install mayavi2 -U
Related
I know this question has been asked many times before but I cannot find a solution that works for me. I'm running Python 3.5.3 under Blender 2.79 in Windows 10. As I require Blender 2.79, upgrading the Python version is not possible.
I've installed matplotlib and I can import it. However, when I try to import pyplot (e.g. import matplotlib.pyplot as plt), I get a crash to desktop with no error messages of any kind. This happens if I run Python externally or from inside Blender. The weird thing is that I was able to avoid this by changing backends to agg (matplotlib.use('agg')) and this is still working in a previous installation (so I know it's possible to get this to work !), but not in a separate, new installation of Blender. I've tried other backends but they make no difference.
The exact procedure I've tried is as follows :
Downloaded Blender 2.79 from a zip file (I'm using Windows 10) and unpacked it (call this directory /Blender/)
In /Blender/2.79/python/bin I run the command ./python -m ensurepip
In /Blender/2.79/python/scripts I run pip3 install --upgrade pip --user. This gives me pip3 version 20.2.4
In the same directory I run pip3 install --target="/Blender/2.79/python/lib/site-packages" matplotlib --upgrade. The "upgrade" switch is to prevent warnings that the "/bin" directory exists. Doesn't make any difference if I remove it, there's no existing installation of matplotlib. This gives me matplotlib version 3.0.3
Finally I start Python by /Blender/2.79/python/bin/python.exe, and do the above mentioned importmatplotlib.pyplot command which causes the crash.
I've tried this from a completely fresh installation of Blender, which comes with no existing external modules installed. Could there be some conflict with other Python modules elsewhere ? How would I go about diagnosing what's going on ?
Thanks for any ideas !
FIXED ! I remembered I found the solution months ago, but stupidly wrote down the answer in the wrong file...
The problem is that matplotlib is looking for a file that doesn't exist. In c:/users/me/.matplotlib (a hidden file), there's a file ""fontlist-vXXX.json", where XXX is the version number. This is set in line 951 of the file "font_manager.py", located in /python/lib/site-packages/matplotlib. In my case, the font_manager was looking for version 300 but the actual file was 310. Changing the version number in the font_manager.py made everything work correctly.
The question of using matplotlib with MacOS is a tricky one which has already been thoroughly reviewed by a number of discussions (see below). The problem is the following:
using MacOS Mojave 10.14.3
using python 3.7.2 in a conda environment
using matplotlib 3.0.3
Here is the simplest code snippet I came up with which allows reproducing the issue:
from matplotlib import pyplot as plt
x = [1, 2, 3]
y = [1, 2, 3]
plt.plot(x, y)
plt.show()
This throws the following error:
2019-03-22 12:25:43.429 python3.7[22209:554135] -[NSApplication _setup:]: unrecognized selector sent to instance 0x7f85866b9de0
2019-03-22 12:25:43.431 python3.7[22209:554135] \*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x7f85866b9de0'
*** First throw call stack:([...])
libc++abi.dylib: terminating with uncaught exception of type NSException
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
The issue is documented here. One solution is to install the PyQt5 package to your Python installation and to add the following lines at the beginning of your script:
import matplotlib
matplotlib.use("Qt5Agg")
While this works perfectly well, I am wondering why other backends fail to provide similar behavior.
Indeed I tried using MacOSX backend :
import matplotlib
matplotlib.use('MACOSX')
Which yields to the error:
from matplotlib.backends import _macosx
ImportError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
The issue is documented here, there and in plenty of other threads.
Two solutions came out :
install python.app(conda install python.app) and launch your script with pythonw instead of python
use TKAggbackend
Using the first one works well but I wonder:
why do we need to call pythonw instead of python ?
what exactly is the python.app package ?
how can we make this solution work using an IDE (let say PyCharm for instance) ?
As for the second one, it does "work" up to a certain point: when running matplotlib using TkAgg, the plot window is really buggy. Indeed, it often needs several clicks on the "zoom", "pan" or "home" buttons to get them to actually work. It really is a great pain to use it. I asked several colleagues or friends using matplotlib with TkAgg and they all have the same issue.
Does anyone know the reason for this state of fact? Or if there is any workaround to avoid this issue (apart from installing pyqt5)?
Using the first option is your best bet since you are already working with a virtual environment.
According to matplotlib, there are two variants of python:
A Framework build - Quite important for GUI stuffs in MacOXs
A regular build.
Matplotlib in this case would want to interact natively with OSX and for this, it needs the Framework build this is the reason why installing the python.app type of python is important.
More information can be gotten from Matplotlib FAQ.
Check this link for more about the need for a framework build python.
I'm going to make some assumptions. If they're wrong I apologize.
You installed Python with Anaconda.
Personally, I've never had any problems on mac with matplotlib. My setup is: Mojave, Python3.7.3 in a venv using the python built in module (python3 -m venv), and matplotlib 3.0.3.
I can't answer your question on how to fix your problem, but I'm kind of trying to answer your "is there any workaround" question. Personally, I've always had issues with using Anaconda/Spyder/Conda for Python. I've always felt installing it as its own binary/app on the system leads to the fewest errors.
Now, I'm not saying you have to download and install by hand though. I use homebrew and it saves me headaches everyday I assume (such as upgrading applications and packages). That's the "work around" I'd suggest. Because isn't installing via Anaconda/Spyder already a workaround to installing Python properly? I've always felt performing one work around requires more workarounds for full functionality. Such as having to specify the matplotlib backend when it should be detected by default.
Obviously, I'm a little biased against that tool and that may be reflected in this answer, so take it with a grain of salt. Even though Conda is a legitimate tool that I think is useful, I find it annoying having to use both pip and conda when conda doesn't contain the packages I want.
There are two things you can try.
You can read Matplotlib info page on that, https://matplotlib.org/3.1.0/faq/osx_framework.html,
The default python provided in (Ana)conda is not a framework build. However, a framework build can easily be installed, both in the main environment and in conda envs: install python.app (conda install python.app) and use pythonw rather than python.
And follow the instructions.
Or simply follow the error message you get when you try %matplotlib inline,
(...)
UnknownBackend: No event loop integration for 'inline'. Supported event loops are: qt, qt4, qt5, gtk, gtk2, gtk3, tk, wx, pyglet, glut, osx
I did %matplotlib osx and have plt.imshow(myimg) working just fine afterwards.
After 3 days of trying to install networkx for python 3.4, I am on the verge of giving up and I've decided to seek for help from some of you people who had some experience with this perhaps.
I managed to install networkx with easy_install or pip_install (I don't even remember anymore of how many times I've tried to install it all), but when I try to compile the very first, most basic piece of code (found in a tutorial):
import networkx as nx;
Test = nx.Graph();
Test.add_node("Test");
nx.draw(Test, node_size=900, node_color="blue");
I get an error: ImportError: No module named 'numpy'
When I try to install numpy with easy_install numpy it starts the download and installation process normally but then it shows this error:
Microsoft Visual C++ 10 is required
Is this referred to MV C++ 1- redistributable? I've downloaded it and tried to install it but it shouts out an error that I already have a newer version of it so I don't need it...
So my questions would be:
1.Can networkx module be installed for python 3.4 at all?
2.If so, do I need anything else besides networkx zip/installer and python 3.4 for it to work? (I've literally found 4 sources that all claim different requirement information about networkx!)
I would really appreciate any help, as I feel completely lost and discouraged about any further use of python.
You didn't say which operating system you are using but by referencing Microsoft Visual C++ I'm going to say Windows. In that case the simplest way to get a functioning scientific Python computing environment is to install one of the packaged distributions. Two good choices are Anaconda https://store.continuum.io/cshop/anaconda/ and Enthought Canopy https://www.enthought.com/products/canopy/
NetworkX definitely works with Python3.4 https://travis-ci.org/networkx/networkx
I'm trying to run the following python script (I'm using Vim):
import numpy as np;
import scipy as sp;
from scipy import misc;
import matplotlib.pyplot as plt;
image = misc.imread('test_image.jpg');
np.fliplr(image);
plt.imshow(image);
When I do, I get the following:
Traceback (most recent call last):
File "test.py", line 4, in <module>
import matplotlib.pyplot as plt;
File "/Library/Python/2.7/site-packages/matplotlib/pyplot.py", line 24, in <module>
import matplotlib.colorbar
File "/Library/Python/2.7/site-packages/matplotlib/colorbar.py", line 29, in <module>
import matplotlib.collections as collections
File "/Library/Python/2.7/site-packages/matplotlib/collections.py", line 23, in <module>
import matplotlib.backend_bases as backend_bases
File "/Library/Python/2.7/site-packages/matplotlib/backend_bases.py", line 50, in <module>
import matplotlib.textpath as textpath
File "/Library/Python/2.7/site-packages/matplotlib/textpath.py", line 11, in <module>
import matplotlib.font_manager as font_manager
File "/Library/Python/2.7/site-packages/matplotlib/font_manager.py", line 53, in <module>
from matplotlib import ft2font
ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib/ft2font.so, 2): Library not loaded: #loader_path/../../../libfreetype.6.dylib
Referenced from: /Library/Python/2.7/site-packages/matplotlib/ft2font.so
Reason: image not found
shell returned 1
I tried reinstalling brew, reinstalling freetype, matplotlib, and numpy in brew, and I uninstalled MacPorts with no change in the error. Suggestions?
EDIT: After uninstalling MacPorts and then doing another reinstall of brew, I now get this error instead.
Fatal Python error: PyThreadState_Get: no current thread
Command terminated
The error only appears when I import matplotlib, so I'm guessing the issue is with matplotlib. I will try to reinstall it with brew.
EDIT2: I've been trying from this page to no avail, but I think my error is probably related to that one.
[MacOS X] Ran into the same problem after installing graphviz (to visualize decision tree). Without carefully isolating environment, this new package appears to have put its own favorite version of freetype into my default python runtime library path. Then when doing a simple import import matplotlib.pyplot as plt, I got error messages:
ImportError: dlopen(/Users/shandou/anaconda3/lib/python3.6/site-
packages/matplotlib/ft2font.cpython-36m-darwin.so, 2): Library not
loaded: #rpath/libfreetype.6.dylib
Referenced from: /Users/shandou/anaconda3/lib/python3.6/site-
packages/matplotlib/ft2font.cpython-36m-darwin.so
Reason: Incompatible library version: ft2font.cpython-36m-darwin.so
requires version 22.0.0 or later, but libfreetype.6.dylib provides
version 21.0.0
At first, I could not understand what #rpath is really pointing to. Checked with locate libfreetype and it looks like for my default python environment, I have (1) /Users/shandou/anaconda3/lib/libfreetype.6.dylib and (2) /Users/shandou/anaconda3/pkgs/freetype-2.8.1-0
I tried the following two fixes. The first one solved the immediate need of making matplotlib import work, but later caused problems in sphinx auto doc generation. The second one is a cleaner fix that made both work.
Fix 1: conda uninstall and then pip install matplotlib
Context: I use anaconda python distribution and use conda as my main package manager
Spoiler alert: temporarily fixed import problem, but got me into trouble later when using sphinx
Takeaway: mixing pip and conda installation for major libraries can be problematic
Following #Robbie Capps's suggestion above, I uninstalled matplotlib originally installed with conda and reinstalled it with pip instead. Afterwards matplotlib import works okay and I was able to continue working until later I ran into errors when running sphinx for documenting codes:
File "/Users/shandou/anaconda3/lib/python3.6/site-
packages/matplotlib/backends/backend_macosx.py", line 17, in <module>
from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X
backend will not be able to function correctly if Python is not
installed as a framework. See the Python documentation for more
information on installing Python as a framework on Mac OS X. Please
either reinstall Python as a framework, or try one of the other
backends. If you are using (Ana)Conda please install python.app and
replace the use of 'python' with 'pythonw'. See 'Working with
Matplotlib on OSX' in the Matplotlib FAQ for more information.
That looks hairy, but if I read this correctly, the gist of the message is: sphinx is not happy about me mixing conda and pip install.
So I ended up reverting matplotlib back to conda installation. Sadly the original libfreetype error immediately returns and I was unable to do basic matplotlib import (darn...)
Fix 2: Update freetype library located in runtime path (#rpath in the error message)
Context: I tried updating freetype, libpng, and matplotlib--basically anything that the web would suggest
Spoiler alert: If runtime path library is not updated, I am left with the same error message about incompatible libfreetype
[Step 1] Brew install freetype library:
$ brew install freetype
$ brew link --overwrite freetype
When checking the library version in /usr/local/Cellar/freetype/2.9/lib/, I get output as below:
$ otool -L libfreetype.6.dylib | head -n 2
libfreetype.6.dylib:
/usr/local/opt/freetype/lib/libfreetype.6.dylib (compatibility version 23.0.0, current version 23.0.0)
This is version 21+, so we are one step closer to solve the problem
[Step 2] Copy /usr/local/Cellar/freetype/2.9/lib/libfreetype.6.dylib to python runtime library path
It turns out even after updating freetype library with conda, the runtime library is not updated. The final solution that works for me is to force copy newer freetype lib to the runtime path:
$ cd /Users/shandou/anaconda3/lib/
$ sudo cp /usr/local/Cellar/freetype/2.9/lib/libfreetype.6.dylib .
Only then, the freetype library version incompatibility problem is gone, and both matplotlib import and sphinx are happy
Bottom line: Fix 2 is the cleaner way to go.
It sounds like you already (at least partially) answered your own question, but I solved this same error, in a somewhat different fashion. Summary: I used otool and install_name_tool to manually change the linkage from the *.so file to a different *.dylib. I'm posting it here mostly as an illustration of how build systems can quickly turn into rat's nests if you're not careful.
Background
I am using conda to manage the virtual environment for a software project I am trying to compile from source (GNU Radio). In order to build the graphics submodule of this project (gr-qtgui) natively on my Mac, I believe I committed some pretty heinous crimes against nature -- more on this below.
My basic strategy to avoid build problems is to rely on a single package manager as much as possible. In this case, the honor went to conda, though some of it required brew and pip. As I'm writing this, I'm now wondering whether I should have linked against the Mac frameworks for Qt4, but what I ended up doing was linking against libQtCore.dylib et al. installed by conda in ~/miniconda3/envs/gr/lib.*
Graphics issues & Resolution
After getting GNU Radio to compile, I then conda install'd matplotlib in this virtual environment. I was initially getting a similar error as OP originally mentions:
ImportError: dlopen(/Users/strotmc1/miniconda3/envs/gr/lib/python2.7/site-packages/matplotlib/ft2font.so, 2): Library not loaded: #rpath/libfreetype.6.dylib
Referenced from: /Users/strotmc1/miniconda3/envs/gr/lib/python2.7/site-packages/matplotlib/ft2font.so
Reason: Incompatible library version: ft2font.so requires version 21.0.0 or later, but libfreetype.6.dylib provides version 14.0.0
I solved it by navigating to the offending shared object's directory and inspecting it:
>> cd ~/miniconda3/envs/gr/lib/python2.7/site-packages/matplotlib
>> otool -L ft2font.so
ft2font.so:
#rpath/libfreetype.6.dylib (compatibility version 21.0.0, current version 21.0.0)
#rpath/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
>> otool -l ft2font.so
...
Load command 9
cmd LC_LOAD_DYLIB
cmdsize 56
name #rpath/libfreetype.6.dylib (offset 24)
time stamp 2 Wed Dec 31 19:00:02 1969
current version 21.0.0
compatibility version 21.0.0
...
Load command 12
cmd LC_RPATH
cmdsize 272
path /Users/strotmc1/miniconda3/envs/gr/lib (offset 12)
...
In other words, it's linking to the libfreetype.dylib located inside the virtual environment, not on the system. Sort of makes sense as an error, because pyplot is also trying to access the graphics libraries, which were already strangely configured. My solution was to switch to linking against the homebrew version of freetype:
>> install_name_tool -change #rpath/libfreetype.6.dylib /usr/local/Cellar/freetype/2.9/lib/libfreetype.6.dylib ft2font.so
and now matplotlib works!
Moral of the story
I said from the beginning that this story is ugly. After finishing writing this up, I'm left with the following conclusions:
Despite being able to compile large software projects, I still don't really know what the hell I'm doing.
Given the difficulty of writing general-purpose libraries, and how much variation can exist across platforms, and that all users set up their systems differently, I'm amazed that anything ever works.
On the other hand, is this really the best we can do? It seems like complexity is the source of the problem. Does any tool sophisticated enough to manage the complexity necessarily introduce more complexity into the system, and thus more opportunities for failure?
Sorry this turned into more of a musing than an answer -- perhaps someone would be so kind to suggest a better place for this type of rambling answer?
*To be completely frank, I never even considered trying to link against the Qt frameworks located in /Library/Frameworks. I'm not sure if the build tools (here, cmake) are smart enough to find these Frameworks, because I haven't tried. I will consider posing this question to the community.
Fixed it... sort of.
Fixed it.
I uninstalled with brew uninstall matplotlib and then installed with pip install matplotlib. The pip version now works. although I think something is wrong with my code because I don't get an image output.
I uninstalled all of my installations of python and then installed ipython, which worked fine. Also, I was forgetting to add plt.show(); after my imshow(); commands... :-( .... but at least someone else has made this mistake before me ...
Refer to this page for very thorough help with any matplotlib imshow issues:
matplotlib does not show my drawings although I call pyplot.show()
You can try to run python with Anaconda and check the version of freetype in your conda environment.
I got the same type of error when I try to install opencv in conda. And finally it was solved by one command:
conda update freetype
Two steps to solve the problem:
Step 1: Updating freetype and coping the .dylib to the anaconda lib folder:
brew upgrade freetype
cp /usr/local/Cellar/freetype/2.10.4/lib/libfreetype.dylib ~/opt/anaconda3/lib/
Step 2: Following the import sequence as below:
import matplotlib
matplotlib.use('PS')
import matplotlib.pyplot as plt
Found one immediate solution that worked for me.
Due to multiple projects in same environment, my matplotlib was not supporting new changes.
pip3 uninstall matplotlib
pip3 install matplotlib
Check path tou your image (and doublecheck)
This is in your traceback:
"Reason: image not found"
Also there is no need to use ';' in python.
One of the graph generation files of Python is Matplotlib("http://matplotlib.org/").
I am using Python3.2.1 on Windows7(64bit) O/S.
I am trying to download the same to run matplotlib.animation.
If any one of the esteemed members of the group may kindly suggest me how to download
the same.
Thanks in Advance,
Regards,
Subhabrata Banerjee.
I can not import matplotlib.pyplot/matplotlib.pylab and if I have to download where from I may download? I am using Python3.2.1 on Windows7(64 bit).
But without a separate download how come matplotlib.animation is fine?
Regards,
Subhabrata.
I dont believe full support of python 3 has been added to matplotlib. Here is the status page.
It will support it on the next release.
If you want to use matplotlib with python. I believe you should use python 2.7 because Python 3 has massive changes that broke backward compatibility.
You can use pip to install the matplotlib by following command:
pip install matplotlib
It will automatically handle download and dependency task for you.
For how to install pip under Windows, refer here: How do I install pip on Windows?