Author Topic: "Failed to import pyxll [No module named threading]"  (Read 5631 times)

totallyunimodular

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
"Failed to import pyxll [No module named threading]"
« on: February 28, 2011, 04:52:53 PM »
I am looking for a Python alternative to RExcel and am hoping pyxll is the ticket. Unfortunately I am running into an error after following the installation instructions and assume it is something simple in cause.

I am on 32-bit Windows XP running Python 2.6.5. I have installed pyxll from the pyxll.py26.1.1.1 zip file and added the pyxll.xll Add-In to Excel 2007. Upon doing this, and every time I start Excel, I get a PyXLL pop up error about

"Failed to import pyxll [No module named threading]"

I have confirmed that the root level Python directory is in my path, as is the DLLs subdirectory.

Can anyone offer any advice on what to look for?

Thanks,

Josh

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 599
  • Karma: +14/-1
    • View Profile
Re: "Failed to import pyxll [No module named threading]"
« Reply #1 on: February 28, 2011, 05:21:52 PM »
Hi Josh,

It sounds like either you don't have the threading module in your python install, or there's a problem with your python path.

Can you check if importing the threading module works in a normal python prompt? If not, that's the problem. You should rebuild python with threading enabled if you're building it from source.

It could just be a problem with your python path. Check where the threading module is located and then make sure that is included in your python path, either in the registry or with the PYTHONPATH environment variable. This should be set correctly when you install python, so maybe just reinstalling it would fix it.

Please let me know if this fixes your problem or if you are still having issues.


Regards,
Tony


totallyunimodular

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: "Failed to import pyxll [No module named threading]"
« Reply #2 on: February 28, 2011, 05:50:57 PM »
Thanks for the quick reply Tony.

The threading module does exist in my Python\Lib directory, and I can import it

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]: import threading

In [2]: dir(threading)
Out[2]:
['BoundedSemaphore',
 'Condition',
 'Event',
 'Lock',
 'RLock',
...

I added Python\Lib to my PATH, as well as adding it to the pythonpath variable in the pyxll.cfg file. But, I still kept getting the "No module named threading" error.

So, I went back to Excel and added pyxll.xll back in, which caused Excel to "replace" the previous attempt. And now when I open examples.xls  I get a new import error

Failed to import pyxll  ['module' object has no attribute '_init']

I can import pyxll just fine from my ipython shell though:

In [11]: import pyxll
In [12]: test = pyxll.AsyncFunctionThread(name="PyXLL AsyncFunctionThread")
In [13]: type(test)
Out[13]: <class 'pyxll.AsyncFunctionThread'>

So, this must be a path issue but it is not clear what else to try here besides adding more and more stuff to my PATH and PYTHONPATH, which has not worked so far.

Any advice is greatly appreciated!

Josh


 

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 599
  • Karma: +14/-1
    • View Profile
Re: "Failed to import pyxll [No module named threading]"
« Reply #3 on: February 28, 2011, 06:27:48 PM »
Hi Josh,

You have to restart excel after changing the python path. Unloading and reloading the addin isn't enough unfortunately. This is because the python interpreter isn't shut down until excel closes.

Regards,
Tony

totallyunimodular

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: "Failed to import pyxll [No module named threading]"
« Reply #4 on: February 28, 2011, 07:16:03 PM »
Sorry for not being more clear, but I have been restarting Excel.

One thing I noticed is that I cannot find a log file. I used the default settings in pyxll.cfg  but then set an explicit path when I did not see any log file in pyxll folder. The current cfg contents are

[PYXLL]
pythonpath = ./examples; C:/Program Files/VNI/PyIMSL_Studio_1.6/Python26/Lib
modules = worksheetfuncs, menus, automation, hello
developer_mode = 1

[LOG]
verbosity = info
format = %(asctime)s - %(levelname)s : %(message)s
path = C:/Documents and Settings/jhemann/My Code/Python/pyxll.py26.1.1.1/logs
file = pyxll.log

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 599
  • Karma: +14/-1
    • View Profile
Re: "Failed to import pyxll [No module named threading]"
« Reply #5 on: February 28, 2011, 07:24:53 PM »
Ah ok. The logging is set up in pyxll._init, but it's not getting that far which will be why you're not getting anything in the log.

Could you try taking pyxll out of your python path please? Pyxll has the real one statically linked in, but I'm wondering if it's picking up the external version instead, which would explain why the init function is missing.

Thanks,
Tony

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 599
  • Karma: +14/-1
    • View Profile
Re: "Failed to import pyxll [No module named threading]"
« Reply #6 on: February 28, 2011, 08:57:45 PM »
Hi Josh,

I've just re-read your earlier reply more carefully.

When I said to make sure the python modules (threading etc) were on your python path, I meant make sure they are set in the registry (//HKEY_LOCAL_MACHINE/Software/Python/PythonCore/2.6/PythonPath) or as the environment variable PYTHONPATH.

Setting it in the PyXLL config won't help as the config file is read after PyXLL has done some preliminary setup, which involves importing some modules from the standard library. It's assumed these will be available as the Python installer should already have done this all for you.

I was wrong about PyXLL possibly loading your local pyxll module. That can't happen. I think the error about the missing _init was because PyXLL had already failed to load once and had put an incomplete pyxll in sys.modules, so when it was loaded again when you re-added the addin the empty failed module was still there and of course has no _init method.

Please can you try setting your python path as an environment variable or registry entry and see if that helps. Also, please could you let me know what Python distribution you're using so I can look at improving this for other users? For the windows installers from www.python.org and for various other distributions it should work straight out of the box.

thanks,
Tony



« Last Edit: February 28, 2011, 09:11:50 PM by Tony »

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 599
  • Karma: +14/-1
    • View Profile
Re: "Failed to import pyxll [No module named threading]"
« Reply #7 on: February 28, 2011, 09:09:48 PM »
I see from your path you're using the RougeWave python distribution. I've contacted them to see if they'll allow me an evaluation license so I can see why this hasn't worked as smoothly as it should have for you.

thanks,
Tony.

totallyunimodular

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: "Failed to import pyxll [No module named threading]"
« Reply #8 on: February 28, 2011, 09:25:14 PM »
OK, working now! I needed to add the Python Lib directory to PYTHONPATH. I actually have Python 2.6.5 and 2.7 installed and try to keep my environment as clean as possible, calling batch files to setup up whether I want to use one version or the other. So, I try to avoid setting PYTHONPATH via the Windows System Settings as much as possible and just set it for the session I am starting.

Thanks for the help, and I'll certainly post again if there are other issues. I am excited to start playing now...

On a side a note, PyIMSL Studio is free to use for non-commercial use. I think you can get a 3-month commercial evaluation.