Incompatible libpng versions when running matplotlib - python

I'm trying to use facebook research's Detectron. When I run it, it gives me the following error:
libpng warning: Application built with libpng-1.6.21 but running with 1.5.12
Traceback (most recent call last):
File "tools/infer_simple.py", line 147, in <module>
main(args)
File "tools/infer_simple.py", line 139, in main
kp_thresh=2
File "/home/sid/DETECTRON/detectron/lib/utils/vis.py", line 391, in vis_one_image
fig.savefig(os.path.join(output_dir, '{}'.format(output_name)), dpi=dpi)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1834, in savefig
self.canvas.print_figure(fname, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2267, in print_figure
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.py", line 2595, in print_pdf
file.finalize()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.py", line 595, in finalize
self.writeImages()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.py", line 1430, in writeImages
ob.id, smaskObject)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.py", line 1416, in _writeImg
self._writePng(data)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.py", line 1366, in _writePng
_png.write_png(data, buffer)
RuntimeError: Could not create write struct
I'm running Ubuntu 16.04. I don't know where the application is finding the libpng 1.5.12 version. I could not find it in my system. I installed libpng16-16. It still gives me the same error. I tried out other solutions suggested on the platform but they didn't work

I guess the problem is that you sudo pip installed matplotlib and that the libpng version that is shipped with the manylinux installation package of matplotlib is confused with the libpng version that was installed by apt. I recommend using matplotlib inside a virtual environment.
# create venv
virtualenv ~/matplotlib-venv
# activate venv
source ~/matplotlib-venv/bin/activate
# install matplotlib
pip install matplotlib
pip install <everything else you need>
# run your script
python ~/path/to/your/srcript.py

Related

cellprofiler install will not run - version conflict

Im trying to run the bioimaging analysis package 'cell profiler' on Ubuntu 16.04, following the source installation instructions provided by the developers:
https://github.com/CellProfiler/CellProfiler/wiki/Source-installation-(Ubuntu-16.04-LTS)
However when I attempt to run cellprofiler from terminal, i encounter the following error code, which seems to be telling me there is a version conflict of matplotlib. Cell profiler seems to be running using python2.7, not python3.6 which is also set up on this machine, so this could be the source of the problem?
Error message in full:
Traceback (most recent call last):
File "/usr/local/bin/cellprofiler", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3112, in <module>
#_call_aside
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3096, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3125, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 580, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 593, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 786, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (matplotlib 1.5.1 (/usr/lib/python2.7/dist-packages), Requirement.parse('matplotlib>=2.0.0'), set(['scikit-image']))
It says your matplotlib is version 1.5.1 when the library you're trying to install requires at least 2.0.0 version.
Try pip install -U matplotlib
As far as I know Cellprofiler is still using Python 2.7. They will transition to Python 3 with the newest version (CP 4.0). So at the moment you can not run it with python 3
As mentioned by Anja CellProfiler requires Python 2.7. When I installed CellProfiler on a Ubuntu 18.04 machine running Python 3.6, I created an virtual environment for CellProfiler with Python 2.7 and installed all required packages into this environment.
You can find a detailed description how to do this here:
https://github.com/CellProfiler/CellProfiler/wiki/Conda-Installation
By following this approach you can run CellProfiler with Python 2.7 via the virtual environment while you are still able to use Python 3.6 for your other applications/projects as before.

How to resolve the dependency hell in order to install matplotlib?

