not loading python module

1,549 views
Skip to first unread message

Rajn

unread,
Jan 23, 2014, 3:30:00 PM1/23/14
to julia...@googlegroups.com
Hi
I followed suggestions and looked up help and searched for earlier similar problem. Found few and tried those out.
For example I set PYTHONPATH and PYTHONHOME variables (Python 2.7 is running because my path in windows was set to the bin for python).
Then I restarted Julia but I am getting same error.
I even changed PyCall.jl lines where few posts suggested issue with exec ":".
I changed back to
:

ENV["PYTHONHOME"]=exec_prefix

by commenting the rest out (i.e., @windows? exec_prefix...etc)

But even this did not work.

I have windows 7-64 bit and downloaded latest Julia binary v0.2.0.

The error messages are:
could not load module python: The specified module could not be found

in pyinitialize at ..\src\PyCall.jl:413
in pyinitialize at ..\src\PyCall.jl:418
warning: backtraces on your platform are often misleading.

at ..\PyPlot.jl:32

I will appreciate some help here. And also I have only one python installation which is the Enthought edition.
Also a related question, if I change something in *.jl such as what I changed above, I read that I have do reverse git. I have no idea what that is.
Really I am quite fresh to this. So please can someone guide me here?

Thanks in advance.



Steven G. Johnson

unread,
Jan 23, 2014, 6:38:08 PM1/23/14
to julia...@googlegroups.com
On Thursday, January 23, 2014 3:30:00 PM UTC-5, Rajn wrote:
I will appreciate some help here. And also I have only one python installation which is the Enthought edition.
Also a related question, if I change something in *.jl such as what I changed above, I read that I have do reverse git. I have no idea what that is.
Really I am quite fresh to this. So please can someone guide me here?

PyCall doesn't work with Enthought Python:

    https://github.com/stevengj/PyCall.jl/issues/42

Last I checked, it was because their sysutils.distconfig is completely broken, and I hadn't found a clean workaround.  I recommend Anaconda Python if you want a prepackaged Python distro.

Rajn

unread,
Jan 24, 2014, 12:35:12 PM1/24/14
to julia...@googlegroups.com
Hi Thanks Steve,

This is how far I got after making the following changes:
changed PYTHONPATH to C:\Python27

and in PyCall.jl
ENV["PYTHONHOME"]=exec_prefix 

using PyCall gives me this error now


julia> using PyPlot
WARNING: No working GUI backend found for matplotlib.
ERROR: PyError (PyImport_ImportModule) <type 'exceptions.ImportError'>
ImportError('DLL load failed: The specified module could not be found.',)
  File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 23, in <module
>
    from matplotlib.figure import Figure, figaspect
  File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 16, in <module
>
    import artist
  File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 6, in <module>

    from transforms import Bbox, IdentityTransform, TransformedBbox, Transformed
Path
  File "C:\Python27\lib\site-packages\matplotlib\transforms.py", line 34, in <mo
dule>
    from matplotlib._path import affine_transform

at C:\Users\RGurjar\.julia\PyPlot\src\PyPlot.jl:94

Do you think I am a step closer or just take your suggestion and move on to Anaconda. Do I have to uninstall Enthought edition?

Jake Bolewski

unread,
Jan 24, 2014, 12:51:35 PM1/24/14
to julia...@googlegroups.com
Are you able to import any of the following from python?

from matplotlib.backends import backend_wxagg
from matplotlib.backends import backend_gtkagg
from matplotlib.backends import backend_qtagg

-Jake

Rajan Gurjar

unread,
Jan 24, 2014, 3:16:52 PM1/24/14
to julia...@googlegroups.com
Yes Jake, I was able to import only the first i.e., wxagg backend. The other two did not because it says I have to install pygtk and pyqt.

Here's the message:
>>> from matplotlib.backends import backend_wxagg
>>> from matplotlib.backends import backend_gtkagg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_gtkagg.py", line 10, in <module>
    from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_gtk.py", line 11, in <module>
    raise ImportError("Gtk* backend requires pygtk to be installed.")
ImportError: Gtk* backend requires pygtk to be installed.
>>> from matplotlib.backends import backend_qtagg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_qtagg.py", line 12, in <module>
    from backend_qt import qt, FigureManagerQT, FigureCanvasQT,\
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_qt.py", line 21, in <module>
    raise ImportError("Qt backend requires pyqt to be installed.")
