Solved

pylab initialization failed

Posted on 2014-02-22
29
869 Views
Last Modified: 2014-05-08
Hello Experts!

I am getting a maddening error on a Python 3.3.4 installation with Numpy version 1.8.0.  This was installed on a Centos 6 system, so I used the instructions from http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/ to install Python and pip to install Numpy.  I've done a lot of Googling trying to find out how others have resolved this issue, and yes I do see postings about this issue, but can't find any adequate responses.  I see some responses to issues very similar (but different) from this one, so I wanted to see if the experts here can out do the rest of the Internet world.

The issue occurs when I try and run ipython3 in a virtualenv and load pylab.  Here is the output of the command:
(my33project) [root@server Python-3.3.4]# ipython3 --pylab
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
Python 3.3.4 (default, Feb 22 2014, 23:28:52)
Type "copyright", "credits" or "license" for more information.

IPython 1.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
[TerminalIPythonApp] WARNING | GUI event loop or pylab initialization failed
---------------------------------------------------------------------------
TclError                                  Traceback (most recent call last)
/usr/local/lib/python3.3/site-packages/IPython/core/shellapp.py in <lambda>(key)
    221         shell = self.shell
    222         if self.pylab:
--> 223             enable = lambda key: shell.enable_pylab(key, import_all=self.pylab_import_all)
    224             key = self.pylab
    225         elif self.matplotlib:

/usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py in enable_pylab(self, gui, import_all, welcome_message)
   2918         from IPython.core.pylabtools import import_pylab
   2919
-> 2920         gui, backend = self.enable_matplotlib(gui)
   2921
   2922         # We want to prevent the loading of pylab to pollute the user's

/usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   2884         # Now we must activate the gui pylab wants to use, and fix %run to take
   2885         # plot updates into account
-> 2886         self.enable_gui(gui)
   2887         self.magics_manager.registry['ExecutionMagics'].default_runner = \
   2888             pt.mpl_runner(self.safe_execfile)

/usr/local/lib/python3.3/site-packages/IPython/terminal/interactiveshell.py in enable_gui(gui, app)
    306         from IPython.lib.inputhook import enable_gui as real_enable_gui
    307         try:
--> 308             return real_enable_gui(gui, app)
    309         except ValueError as e:
    310             raise UsageError("%s" % e)

/usr/local/lib/python3.3/site-packages/IPython/lib/inputhook.py in enable_gui(gui, app)
    526         e = "Invalid GUI request %r, valid ones are:%s" % (gui, list(guis.keys()))
    527         raise ValueError(e)
--> 528     return gui_hook(app)
    529

/usr/local/lib/python3.3/site-packages/IPython/lib/inputhook.py in enable_tk(self, app)
    322         if app is None:
    323             import tkinter
--> 324             app = tkinter.Tk()
    325             app.withdraw()
    326             self._apps[GUI_TK] = app

/usr/local/lib/python3.3/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use)
   1798                 baseName = baseName + ext
   1799         interactive = 0
-> 1800         self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
   1801         if useTk:
   1802             self._loadtk()

TclError: no display name and no $DISPLAY environment variable

Open in new window

0
Comment
Question by:OmniUnlimited
  • 15
  • 12
29 Comments
 
LVL 61

Accepted Solution

by:
gheist earned 500 total points
Comment Utility
Have you tried and failed with:
Python 2.6 from the system
Python 2.7 from scientificlinux
Whichever Pypy from EPEL?

It clearly says it will not work well with virtualenv.
0
 
LVL 17

Author Comment

by:OmniUnlimited
Comment Utility
Hi gheist, thank you for your response.

Are your suggestions that I try an earlier version of Python because you know this won't work with Python 3.3.4?

When working with separate projects on anything above Python 2.7, it is recommend that we use virtualenv.  Are you telling me that one of the most useful Python utilities won't work under these environments?
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
Warning on first line of your post says so.
You can install from EPEL (aka Fedora) ready packages
https://fedoraproject.org/wiki/EPEL
Get EL6 signing key and epel-release RPM
rpm --import the key

yum install the rpm