I want to install matplotlib via pip. However, I run into circular issues and at certain point I got stuck. Running pip in the terminal produces:
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 3080, in <module>
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 3066, in _call_aside
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 3093, in _initialize_master_working_set
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 651, in _build_master
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 952, in require
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 839, in resolve
pkg_resources.DistributionNotFound: The 'pip==1.5.4' distribution was not found and is required by the application
I tried to fix this with easy_install, but it produced the following error message:
Traceback (most recent call last):
File "/usr/bin/easy_install", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 3080, in <module>
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 3066, in _call_aside
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 3093, in _initialize_master_working_set
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 653, in _build_master
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 666, in _build_from_requirements
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 839, in resolve
pkg_resources.DistributionNotFound: The 'setuptools==3.3' distribution was not found and is required by the application
Running sudo apt-get install python-setuptools says that I already have the newest version.
My OS is Ubuntu 14.04. I have tried many different approaches to fix the issue and probably ended up doing even further harm. I don't recall everything I did and how I ended up at this stage, so unfortunately cannot give further info.
My objective is to have matplotlib installed in the end and have a stable state of all my python related libraries. Any solution will work, so I don't mind reinstalling everything or whatever would fix the issue.
UPDATE
Running sudo apt-get build-dep python-matplotlib produces
Reading package lists... Done
Building dependency tree
Reading state information... Done
Picking 'matplotlib' as source package instead of 'python-matplotlib'
E: Unable to find a source package for matplotlib
Whereas sudo apt-get install python-matplotlib produces
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-matplotlib is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
However, matplotlib is still not found from python.
Try:
sudo apt-get build-dep python-matplotlib
This should install the dependecies that matplotlib needs via the Ubuntu package management system (because a lot of those dependencies are not trivial to install with pip), enabling you to:
pip install matplotlib
Source: Matplotlib documentation
I have used this process on both Ubuntu 14.04 and Kubuntu 15.10 to install the newest, stable matplotlib (in virtual environments, but that shouldn't make a difference).

traitlets.traitlets.TraitError in Pycharm

I am a beginner in python. I am facing the following problem.
Whenever I start pycharm Community edition (version 5.0.3), the Python console fails to starts and shows the following error:
usr/bin/python2.7 /usr/lib/pycharm-community/helpers/pydev/pydevconsole.py 53192 49994
Traceback (most recent call last):
File "/usr/lib/pycharm-community/helpers/pydev/pydevconsole.py", line 488, in <module>
pydevconsole.StartServer(pydev_localhost.get_localhost(), int(port), int(client_port))
File "/usr/lib/pycharm-community/helpers/pydev/pydevconsole.py", line 330, in StartServer
interpreter = InterpreterInterface(host, client_port, threading.currentThread())
File "/usr/lib/pycharm-community/helpers/pydev/pydev_ipython_console.py", line 26, in __init__
self.interpreter = get_pydev_frontend(host, client_port)
File "/usr/lib/pycharm-community/helpers/pydev/pydev_ipython_console_011.py", line 472, in get_pydev_frontend
_PyDevFrontEndContainer._instance = _PyDevFrontEnd()
File "/usr/lib/pycharm-community/helpers/pydev/pydev_ipython_console_011.py", line 303, in __init__
self.ipython = PyDevTerminalInteractiveShell.instance()
File "/usr/lib/python2.7/dist-packages/IPython/config/configurable.py", line 354, in instance
inst = cls(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/IPython/terminal/interactiveshell.py", line 328, in __init__
**kwargs
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 483, in __init__
self.init_readline()
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 1816, in init_readline
if self.readline_use:
File "/home/vivekruhela/.local/lib/python2.7/site-packages/traitlets/traitlets.py", line 529, in __get__
return self.get(obj, cls)
File "/home/vivekruhela/.local/lib/python2.7/site-packages/traitlets/traitlets.py", line 507, in get
% (self.name, obj))
traitlets.traitlets.TraitError: No default value found for None trait of <pydev_ipython_console_011.PyDevTerminalInteractiveShell object at 0x7f7b0e682cd0>
Process finished with exit code 1
Couldn't connect to console process.
How can I connect to the pycharm console? I have already installed IPython in my system.
I had the same issue.
I solved this by updating ipython.
My version was 3.1.0, upgrading it to 4.1.1 solved it.
in my case:
workon project
pip install -U ipython
I've found that this happened because I had installed ipython version 4.x, and then reverted to 3.2.0, without uninstalling the traitlets more advanced version first. This did the trick then:
pip uninstall ipython[all]
pip uninstall traitlets
pip install ipython==3.2.0
In my case, this was due to a conflicting installation of IPython through pip and apt. Removing the apt-installed version using sudo apt remove ipython fixed the problem.
I initially tried unsuccessfully by trying
pip install -U ipython
But then tried following and it worked:
pip uninstall ipython[all]
pip uninstall traitlets
pip install ipython
Thanks #mirandes

trouble with pip and easy_install to install python packages

I am going to install numpy library as a *.whl file, as numpy-1.9.2rc1+mkl- cp27-none-win32, on my Windows 7 machine...
Here is my approaches to do that, are which pip and easy_install packages...
The odd thing is that both don't work in the case of either Python 3.4 or Python 2.7...
Here are the trace of the attempts in the command prompt:
pip:
"C:\Users\Matinking\Desktop\numpy- 1.9.2rc1+
mkl-cp27-none-win32.whl" f
Exception:
Traceback (most recent call last):
File "c:\python34\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "c:\python34\lib\site-packages\pip\commands\install.py", line 257, in r
InstallRequirement.from_line(name, None))
File "c:\python34\lib\site-packages\pip\req.py", line 172, in from_line
return cls(req, comes_from, url=url, prereleases=prereleases)
File "c:\python34\lib\site-packages\pip\req.py", line 70, in __init__
req = pkg_resources.Requirement.parse(req)
File "c:\python34\lib\site-packages\pip\_vendor\pkg_resources.py", line 2667
in parse
reqs = list(parse_requirements(s))
File "c:\python34\lib\site-packages\pip\_vendor\pkg_resources.py", line 2605
in parse_requirements
line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec")
File "c:\python34\lib\site-packages\pip\_vendor\pkg_resources.py", line 2573
in scan_list
raise ValueError("Expected "+item_name+" in",line,"at",line[p:])
ValueError: ('Expected version spec in', ' C:\\Users\\Matinking\\Desktop\\numer
performance.pdf', 'at', ':\\Users\\Matinking\\Desktop\\numericperformance.pdf'
Storing debug log for failure in C:\Users\Matinking\pip\pip.log
and easy_install:
C:\Python34\Scripts>easy_install.exe "C:\Users\Matinking\Desktop\numpy- 1.9.2rc1+
mkl-cp27-none-win32.whl"
Processing numpy-1.9.2rc1+mkl-cp27-none-win32.whl
Writing C:\Users\MATINK~1\AppData\Local\Temp\easy_install- jr2ijafr\numpy\setup.c
fg
Running numpy\setup.py -q bdist_egg --dist-dir C:\Users\MATINK~1\AppData\Local\T
emp\easy_install-jr2ijafr\numpy\egg-dist-tmp-umy5kseg
This is the wrong setup.py file to run
No eggs found in C:\Users\MATINK~1\AppData\Local\Temp\easy_install-jr2ijafr\nump
y\egg-dist-tmp-umy5kseg (setup script problem?)
Any idea for the problem?!
You should upgrade your pip to version 6.0, the .whl file you're using isn't compatible with earlier versions.
To bump up your pip version on Windows :
python -m pip install -U pip
pip error -> why were you running an install on a pdf? That was never going to work.
easy_install error -> looks like you downloaded a python 2.7 binary and tried to install into a python 3.4 installation.
For scientific stack python, you are hard pressed to beat an Anaconda python distribution.

Python Pip Install "Egg" Error (Pandas and other modules)

Having issues installing some python modules (for example pandas) and also had some issues installing ipython notebook.
This error seems to have come up before for other folks (Python pip install fails: invalid command egg_info), but they were using Python 2.7, whereas I'm using 2.6 (default with my Mac OS 10.6). Also I tried easy_install -U setuptools and pip install --upgrade setuptools but neither worked.
This is the error I get for installing pandas:
Command python setup.py egg_info failed with error code 1 in /private/var/folders/Wm/WmmbYincEnuCrAMtGBudAk+++TM/-Tmp-/pip_build_AWal/pandas
Storing debug log for failure in /Users/AWal/Library/Logs/pip.log
For installing iPython, this is the error that I get:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/commands/install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/req.py", line 1435, in install
requirement.install(install_options, global_options, *args, **kwargs)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/req.py", line 671, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/req.py", line 901, in move_wheel_files
pycompile=self.pycompile,
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/wheel.py", line 341, in move_wheel_files
generated.extend(maker.make_multiple(['%s = %s' % kv for kv in console.items()]))
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/_vendor/distlib/scripts.py", line 316, in make_multiple
filenames.extend(self.make(specification, options))
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/_vendor/distlib/scripts.py", line 305, in make
self._make_script(entry, filenames, options=options)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/_vendor/distlib/scripts.py", line 209, in _make_script
self._write_script(scriptnames, shebang, script, filenames, ext)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/_vendor/distlib/scripts.py", line 189, in _write_script
self._fileop.write_binary_file(outname, script_bytes)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/_vendor/distlib/util.py", line 384, in write_binary_file
with open(path, 'wb') as f:
IOError: [Errno 13] Permission denied: '/usr/local/bin/sphinx-apidoc'
Storing debug log for failure in /Users/AWal/Library/Logs/pip.log
Any thoughts on what to do?
UPDATE:
When I do sudo pip install pandas (another module that I can't install), I get a long long traceback with the end error message:
RuntimeError: Broken toolchain: cannot link a simple C program
And traceback (a sample of it of the 100 or so lines) looks like this:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/private/tmp/pip_build_root/pandas/setup.py", line 619, in <module>
**setuptools_kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/core.py", line 113, in setup
File "build/bdist.macosx-10.6-universal/egg/setuptools/dist.py", line 266, in __init__
File "build/bdist.macosx-10.6-universal/egg/setuptools/dist.py", line 312, in fetch_build_eggs
File "build/bdist.macosx-10.6-universal/egg/pkg_resources/__init__.py", line 753, in resolve
File "build/bdist.macosx-10.6-universal/egg/pkg_resources/__init__.py", line 1005, in best_match
File "build/bdist.macosx-10.6-universal/egg/pkg_resources/__init__.py", line 1017, in obtain
File "build/bdist.macosx-10.6-universal/egg/setuptools/dist.py", line 379, in fetch_build_egg
File "build/bdist.macosx-10.6-universal/egg/setuptools/command/easy_install.py", line 619, in easy_install
A permission Denied message would suggest you to run your command as root as suggested by Hackaholic.
try sudo pip install YOUR_PACKAGE
You might also want to have a look at virtualenv to use a more isolated environment.
Under debian based distributions, you might install python-virtualenv package with apt-get install python-virtualenv.
Then create a virtual environment names whatever by typing virtualenv whatever (this will create a folder whatever inside your current folder.
Then cd to it and type bin/activate to enter this virtual environment.
From there try again your pip install command.
Might help
UPDATE :
You might try to use the suggested solutions available here
To sumup, try to add export ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future inside ~/.bash_profile
This question comes first in Google, but the second one actually worked:
pip install -U setuptools
pip install ez_setup

Categories