ImportError: Qt backend requires pyqt to be installed.



Also I must mention one fact. When I tried ipython --pylab in my first python install, the DOS shell would not recognize ipython as a command. I was then asked to place the ipython batch file in the Scripts folder in the main Python2.7 directory.
And then I was asked to set the environment variable for that directory.
I am now able to run ipython --pylab from dos shell. Therefore, as a test I made a copy of ipython bat file and placed it in the main Python2.7 folder which also has python executable and erased the environment variable linking to the script file and then ran Julia. But error messages are the same i.e., Julia still gives the same error as in my post.

Thank you for looking into this.

Steven G. Johnson

unread,
Jan 24, 2014, 3:19:51 PM1/24/14
to julia...@googlegroups.com


On Friday, January 24, 2014 3:16:52 PM UTC-5, Rajn wrote:
Yes Jake, I was able to import only the first i.e., wxagg backend.

Does

using PyCall
pygui(:wx)
using PyPlot

work?  (i.e. forcing it to use the wxagg backend?)

Rajan Gurjar

unread,
Jan 24, 2014, 3:25:05 PM1/24/14
to julia...@googlegroups.com
No, pygui(:wx) gives

julia> pygui(:wx)
ERROR: Python GUI toolkit for wx is not installed.

and I again verified running pyplot from ipython i.e., ipython --pylab; plot(range(1,5),range(1,5));
and the plot window shows up.
Also looked at the matplotlibrc file and the backend is selected to be WxAgg.

Rajan Gurjar

unread,
Jan 24, 2014, 3:27:55 PM1/24/14
to julia...@googlegroups.com
I also forgot to mention that if I make the environment variable "C:\Python27;" Julia does not even recognize python module.
But if I change the Env variable to "C:\Python27" i.e., without semicolon everything is good. This is strange.

Rajan Gurjar

unread,
Jan 24, 2014, 3:32:40 PM1/24/14
to julia...@googlegroups.com
"But if I change the Env variable to "C:\Python27" i.e., without semicolon everything is good. This is strange."

What I mean is that python module is being recognized now but I still get the matplotlib issue...

Steven G. Johnson

unread,
Jan 24, 2014, 3:41:11 PM1/24/14
to julia...@googlegroups.com


On Friday, January 24, 2014 12:35:12 PM UTC-5, Rajn wrote:
This is how far I got after making the following changes:
changed PYTHONPATH to C:\Python27

and in PyCall.jl
ENV["PYTHONHOME"]=exec_prefix 


I'm confused, what did you set PYTHONHOME to?

Rajan Gurjar

unread,
Jan 24, 2014, 3:56:33 PM1/24/14
to julia...@googlegroups.com
in the windows environment variable I set it to: C:\Python27
by going to the Computer properties and setting the environment variable there.

in Julia's Pycall.jl , I have
ENV["PYTHONHOME"]=exec_prefix

Rajan Gurjar

unread,
Jan 24, 2014, 3:59:38 PM1/24/14
to julia...@googlegroups.com
Sorry Steve,
There is no PYTHONPATH in the Windows environment variable. I have not set that variable. I miswrote earlier.
There is only PYTHONHOME which is set to C:\Python27
i.e., I go to Computer->Properties->environment variable and then
PYTHONHOME=C:\Python27


Rajan Gurjar

unread,
Jan 24, 2014, 4:24:32 PM1/24/14
to julia...@googlegroups.com
So I see two issues, first is not recognizing the backend and the second is not able to find affine_transform.py.

I looked around in Python27 and cannot find either i.e., matplotlib._path nor affine_transform.py

Wonder why?

Rajan Gurjar

unread,
Jan 24, 2014, 4:47:21 PM1/24/14
to julia...@googlegroups.com
I updated matplotlib.
When I run in Julia

using PyPlot

it now gives only one error: no working GUI backend found for matplotlib.

However, the window soon crashes with this error:

Runtime error in C\julia-05c6461b55\bin\julia-readline.exe
R6034
An application has made an attempt to load C runtime library incorrectly.

Rajan Gurjar

unread,
Jan 24, 2014, 5:20:23 PM1/24/14
to julia...@googlegroups.com

I still could not find matplotlib._path or affine_transform after updating matplotlib.
It seems it is in _pyd if installed correctly.

