libpng version incompatibility in fresh installation of IPython - macos

I used this guide to install the "scientific stack" for Python (OSX 10.9.2, brewed Python 2.7.6, IPython 2.0, matplotlib 1.3.1, libpng 1.6.10). Everything was looking good.
However, trying to run a simple plot in IPython's notebook environment with --pylab=inline gives me this error:
/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/core/formatters.py:239: FormatterWarning: Exception in image/png formatter: Could not create write struct
FormatterWarning,
And in the terminal it says: libpng warning: Application built with libpng-1.5.17 but running with 1.6.10
I have no other libpng installed as far as I can tell. I tried deleting all files beginning with libpng from /usr/local/ and reinstalling everything, to no avail. The output from building matplotlib (pip install matplotlib) contains:
BUILDING MATPLOTLIB
matplotlib: yes [1.3.1]
python: yes [2.7.6 (default, Mar 16 2014, 15:04:47) [GCC
4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38)]]
platform: yes [darwin]
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [version 1.8.1]
dateutil: yes [using dateutil version 2.2]
tornado: yes [using tornado version 3.2]
pyparsing: yes [using pyparsing version 2.0.1]
pycxx: yes [Couldn't import. Using local copy.]
libagg: yes [pkg-config information for 'libagg' could not
be found. Using local copy.]
freetype: yes [version 17.2.11]
png: yes [version 1.6.10]
OPTIONAL SUBPACKAGES
sample_data: yes [installing]
toolkits: yes [installing]
tests: yes [using nose version 1.3.1]
OPTIONAL BACKEND EXTENSIONS
macosx: yes [installing, darwin]
qt4agg: yes [installing, Qt: 4.8.6, PyQt4: 4.10.4]
gtk3agg: no [Requires pygobject to be installed.]
gtk3cairo: no [Requires cairo to be installed.]
gtkagg: no [Requires pygtk]
tkagg: yes [installing, version 81008]
wxagg: no [requires wxPython]
gtk: no [Requires pygtk]
agg: yes [installing]
cairo: no [cairo not found]
windowing: no [Microsoft Windows only]
OPTIONAL LATEX DEPENDENCIES
dvipng: no
ghostscript: no
latex: no
pdftops: no
So it seems to me matplotlib should be compiled against libpng 1.6.10? Can someone help me figure out what's going on?

An expansion of the answer provided by #glenn-randers-pehrson:
pip uninstall matplotlib
cd /opt/X11/include/libpng15
mv png.h _png.h
mv pngconf.h _pngconf.h
mv pnglibconf.h _pnglibconf.h
pip install matplotlib
(if needed remove the old directory or use the force option)
(now move the .h files back to their original locations)

Look for old header files beginning with "png" (png.h, pngconf.h, perhaps others) and remove them.

For the sake of documentation (following on from above comments):
Remove X11
launchctl unload /Library/LaunchAgents/org.macosforge.xquartz.startx.plist
sudo launchctl unload /Library/LaunchDaemons/org.macosforge.xquartz.privileged_startx.plist
sudo rm -rf /opt/X11* /Library/Launch*/org.macosforge.xquartz.* /Applications/Utilities/XQuartz.app /etc/*paths.d/*XQuartz
sudo pkgutil --forget org.macosforge.xquartz.pkg
Then,
if you have matplotlib / python installed, run the following as appropriate:
pip uninstall matplotlib
pip uninstall ipython
Then,
pip install matplotlib
pip install ipython
If necessary, XQuartz can be re-installed from https://www.macupdate.com/app/mac/26593/xquartz.
[Note: This does re-add the /opt/X11/include/libpng15/png.h etc files, but ipython worked fine afterwards.]

While it is a bit ridiculous having multiple copies of libpng around, this problem results from the path for the pip compiler and python being different. You could also fix this problem through the path, and then recompiling, but the above solutions work too.

Related

how do I update xarray?

How can I update xarray? I tried:
>>> import xarray
>>> xarray.show_versions
<function show_versions at 0x7fcfaf2aa820>
But I cannot find any documentation how to read this, or how to update to a new version of xarray.
I was not the person to install it on the computer, so I do not know if it was through anaconda or something else. Is there a way to find this out?
xarray.show_versions is a function, which prints the versions of xarray and its dependencies.
To get just the version of xarray, you can check the __version__ property of the module.
Updating xarray is best done with pip or conda, depending on how you installed it in the first place.
import xarray as xr
print(xr.__version__)
# '0.18.2'
xr.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.8.8 (default, Feb 19 2021, 18:07:06)
[GCC 8.3.0]
python-bits: 64
OS: Linux
OS-release: 5.11.0-27-generic
machine: x86_64
processor:
byteorder: little
LC_ALL: C.UTF-8
LANG: C.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.0
libnetcdf: 4.7.4
xarray: 0.18.2
pandas: 1.2.4
numpy: 1.20.3
scipy: 1.6.3
netCDF4: 1.5.6
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: 2.8.3
cftime: 1.5.0
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.2.3
cfgrib: None
iris: None
bottleneck: 1.3.2
dask: 2021.05.0
distributed: 2021.05.0
matplotlib: 3.4.2
cartopy: None
seaborn: None
numbagg: None
pint: None
setuptools: 53.0.0
pip: 21.1.1
conda: None
pytest: None
IPython: 7.23.1
sphinx: None
To update xarray:
pip install --upgrade xarray
or
conda update xarray
To see if it was installed using conda or pip, run conda list xarray. If it was installed using pip, it should state pypi in the Channel column.
This is for those who want to do through GUI and who use software like pycharm, spyder, or other similar softwares.
SO, try finding 'python interpreter' in the settings. Most softwares shows the existing packages, current version,latest version(for example see the image of pycharm)
There is option to select the version that you want. for example there are times, when a module is in its beta phase and is not stable in usage. so, you can specify the latest stable version too. It is applicable for any module and not limited to xarray.

Installing PyAudio for Python 3 on OS X

I would like to construct a "Hello, World!" of audio for OS X/Python 3 that populates a buffer with a sine wave and plays it through the speakers.
My basic options are listed in Audio in Python.
Playing Music with Python demonstrates several of these, but it omits details of installation.
I'm trying PyAudio first.
PyAudio has a section on OS X, saying "For Python 3 support, first install MacPython 3.3"
This confuses me greatly. OS X ships with Python. Also, I have used Homebrew to install Python 3. I've never come across the term MacPython, so I'm not sure if what I have is MacPython or not. And if it isn't, then I want to install PyAudio for the Python I currently have. I don't want to have to download some special Python to use it. That would be completely defeating the purpose.
I also tried "pip3 install pyaudio", with the following (negative) results:
⤐ pip3 install pyaudio
Collecting pyaudio
Could not find a version that satisfies the requirement pyaudio (from versions: )
Some externally hosted files were ignored as access to them may be unreliable (use --allow-external pyaudio to allow).
No matching distribution found for pyaudio
✘
pi#piBookAir.local ~ /Users/pi:
⤐ pip install --allow-external pyaudio
You must give at least one requirement to install (see "pip help install")
✔
pi#piBookAir.local ~ /Users/pi:
⤐ pip install pyaudio --allow-external pyaudio
Collecting pyaudio
Could not find a version that satisfies the requirement pyaudio (from versions: )
Some insecure and unverifiable files were ignored (use --allow-unverified pyaudio to allow).
No matching distribution found for pyaudio
✘
It's frustrating that it is so awkward to even get onto the first rung of the ladder.
How can I correctly install PyAudio for Python 3 on my (up-to-date) OS X? Should I use Homebrew? Should I use pip3?
PS: PyAudio with Homebrew -- I hope I don't have to follow this solution
PPS: Music software written in Python lists a daunting number of possible solution paths -- I'm not at all certain PyAudio is the best path. Is there a better one?
Use Homebrew to install the prerequisite portaudio library, then install PyAudio using pip:
brew install portaudio
pip install pyaudio
Notes:
If not already installed, download Homebrew.
pip will download the PyAudio source and build it for your version of Python.
Homebrew and building PyAudio also require installing the Command Line Tools for Xcode (more information).
(This works on Mac OS X)
At first PyAudio has a portaudio dependency:
brew install portaudio
And then run:
pip3 install pyaudio --global-option="build_ext" --global-option="-I/usr/local/include" --global-option="-L/usr/local/lib"
Or sometimes magic happens, if you use:
python3 -m pip install pyaudio --global-option="build_ext" --global-option="-I/usr/local/include" --global-option="-L/usr/local/lib"
Unfortunately, 王淳龙's solution did not work for me (macOS v10.15.6 (Catalina), Python 3.8.5). The following errors persisted:
gcc-5 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/tom/anaconda3/include -arch x86_64 -I/Users/tom/anaconda3/include -arch x86_64 -DMACOSX=1 -I/Users/tom/anaconda3/include/python3.6m -c src/_portaudiomodule.c -o build/temp.macosx-10.9-x86_64-3.6/src/_portaudiomodule.o
In file included from src/_portaudiomodule.c:33:0:
/usr/local/include/pa_mac_core.h:48:33: fatal error: AudioUnit/AudioUnit.h: No such file or directory
compilation terminated.
error: command 'gcc-5' failed with exit status 1
Therefore, I had to link the missing libraries manually:
cd /usr/local/include/
ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/AudioUnit.framework/Versions/A/Headers AudioUnit
ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/AudioToolbox.framework/Versions/A/Headers AudioToolbox
ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/CoreAudioTypes.framework/Versions/A/Headers CoreAudioTypes
ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/CoreFoundation.framework/Versions/A/Headers CoreFoundation
ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/CoreAudio.framework/Versions/A/Headers CoreAudio
This solved the dependencies, but not the following compiler problem:
In file included from /usr/local/include/AudioToolbox/AUComponent.h:65:0,
from /usr/local/include/AudioUnit/AUComponent.h:1,
from /usr/local/include/AudioUnit/AudioUnit.h:11,
from /usr/local/include/pa_mac_core.h:48,
from src/_portaudiomodule.c:33:
/usr/local/include/AudioToolbox/AudioComponent.h:509:39: error: expected ')' before '^' token
void (^inCompletionHandler)(AudioComponentInstance __nullable, OSStatus))
^
Forcing the use of system-wide gcc (Apple Clang version 11.0.3) instead of gcc-5 solved the problem. I did that by uninstalling gcc#5 and linking gcc-5 to gcc. However, there must be a more elegant way.
Today I also encountered this problem and searched a lot. Finally I found a solution:
brew install portaudio
pip install pyaudio
Python vs MacPython:
AFAIK there is no such thing as MacPython — or at least not from the developers of Python. I can only assume whoever created the link on the PyAudio page tried to get creative with the name and were actually meaning the "Mac OS X 64-bit/32-bit installer containing Python v3.3".
The link to the mysteriously named MacPython leads to the main Python download page that features the most recent stable versions (which as of today is v3.4.3):
https://www.python.org/downloads/release/python-343/
PyAudio:
PyAudio can be compiled from source, outlined here, which might yield better results.

Installing Cairo on Mac - Could not find libpng in the pkg-config search path

checking whether cairo's PNG functions feature could be enabled... no
I have been following the setup for configuring node canvas. Cairo is needed but i am having issues trying to set it up. https://github.com/Automattic/node-canvas/wiki/Installation---OSX
If libpng fails and you get the error "error: recommended PNG functions feature could not be enabled", try installing this binary and re-running the configure step.
I followed above by installing the binaries on Mac OS 9 and run the configuration command and still no luck. I am running the install shell script in node-canvas repository:
https://github.com/Automattic/node-canvas/blob/master/install
In my /usr/local/lib I currently have:
dtrace libjpeg.8.dylib libpng.a libpng14.a
libfreetype.6.dylib libjpeg.a libpng.dylib libpng14.dylib
libfreetype.a libjpeg.dylib libpng.la libpng14.la
libfreetype.dylib libjpeg.la libpng12.0.dylib libpng15.15.dylib
libfreetype.la libpixman-1.0.dylib libpng12.0.dylib.dSYM libpng15.15.dylib.dSYM
libgif.4.1.6.dylib libpixman-1.a libpng12.a libpng15.a
libgif.4.dylib libpixman-1.dylib libpng12.dylib libpng15.dylib
libgif.a libpixman-1.la libpng12.la libpng15.la
libgif.dylib libpng.3.dylib libpng14.14.dylib node_modules
libgif.la libpng.3.dylib.dSYM libpng14.14.dylib.dSYM pkgconfig
Libpng-1.6.10 has been replaced by libpng-1.6.12.
In your install script, change
LIBPNG="http://downloads.sourceforge.net/project/libpng/libpng16/1.6.10/libpng-1.6.10.tar.gz"
to
LIBPNG="http://downloads.sourceforge.net/project/libpng/libpng16/1.6.12/libpng-1.6.12.tar.gz"
I have a set of detailed instructions for building cairo here:
https://github.com/soegaard/racket-osx-libs
There resulting libraries are here:
https://github.com/soegaard/racket-osx-libs/tree/master/lib

Error in Installing the Cairo R Package

I am attempting to install the Cairo package in the development version of R on Mac OS X 10.7.4, but I'm running into an issue that I cannot resolve.
I have installed Cairo with homebrew (i.e., brew install cairo) and received the following message:
==> Caveats This formula is keg-only, so it was not symlinked into /usr/local.
Mac OS X already provides this program and installing another version
in parallel can cause all kinds of trouble.
The Cairo provided by Leopard is too old for newer software to link
against.
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add its lib
& include paths to your build variables:
LDFLAGS -L/usr/local/Cellar/cairo/1.12.2/lib
CPPFLAGS -I/usr/local/Cellar/cairo/1.12.2/include
With the above message in mind, I attempted to install the Cairo package from R-Forge with the following R command:
install.packages("Cairo", repos="http://www.rforge.net/", configure.args = c("CAIRO_LIBS=/usr/local/Cellar/cairo/1.12.2/lib", "CAIRO_CFLAGS=/usr/local/Cellar/cairo/1.12.2/include/cairo"))
I receive the following error:
checking cairo.h usability... no
checking cairo.h presence... no
checking for cairo.h... no
configure: error: Cannot find cairo.h!
Please install cairo (http://www.cairographics.org/) and/or set
CAIRO_CFLAGS/LIBS correspondingly. ERROR: configuration failed for package ‘Cairo’
I repeated the same command without the repos argument (by default, I use the FHCRC mirror) with the same result.
At this point, the problem seems obvious: the file cairo.h is not present. But then I listed the files in the include/cairo directory. Here's the response:
ls /usr/local/Cellar/cairo/1.12.2/include/cairo
cairo-deprecated.h cairo-ft.h
cairo-ps.h
cairo-script-interpreter.h
cairo-svg.h
cairo-xcb.h
cairo-xlib.h
cairo-features.h
cairo-pdf.h
cairo-quartz.h
cairo-script.h
cairo-version.h
cairo-xlib-xrender.h
cairo.h
So, I'm pointing the installation of the Cairo package to the appropriate place, but the error persists. I have tried variations, such as CAIRO_CFLAGS=/usr/local/Cellar/cairo/1.12.2/include, with no luck.
Thoughts? Any help you can provide is greatly appreciated.
In case it's necessary, here is my sessionInfo:
R Under development (unstable) (2012-08-08 r60208) Platform: x86_64-apple-darwin11.4.0 (64-bit)
locale: [1]
en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages: [1] stats graphics grDevices utils
datasets methods base
other attached packages: [1] BiocInstaller_1.5.12
loaded via a namespace (and not attached): [1] tools_2.16.0
I had similar issue with cairo config error, and I already installed cairo with homebrew. Try below
brew install pkg-config
This solved mine problem.
A coworker and I just fixed the problem by ignoring all of what I typed above. Rather, we installed Cairo and all of its dependencies from source manually, thereby bypassing the usage of brew or variants like port. This worked like a charm, so I am not entirely sure what was wrong above.
After trying everything listed here, I found this blog post about installing the "full R package" using brew: https://luispuerto.net/blog/2018/05/11/installing-r-with-homebrew-with-all-the-capabilities/
What finally worked for me was building R explicitly with cairo (brew's default R tap uses --without-cairo and simply editing the tap did not solve the issue for me).
Works like a charm for me with R 4.0.2, cairo 1.16.0_3 under macOS Catalina 10.15.6.

MacPorts - Installing Port, Dependencies Failed

I am attempting to install xulrunner on OSX 10.6.3 using the following:
sudo port install xulrunner
However, I am receiving the following error:
nat-10-200-136-126:phoneyc-new $ sudo port install xulrunner
---> Computing dependencies for xulrunner
---> Activating zlib #1.2.5_0
Error: The following dependencies failed to build: gconf dbus-glib glib2 zlib gtk-doc docbook-xml docbook-xml-4.1.2 xmlcatmgr docbook-xml-4.2 docbook-xml-4.3 docbook-xml-4.4 docbook-xml-4.5 docbook-xml-5.0 docbook-xsl gnome-doc-utils iso-codes libxslt libxml2 p5-xml-parser py26-libxml2 python26 bzip2 db46 gdbm openssl readline sqlite3 tk Xft2 fontconfig freetype xrender xorg-libX11 xorg-bigreqsproto xorg-inputproto xorg-kbproto xorg-libXau xorg-xproto xorg-libXdmcp xorg-util-macros xorg-xcmiscproto xorg-xextproto xorg-xf86bigfontproto xorg-xtrans xorg-renderproto tcl xorg-libXScrnSaver xorg-libXext xorg-scrnsaverproto rarian getopt intltool gnome-common p5-getopt-long p5-pathtools p5-scalar-list-utils gtk2 atk cairo libpixman libpng jasper jpeg pango shared-mime-info tiff xorg-libXcomposite xorg-compositeproto xorg-libXfixes xorg-fixesproto xorg-libXcursor xorg-libXdamage xorg-damageproto xorg-libXi xorg-libXinerama xorg-xineramaproto xorg-libXrandr xorg-randrproto orbit2 libidl policykit heimdal lcms libcanberra gstreamer bison flex gzip texinfo lzmautils libvorbis libogg libnotify nss xorg-libXt xorg-libsm xorg-libice
Error: Status 1 encountered during processing.
Before reporting a bug, first run the command again with the -d flag to get complete output.
nat-10-200-136-126:phoneyc-new$
I am unsure how to correct this issue, so any help would be much appreciated!
Did you try running with the -d flag?
You'd probably be best served by running:
sudo port install gconf
sudo port dbus-glib
etc
to see which exactly is breaking.
However, it might be possible this is using some Linux only code that might not be available in Mac OS X

Resources