yum clean all
yum install ipython numpy scipy ....

:::
$ ipython
Python 2.6.6 (r266:84292, Jan 22 2014, 09:37:14)
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]:
Do you really want to exit ([y]/n)? y
$ cat /etc/redhat-release
CentOS release 6.5 (Final)
0
 
LVL 17

Author Comment

by:OmniUnlimited
Comment Utility
Python 2.6.6 is native to the system I currently am running, however some of the functions I need to run are only available on later Numpy versions and require newer versions of Python.  So to your knowledge this would not be possible on the system I am running?
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
You may want to try to build numpy from fedora 19-20 souce RPM?
basically:
yum install rpmdevtools
useradd rpmnothing
su - rpmnothing
rpmdev-setuptree
cd rpmbuild
now rpm2cpio whatever.srpm | pax -rv
copy spec to SPECS, sources to sources
rpmbuild -ba SPECS/numpy.spec
now install those RPMs

if it asks for more dependencies - remove respective system package and build and install dependency rpm (some system rpms are best left untouched, so it reaches dead end if you cannot uninstall one system rpm)
you now some desktop virtualisation product like vmware player or virtuapc etc.... maybe that can produce good enough RPMs while keeping target system intact.
0
 
LVL 17

Author Comment

by:OmniUnlimited
Comment Utility
Ok, it is obvious you know tons more about this stuff than I do.  I'm afraid you are going to have to go a little slower.

I executed the following statements verbatim:

yum install rpmdevtools
useradd rpmnothing
su - rpmnothing
rpmdev-setuptree
cd rpmbuild

Obviously, when I tried to execute the next statement you listed verbatim, it gave me the following errors:

-bash: pax: command not found
-bash: now: command not found

Please do not assume I know anything about this.  I need to be told exactly what to do, step by step.

Thank you.
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
so install it
it is historical universal extractor fro all tar and cpio file (aka portable archive exchange)

now is indication of time:)

command is:
rpm2cpio xxx.fc21.src.rpm| pax -rv
0
 
LVL 17

Author Comment

by:OmniUnlimited
Comment Utility
Hi gheist:

Thanks for your input, however I am unable to locate an xxx.fc21.src.rpm file.  When I try and run your command verbatim, I get the following error:
[root@server [rpmnothing@server ~]$ rpm2cpio xxx.fc21.src.rpm | pax -rv
-bash: pax: command not found
rpm2cpio: xxx.fc21.src.rpm: No such file or directory

Open in new window

0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
mmm ammm zzzz you know how to download files online? fedora SRPMS directories are a good start (you mentioned numpy needs upgrade, so in whatever SRPMS or Sources dirrectory there should be a file *numpy*.src.rpm, so download it, expand and build for el6.
0
 
LVL 17

Author Comment

by:OmniUnlimited
Comment Utility
Ok, getting closer.  I was able to Google "fedora SRPMS" and found their directories and downloaded numpy-1.8.0-4.fc21.src.rpm to the server, but now I get the following error:
[rpmnothing@server rpmbuild]$ rpm2cpio numpy-1.8.0-4.fc21.src.rpm | pax -rv
-bash: pax: command not found

Open in new window

I tried looking for a pax download, but I am really not sure what I am looking for, nor how to install it.
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
"yum install pax" ;)
0
 
LVL 17

Author Comment

by:OmniUnlimited
Comment Utility
Awesome.  That worked!  Thanks.

Here are the results from what I've done:
[rpmnothing@server rpmbuild]$ rpm2cpio numpy-1.8.0-4.fc21.src.rpm | pax -rv
numpy-1.8.0.tar.gz
numpy-insecure-mktemp-use.patch
numpy.spec
pax: sv4cpio vol 1, 3 files, 3806796 bytes read, 0 bytes written.
[rpmnothing@server rpmbuild]$ ls
BUILD                       numpy-insecure-mktemp-use.patch  SOURCES
numpy-1.8.0-4.fc21.src.rpm  numpy.spec                       SPECS
numpy-1.8.0.tar.gz          RPMS                             SRPMS
[rpmnothing@server rpmbuild]$ cp numpy.spec SPECS

Open in new window


For your next set of instructions:
copy spec to SPECS, sources to sources
rpmbuild -ba SPECS/numpy.spec
now install those RPMs

Open in new window


I suspected you meant copy the numpy.spec file to the SPECS folder, which I did.  However which file contains the sources?  Is it the numpy-1.8.0.tar.gz file, or is it the numpy-1.8.0-4.fc21.src.rpm file?  And do I copy that to the SOURCES directory?  Once that is done, how do I install the RPM's?
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
once you run rpmbuild -ba SPECS/numpy.spec it immediately complains about what is missing.... (normally it is all files extracted expect .spec
i.e .tar.gz and patch if i follow your output.
Durinng build it will package new source rpm too.
0
 
LVL 17

Author Comment

by:OmniUnlimited
Comment Utility
Ok, well that was a haltering way of finding out what was missing, but it worked.  Here is what I've done so far:
[rpmnothing@server rpmbuild]$ rpmbuild -ba SPECS/numpy.spec
error: File /home/rpmnothing/rpmbuild/SOURCES/numpy-1.8.0.tar.gz: No such file or directory
[rpmnothing@server rpmbuild]$ cp numpy-1.8.0.tar.gz SOURCES
[rpmnothing@server rpmbuild]$ rpmbuild -ba SPECS/numpy.spec
error: Bad source: /home/rpmnothing/rpmbuild/SOURCES/numpy-insecure-mktemp-use.patch: No such file or directory
[rpmnothing@server rpmbuild]$ ls
BUILD                       numpy-1.8.0.tar.gz               RPMS     SRPMS
BUILDROOT                   numpy-insecure-mktemp-use.patch  SOURCES
numpy-1.8.0-4.fc21.src.rpm  numpy.spec                       SPECS
[rpmnothing@server rpmbuild]$ cp numpy-insecure-mktemp-use.patch SOURCES
[rpmnothing@server rpmbuild]$ rpmbuild -ba SPECS/numpy.spec
error: Failed build dependencies:
        lapack-devel is needed by numpy-1:1.8.0-4.el6.x86_64
        python-setuptools is needed by numpy-1:1.8.0-4.el6.x86_64
        atlas-devel is needed by numpy-1:1.8.0-4.el6.x86_64
        python-nose is needed by numpy-1:1.8.0-4.el6.x86_64
        Cython is needed by numpy-1:1.8.0-4.el6.x86_64
[rpmnothing@server rpmbuild]$

Open in new window


Now, what I don't understand is that I have already installed these dependencies, but I installed them in the Python-3.3.4 which is only accessible through the virtualenv.  It seems to me that this RPM build is affecting the Python 2.6 version which is native to the server.  If this is the case, we need to stop, because I do not want to make any changes to the native version.

How can I do this so that only the Python-3.3.4 installation is affected?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 61

Expert Comment

by:gheist
Comment Utility
You can add modules to native version (nobody but you will call them, no binaries are modified to breka yum rhn etc)
yum will not see the difference.
sorry your Python 3.3.4 is broken, i am trying to make you use system python.
If system python is not enough scientificlinux at el6 level has 2.7.
Still not there? - use fedora or ubuntu really...

you will upgrade NUMPY only over EPEL version (you can uninstall --nodeps it and reinstall EPEL whnever you want)
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
I made this:
-rw-rw-r--. 1 rpms rpms 5403760 Feb 26 20:42 RPMS/i386/numpy-1.8.0-4.el6.i386.rpm
-rw-rw-r--. 1 rpms rpms  294011 Feb 26 20:42 RPMS/i386/numpy-f2py-1.8.0-4.el6.i386.rpm

rpm -e --nodeps numpy
rpm -ivv $(the first file)
0
 
LVL 17

Author Comment

by:OmniUnlimited
Comment Utility
gheist, I explained earlier that I needed a newer version of Python to run with pylab.  I do not appreciate your trying to get pylab to work on the native version as that does not resolve the problems I am having and is essentially a waste of both of our valuable times.

You seem to be saying that there is no way to get pylab to work with 3.3.4, is this correct?  You think I won't have this issue if I install 2.7?
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
There is no way  ipython works in virtualenv (read again first line of warning), no matter python/system version.

Do you get any errors from system python with freshly built numpy and epel ipython ? - is your script working?
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
PS that is the pain of enterprise linux, that it has long-term support for packages, and now 4 years from  release RHEL6 looks like scrapyard for fresh installation.
PPS pypy in EPEL is 2.7, but you will need to build numpy and ipython using it just like in your virtualenv...
0
 
LVL 17

Author Comment

by:OmniUnlimited
Comment Utility
Ok, maybe you are interpreting this differently than I am.  The warning says this:
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.

Open in new window


I interpret this that there may be problems when working inside a virtualenv, and that an apparent resolution would be found if iPython were installed within the virtualenv.  In Python-3.3.4, I found this was not to be the case as problems continued even after iPython was installed within the virtualenv.

I have never interpreted the warning to mean that it is impossible to execute iPython within a virtualenv, something which you seem to feel that it means.  And if it does mean that (they probably should reword the warning), then I am at a loss.

According to the link I provided in my question above, access to the alternate installations of Python occurs through the virtualenv.  I know (also from the same article) that I cannot upgrade the system Python without breaking things.  Do you know of an alternative method of installing two python installations such that you could execute each of the installations without virtualenv?
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
scientific linux package does not change system python/python2/python2.6, it just adds python2.7 in system, so you you have a choice of easy_install/pip as site-packages for that one(and have two pythons with completely different library sets).
it is really much cleaner to juggle around EPEL rpms (they have lots of science packages prebuilt)
Ubuntu may be a good choice:
Python 2.7 and Python 3.2 only in Ubuntu 12.04. With Precise Pangolin, we have dropped Python 2.6.
RHEL7 beta aka Fedora 19?
OpenSUSE?
0
 
LVL 17

Author Comment

by:OmniUnlimited
Comment Utility
I just talked to two other server experts around here.  They seem to feel it is an X11 Forwarding issue.  echo $DISPLAY displays nothing.  sshd_config has X11Forwarding yes, so I don't know what's going on.
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
install xauth (with yum)

enable X11 forwarding in your client and  keep X server (like Xming?) running while connected.
now re-connect and it will work as much as it needs X11
0
 
LVL 17

Author Comment

by:OmniUnlimited
Comment Utility
I went ahead and installed xauth and reconnected.  Sure enough, now I get "localhost:10.0" in response to "echo $DISPLAY".  I wasn't able to follow you with regards to the rest of the stuff you were saying, however.  I read where Xming is an X Window System Server, so I guess that would have to run on my computer.  Are you saying I should install and run Xming on my computer and somehow connect it to my remote server?
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
you should install Xming and run umm Xming (it keeps icon in tray), not Xlaunch or their putty or so)

with X11 forwarding on (like you see DISPLAY 10+)  you will gett all graphics output forwarded to local display via SSH session subchannel.
0
 
LVL 17

Author Comment

by:OmniUnlimited
Comment Utility
Ok, I installed Xming without their putty link program, and I accessed the server using putty with X11 Forwarding checked, but I am not familiar enough with X Window applications to know what to run.  Commands like xterm, etc. just give me -bash: xterm: command not found errors.  If I am not mistaken, Xming should open up a window on my computer when I run an X app on the server, is this not correct?
0
 
LVL 16

Expert Comment

by:Joseph Gan
Comment Utility
To quickly solve X11 forward issue, you could use vnc, which is a GUI enviroment, ie
# yum install vnc cnv-server
# chkconfig vncserver on

On your desktop, install "vncviewer.exe" if your desktop is Windows.

Google it how to configure your vncserver, very simple.

Using vncviewer log onto your vnc server, you will get a X11 enviroment. From there run your installation/configurastion.

Ensure your echo $DISPLAY has some output, not blank.
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
Probably your system is started at minimum installation
So you need to install xterm to run it, or xdpyinfo to get text infos about your display server (xming has opengl)
If you intend to keep ipython-gui running for long vnc (right above) is the way to go.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now