To check I did the following in python
import matplotlib._path
dir(matplotlib._path)

and it shows affine_transform

but then I am not sure what this new window crash from julia-readline is due to...

Rajan Gurjar

unread,
Jan 24, 2014, 5:24:31 PM1/24/14
to julia...@googlegroups.com
Any relation to the issue on this link because dll load failed previously and now it could be something similar?
http://bugs.python.org/issue3308
"Basically MinGW erroneously ships a .lib saying localtime is in
MSVCR90.DLL when it isn't.  That means there is no link failure but the
pyd will fail to load without information as to why.  Fixing the .lib
means that localtime is picked up from MSVCRT.DLL (ie no version in
name) and everything appears to work well.

The MinGW project also claims they only support MSVCRT.DLL and not any
of the numbered ones, so basically it is luck they work.  Noone pointed
out any compile time directives to direct versioning of MSVCRT.

I guess this is more fuel for the semi-regular flame war about free
software and free compilers on Windows"

Steven G. Johnson

unread,
Jan 24, 2014, 5:36:24 PM1/24/14
to julia...@googlegroups.com
On Friday, January 24, 2014 3:59:38 PM UTC-5, Rajn wrote:
Sorry Steve,
There is no PYTHONPATH in the Windows environment variable. I have not set that variable. I miswrote earlier.
There is only PYTHONHOME which is set to C:\Python27

You might try setting your PYTHONPATH variable, so that libpython can use it to find the Python modules it is missing.

Jake Bolewski

unread,
Jan 24, 2014, 7:16:41 PM1/24/14
to julia...@googlegroups.com
Honestly after fighting with Python on Windows for many years, your best course of action is probably to uninstall everything and try again from scratch.  I would back Steven's suggestion to install Anaconda if you are able.  It sounds like more work but in the end it is the only way to preserve your sanity.

Rajan Gurjar

unread,
Jan 24, 2014, 7:53:55 PM1/24/14
to julia...@googlegroups.com
Ok, looks like I may have to uninstall and try Anaconda.
I tried setting PYTHONPATH to C:\Python27\Lib -did not work and then to C:\Python27 but nothing changed.

Thanks folks. Will let you know if things work after fresh install

Rajn

unread,
Jan 24, 2014, 10:08:02 PM1/24/14
to julia...@googlegroups.com
Well actually I tried linux too. I have latest Xubuntu 13.0 version and Julia does not even install (worse than Windows) when I try its repositories suggested in the download webpage. Some issue with unmet dependencies with some math library.
I guess I will stick to Octave and python for now and come back to Julia next year when things are a bit better resolved.
I wish I had more time to play around but I am hard pressed for time.

Stefan Karpinski

unread,
Jan 25, 2014, 2:08:35 PM1/25/14
to Julia Users
Sorry you're having trouble with this. Windows is always a problem child but installing Julia on Linux should not present any major problems.

bp2012

unread,
Jan 25, 2014, 2:10:03 PM1/25/14
to julia...@googlegroups.com
Rajn,

If I could make a recommendation, perhaps you might find more success with ubuntu 12.04 on a virtual machine on your windows machine. I have step by step instructions here:

Then to get matplotlib working these steps should do the trick:
sudo apt-get build-dep python-numpy python-scipy
 sudo apt-get install python-pip
 sudo pip install -U numpy
 sudo pip install -U scipy
 sudo apt-get install python-matplotlib

In julia:
 Pkg.add("PyPlot")
 Pkg.update()

I've been using this setup for a while and have found it to work great.

Rajan Gurjar

unread,
Jan 25, 2014, 3:31:24 PM1/25/14
to julia...@googlegroups.com
Hi Stefan,
I having more trouble with Linux as you will see from my other post (concerning Linux issues) and that is because I have R installed - so some issues with RMath library. Instead why I tried to build it myself from the Git it gives a crash status. Found out some issues with Xubuntu.
That is latest. I will try out bert's suggestion next.
I still have to try uninstalling Enthought from Windows - replace it by Anaconda and then hopefully everything will be fine. That is a backup plan.

Rajan Gurjar

unread,
Jan 25, 2014, 3:33:53 PM1/25/14
to julia...@googlegroups.com
Hi Bert,
I also have a virtual Xubuntu. However, when I tried building Julia from Github it did not work. So I am guessing that even virtual Xubuntu will not work. However, I should try Virtual Ubuntu 12.04 as you suggested.
Thanks

