pip install matplotlib fails on mavericks with homebrew - python

I am trying to install the Scipy python stack, but having issues.
I have a new mac os with mavericks (10.9).
I have installed homebrew and am using brew to manage installations.
I used
% brew install python
then (I verified pip is from my homebrew installation)
% pip install numpy [this works]
% pip install scipy [this works]
% pip install matplotlib OR pip install http://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.3.1/matplotlib-1.3.1.tar.gz
Both fail with the same error. After checking the backend, I get
Fatal Python error: PyThreadState_Get: no current thread
The error message from mac os X (the pop up error window) shows errors very similar to those in the previous thread
Homebrew + Python on mac os x 10.8: Fatal Python error: PyThreadState_Get: no current thread importing mapnik
It seems I need to fix the python bindings, as some of them linked against the /System/Library python that ships with the mac. What is not clear to me from the above post is
which of the Binary Images need to be "re-linked"? all of them? some seem quite general an not related to matplotlib
how do I actually use install_name_tool to fix the link? As I mentioned, some seem quite general - do I really want to change the path? Do I cp the dylib from old to new?
I have also tried
brew uninstall python
and re-brewing, all to get the same error. I am trying not to use EPD because EPD installs its own libxml2 and others, which I need for other software I will install, and this has caused me problems on an old machine. I am open to considering a virtualenv, but was hoping to learn to just fix my current problem if possible.
Thanks,
Andre
PS, when pip install matplotlib`, the following warning appears, which seems odd because matplotlib is such a staple piece of software
You are installing an externally hosted file. Future versions of pip will default to disallowing externally hosted files.
You are installing a potentially insecure and unverifiable file. Future versions of pip will default to disallowing insecure files.

This is an issue in pygtk. You can test it with brew (it should throw the same error):
brew test pygtk
I ran into the same problem, and got past that error with the following steps from https://github.com/mxcl/homebrew/issues/13654
brew rm py2cairo
brew install py2cairo
You can test that pygtk is working using brew test pygtk again.
I'm still having other problems getting pip install matplotlib to work, so you may also run into more problems, but that should get you past that particular issue.

I had the same problem, and after some experimentation it seems that installing under Python 3 works more reliably. i.e. this installed without error:
pip3 install matplotlib
I then had to re-install everything else using pip3, and make sure I was running under python3 at execution time.

brew install freetype
it works on mac os sierra!

Related

FFmpeg installation requiring python uninstallation on Mac

Did brew install ffmpeg, installs some packages and gives this error :
Error: python is already installed from !
Please brew uninstall python first."
I have python3.6.5 installed via brew, for using Tensorflow etc. No other python version is installed via brew right now. Why is this error coming up? What version does FFmpeg need?
Earlier I actually uninstalled python and that broke my system in many frustrating ways. I had to delete everything and start over. What is a safer way to get this working?

Pillow is installed, but still getting "ImportError: No module named PIL"

I did find this question asked by few more people, but none of those exactly met my situation, so asking here myself.
I've (rather had) two versions of Python (2.7 and 3.4.3) on my Mac running the latest MacOS High Sierra. As I understand, the v2.7 comes as default installation with the MacOS. And I installed the 3.4.3 (from .dmg file downloaded from the python site). Thus now, the python command defaults to the 2.7, while python3 points to the 3.4.3 in the terminal.
While trying to learn, I tried a python script that uses
import PIL and from PIL import Image
But when running, this gave the error ImportError: No module named PIL.
Upon research on google, I figured out to install PIL and Pillow using
sudo pip install Pillow
It installed correctly, but I'm still getting the same error.
To remove the confusion, I decided to remove the python 3.4.3 from the system. But even after it's removed, I still get the same error.
Even pip list displays Pillow 5.1.0 alright.
So right now, I've only Python 2.7, and the error persists, while Pillow is also in there.
which python gives /opt/local/bin/python as the path.
Does any of the above ring a bell? Any ideas, what else could be missing here?
Phew, finally found the issue. Thanks #Yash for the pointers.
Incidentally I did a which -a python and surprisingly got this output:
/opt/local/bin/python
/usr/bin/python
Damn, I don't remember when I installed a second 2.7 version on the /opt/local/bin folder (probably via macports). Alright, removed the confusion, deleted this python, so now I'm left only with the system installed python at /usr/bin.
And now the imports all run perfectly fine as expected. :-)
Try this,
sudo pip install image
I hope it works! One more thing, do check if you're running python3 filename.py instead of python filename.py, if you want to install it for Python 3, run the command,
sudo pip3 install Pillow
Basic Installation:
pip install Pillow
Windows Installation:
pip install Pillow
Reference: https://pillow.readthedocs.io/en/stable/installation.html
Try this. It worked for me
pip install --upgrade --force-reinstall pillow
If you get something like access denied error run the below command
pip install --upgrade --force-reinstall pillow --user

How to install Numpy & pip3 for python3.x when they were installed in python2.7? Using Conda?

I want to write program in python3 (3.5), hence I installed python3 next to the pre-installed python2 (2.7) on Mac OS X El Captian.
Since my terminal runs python2.7 by default and Numpy is already installed for it, I put alias python=python3 and expected to be able to install Numpy for python3. when I type pip install numpy. This was the generated message:
Requirement already satisfied (use --upgrade to upgrade): numpy in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
I also noticed that I have no pip3 even though I am using python3: python --version returned Python 3.5.2, but pip3 install numpy got me -bash: pip3: command not found.
So my questions are:
1) How to install Numpy for python3.x when Numpy is installed on python2.x?
2) How to get pip3?
3) Is it better to use virtual environments, such as Conda, instead of juggling between python2 and python3 on the system?
Thank you from a total n00b
------------------- Update -------------------
Reinstalling python3 also fixed another problem in my case.
When I ran brew doctor, one of the warning message I got was:
Warning: You have unlinked kegs in your Cellar Leaving kegs unlinked can lead to build-trouble and cause brews that depend on those kegs to fail to run properly once built. Run brew link on these: python –
This is a result of me running brew unlink python in order to fix
"Python quit unexpectedly"
when I launch Vim and also
"The ycmd server SHUT DOWN"
Both seem to relate to the YouCompleteMe autocomplete plugin which I downloaded for Python.
I got my idea of removing symlinks from here and here
However, Homebrew evidently did not like the absence of those 39 symlinks.
After uninstall (brew uninstall python3) and then re-install python3 (brew install python3) as Toby suggested, Homebrew gave me
You can install Python packages with
pip3 install <package>
Then when I pip3 install numpy and pip3 install scipy, both executed successfully.
To my surprise, symlinks created during Python installation used to cause aforementioned error messages for Python and YouCompleteMe, but now I open python files using Vim without crash from a fresh Python installation, which definitely created the symlinks.
------------------- Update2 ------------------
After re-installing Anaconda2, the same YouCompleteMe error came back. I suspect Anaconda messed up symlinks.
I would recommend using the Anaconda Python distribution.
The main reasons are as such:
You will have a Python distribution that comes with numpy and the rest of the Scientific Python stack.
The Anaconda Python will be installed under your home directory, with no need for sudo-ing to install other packages.
conda install [put_packagename_here] works alongside pip install [put_packagename_here]; conda install is much 'cleaner' (IMHO, differing opinions are welcome).
If you have a Python 3 environment as your default, then pip works out-of-the-box without needing to remember to do pip3.
conda environments are easier to manage than virtualenv environments, in my opinion. And yes, you can have Python 2 alongside Python 3.
I once messed up my system Python environment - the one that came with my Mac - and it broke iPhoto (back in the day). Since then, I became convinced of needing separate, atomic environments for different projects.
I've detailed more reasons in a personal blog post.
Other distributions, of course, are all good, provided they give you what you need :).
The simplest way on a Mac is with Homebrew:
http://brew.sh/
Install Homebrew, then run:
brew install python3 pip3
Edit --
Python3 includes pip3, but Homebrew occasionally has trouble linking to the correct versions, depending on what has been installed. Running the following command:
brew doctor
And if you see errors relating to python or unlinked kegs, try running:
brew uninstall python python3
And reinstalling after checking brew doctor.
https://unix.stackexchange.com/questions/233519/pip3-linked-to-python-framework-instead-of-homebrew-usr-local-bin

Installing OpenMDAO

I am trying to install OpenMDAO, which is an open source framework that uses python. So before I get to it, it needs 3 packages:
Fortran Compiler
NumPY
ScyPy
Which I did install using homebrew:
brew install gfortran
sudo easy_install-2.6 pip
sudo pip-2.6 install numpy
sudo pip-2.6 install scipy
Now, to install OpenMDAO, I'm supposed to be in the OpenMDAO folder and at that level I should run this script:
python go-openmdao-dev.py
But I keep getting this error:
ERROR: the following prerequisites could not be imported: ['scipy'].
So I was talking to the people at OpenMDAO, and it seems that I need to use is python2.6 - although I'm not certain, so my guess is that all the packages I installed are for python 2.7 which I downloaded since it was recommended in the python website.
The one that comes with Mac was not. So when I type in terminal the following:
python2.6
It actually runs that version. So at this point I don't know if I have to go run the script in python 2.6, but if so, I have no idea how to do it. I tried doing this and it did not work:
If anyone is familiar with the environment or just with python itself and has any suggestions, I'll really appreciate it.
This question was answered on the OpenMDAO support forum:
http://openmdao.org/forum/questions/744/error-the-following-prerequisites-could-not-be-imported-scipy
The solution was to install scipy and numpy for python2.7. The original poster first installed them for python2.6, but then ran the go-openmdao.py script with python2.7. Once all the pre-reqs were installed for 2.7, it worked.
I had the same problem after downloading scipy from a .dmg. I uninstalled, and then reinstalled from source: http://sourceforge.net/projects/scipy/files/scipy/0.12.0/ and then the openmdao installer recognized scipy.
This may be useful (from INSTALL.txt in scipy-0.12.0.tar.gz):
To test SciPy after installation (highly recommended), execute in
Python
>>> import scipy
>>> scipy.test()
To run the full test suite use
>>> scipy.test('full')
Please note that you must have version 0.10 or later of the 'nose'
test framework installed in order to run the tests. More information
about nose is available on the website__.
__ http://somethingaboutorange.com/mrl/projects/nose/

Import Error: No module named AppKit

I use Mac OS X Lion and Python 2.7. I am new to python. Can anyone tell me how to import AppKit and PyObjC to Python. But i get the errors when trying to import Import Error: No module named AppKit or 'Import Error: No module named PyObjC.
Trying easy_install does not help either.
What can i do to import these 2 modules?
If not already installed, install pip by running:
sudo easy_install pip
Then run:
## install for all users
sudo pip install pyobjc
or
## install for current user only
pip install pyobjc --user
NOTE: the general recommendation is to avoid using the system python, and use instead a user-maintained version, for example installed via brew install python3, macports, conda or whatever you already use for third party dependencies.
If you're on Mac it could be you're using the incorrect pip version, try sudo pip3 install -U pyobjc that solved it for me.
This a good guide on how to install PyObjc: http://ioanna.me/2009/09/installing-pyobjc-xcode-templates-in-snow-leopard/
When I was trying to install PyObjc I found it quite hard, but after a while, (and lots of google searches) I got it working.
Edit
I've found a more modern guide on how to do this. Download the templates and put them into your ~/Library/Developer/Xcode/Templates/ directory, and everything should work correctly.
If you are using PyCharm, you should install PyObjC package manually within it because of venv I guess. This was the only working solution for me.
In my case none of them worked. I was using Anaconda in my mac, later I discovered that the main issue with the Anaconda. Then I installed PyObjC with it's all supporting libraries inside Anaconda in a specific Environment.
I run the command line by clicking the Environment play icon and run my script.
It worked without any issues :)

Categories

Resources