Rajan Gurjar

unread,
Jan 27, 2014, 1:02:48 PM1/27/14
to julia...@googlegroups.com
After every install of pyplot (or any graphing app) failing in Windows and install of Julia failing in Linux - went back to Windows.

Uninstalled Enthought, removed Julia.

Got Anaconda, then installed Julia.

This is the error I get.

julia> using PyPlot
ERROR: could not load module python: The specified module could not be found.

 in pyinitialize at C:\Users\RGurjar\.julia\PyCall\src\PyCall.jl:422
 in pyinitialize at C:\Users\RGurjar\.julia\PyCall\src\PyCall.jl:417
WARNING: backtraces on your platform are often misleading or partially incorrect


Looks like back to square one? 
for information
PYTHONHOME is set to C:\Anaconda;C:\Anaconda\Scripts
PYTHONPATH is set to C:\Anaconda\Lib

Help please

Isaiah Norton

unread,
Jan 27, 2014, 1:07:55 PM1/27/14
to julia...@googlegroups.com
Please upload the following outputs in a gist (gist.github.com)

1. julia> versioninfo()
2. Pkg.build("PyCall")

3. all version info when you start python ("Python 2.7.5 | Anaconda...")
4. python>>> sys.path

Steven G. Johnson

unread,
Jan 27, 2014, 1:34:25 PM1/27/14
to julia...@googlegroups.com
Weird, Anaconda has always worked out of the box for me on Windows.  When you installed Anaconda, did you check the boxes "Add Anaconda to the System Path" and also "Register Anaconda as default Python version of the system" in the installer?



On Monday, January 27, 2014 1:02:48 PM UTC-5, Rajn wrote:
PYTHONHOME is set to C:\Anaconda;C:\Anaconda\Scripts
PYTHONPATH is set to C:\Anaconda\Lib

(Normally, I thought it was just PYTHONHOME=C:\Anaconda)


 

Rajn

unread,
Jan 27, 2014, 2:09:54 PM1/27/14
to julia...@googlegroups.com
Yes, I did both.
I tried just PYTHONHOME=C:\Anaconda
did not work.

Can you please advice me on the following please?
1. that while installing pyplot, the PYTHONHOME variable should already be set?
2. is there any way to print out variables from PyCall.jl? If I can print the variable 'lib' to what it is printing? According to the error displayed it occurs when it looks for the library directory.
I tried to force it to "python27.dll" but I am always getting the same error no matter what.
3. what should I try in pyinitialize("?") - should it be python27? Tried it but did not work.

Thanks

My dist_utils show the following:
{'EXE': '.exe', 'exec_prefix': 'C:\\Anaconda', 'LIBDEST': 'C:\\Anaconda\\Lib', 'prefix': 'C:\\Anaconda', 'VERSION': '27', 'SO': '.pyd', 'BINLIBDEST': 'C:\\Anaconda\\Lib', 'INCLUDEPY': 'C:\\Anaconda\\include', 'BINDIR': 'C:\\Anaconda'}
>>> python-config --ldflags

Steven G. Johnson

unread,
Jan 27, 2014, 2:28:45 PM1/27/14
to julia...@googlegroups.com
I installed on a fresh machine with Anaconda, and I didn't have to set any environment variables at all ... everything needed was done by the Anaconda installer.   My guess is that you have some leftover settings (environment vars? registry?) from your earlier attempts with Enthought or whatever and it is screwing things up.


On Monday, January 27, 2014 2:09:54 PM UTC-5, Rajn wrote:
Yes, I did both.
I tried just PYTHONHOME=C:\Anaconda
did not work.

Can you please advice me on the following please?
1. that while installing pyplot, the PYTHONHOME variable should already be set?
2. is there any way to print out variables from PyCall.jl? If I can print the variable 'lib' to what it is printing? According to the error displayed it occurs when it looks for the library directory.
I tried to force it to "python27.dll" but I am always getting the same error no matter what.
3. what should I try in pyinitialize("?") - should it be python27? Tried it but did not work.

Try pyinitialize("C:\Anaconda\python"), or whatever the name of your executable is; you could also try giving it the DLL location directly, i.e. pyinitialize("C:\Anaconda\python27.dll")

Rajn

unread,
Jan 27, 2014, 2:28:51 PM1/27/14
to julia...@googlegroups.com
Hi,
I just populated the outputs to gist through your link.
Not sure if I should save it or if I have to sign in? The file was named as Rajn_notloadingpython

Thanks

Rajn

unread,
Jan 27, 2014, 3:28:58 PM1/27/14
to julia...@googlegroups.com
This worked finally!
I did pyinitialize("C:\Anaconda\python") as suggested by Steve.
I am now able to use PyPlot.
So the question remains...what is broken in PyCall?
What is the solution
Thanks

Rajan Gurjar

unread,
Jan 27, 2014, 3:57:50 PM1/27/14
to julia...@googlegroups.com
Ok, I got it now to run it without using PyCall and pyinitialize.

I just changed PyCall line where ENV variable is set i.e.,

changed from [ENV] = @windows exec_prefix: preconfigvar(...,"prefix") etc 
to
[ENV] = exec_prefix



Thanks for all the help I got from the forum. I can now work Julia on Windows.

Linux (my preferred OS) has its bigger share of trouble for me though as you will notice from my second post.

Steven G. Johnson

unread,
Jan 27, 2014, 5:14:04 PM1/27/14
to julia...@googlegroups.com


On Monday, January 27, 2014 3:57:50 PM UTC-5, Rajn wrote:
Ok, I got it now to run it without using PyCall and pyinitialize.

I just changed PyCall line where ENV variable is set i.e.,

changed from [ENV] = @windows exec_prefix: preconfigvar(...,"prefix") etc 
to
[ENV] = exec_prefix


Wait, what?  You changed

     ENV["PYTHONHOME"] = @windows? exec_prefix : pyconfigvar(python, "prefix") * ":" * exec_prefix

to

     ENV["PYTHONHOME"] = exec_prefix

?? But on Windows (where @windows is true), those two lines should be exactly equivalent!  Did I misunderstand you?

--SGJ

PS. I just tried a fresh Windows 8.1 x64 machine.  Installed Anaconda (64-bit), installed Julia 0.2 (64-bit), ran Pkg.add("PyPlot"); Pkg.add("IJulia") in julia, and then ran "ipython notebook --profile julia" at the Windows command prompt.   Everything seems to work fine, no patches required.

Rajan Gurjar

unread,
Jan 27, 2014, 6:02:54 PM1/27/14
to julia...@googlegroups.com
Yes, this is exactly what I did and the whole thing ran and now I am chugging along.
The very last step just before that was resetting the PYTHONHOME to C:\Anaconda from earlier setting of C:\Anaconda;C:\Anaconda\Scripts. And it did not work.
Then you suggested the change to PYTHONHOME should have only one file reference. I changed and PyPlot still did not run.
The next step was as again what you suggested pyinitialize("C:\\Anaconda\\python") and this ran.
Now unless this set up everything - that is a different story.
I closed Julia window, opened the pycall.jl file and made the change that I wrote above about which you expressed surprise.
And then restarted Julia and without using PyCall went ahead with using PyPlot. Everything went fine.
If you want I can undo my change to pycall.jl and let you know?

Rajan Gurjar

unread,
Jan 27, 2014, 6:12:33 PM1/27/14
to julia...@googlegroups.com
Actually I have been playing around so much that the sequence of events is difficult to remember. I do remember that I also deleted PYTHONPATH which was set to C:\\Anaconda\\Lib
However, I do agree with Steve and that is the code that I changed to is similar to previous code. The reason why I made that change? It happened by mistake - I was trying to print out the output of lib by issuing a print(lib) command and it wasn't working. I kept getting "python module not found". I tried to force the pycall.jl code to the executable file and that is when I must have changed the code. But it does not make sense. So let me test it again.


Rajan Gurjar

unread,
Jan 27, 2014, 6:24:00 PM1/27/14
to julia...@googlegroups.com
Ok, I have verified by going back to 
ENV["PYTHONHOME"] = @windows? exec_prefix : pyconfigvar(python, "prefix") * ":" * exec_prefix

and PyPlot executes properly.
Sorry to mislead you all.
It must have been some wrong combination of PYTHONHOME and PYTHONPATH setting that threw me off. Also I learnt to make one change at a time and test. Otherwise it leads to false conclusions.


Reply all
Reply to author
Forward
0 new messages