Author Topic: pyxll doesnt recognize module installed through pip  (Read 741 times)

bondtower

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
pyxll doesnt recognize module installed through pip
« on: September 01, 2015, 11:10:42 AM »
hi, I have noticed that pyxll doesn't recognize modules that are subsequently installed through pip in Anaconda. E.g. if I install a module called py_expression_eval by pip install py_expression_eval, and then I try to import it in a module referenced by pyxll by writing the following line of code: from py_expression_eval import Parser, I get the error:
2015-09-01 10:59:52,371 - ERROR :     from py_expression_eval import Parser
2015-09-01 10:59:52,371 - ERROR : ImportError: No module named py_expression_eval
Is there a workaround for this?
Thanks.

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Karma: +13/-1
    • View Profile
Re: pyxll doesnt recognize module installed through pip
« Reply #1 on: September 01, 2015, 11:46:36 AM »
Hi,

are you installing into a virtualenv? If you are then it's not enough to simply add the site-packages folder from that virtualenv to your pythonpath as site.py needs to know about it so that it can add all packages from the .pth files to the path.

You can create a file called "pyxll-startup.py" and put it in the same folder as pyxll.xll to execute some Python code before any other initialization. This gives you a chance to set the python path to your virtualenv, for example you could do something like this:

Code: [Select]
# Setup the Python path.
import site
sitepackages = os.path.join("**my virtual env**", "site-packages")
site.addsitedir(sitepackages)

You can get detailed logging information for the PyXLL initialization by setting the environment variable "PYXLL_DEBUG_LOG=mylogfile.txt" before starting Excel.

Best regards,
Tony



bondtower

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: pyxll doesnt recognize module installed through pip
« Reply #2 on: September 01, 2015, 12:52:34 PM »
hi Tony, Im not installing into a virtual environment. Let me try your recipe though. I tried creating a pyxll-startup.py file in same directory as pyxll.xll, with the following code
Quote
import sys
sys.path.extend(['C:/Anaconda/Lib/site-packages/py_expression_eval', 'C:/Anaconda/Lib/site-packages/'])
but doesn't really work.

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Karma: +13/-1
    • View Profile
Re: pyxll doesnt recognize module installed through pip
« Reply #3 on: September 01, 2015, 01:24:33 PM »
If you're not using a virtualenv then as long as the package is installed correctly it should work fine.

Check the python path in the debug log.

If you are adding the explicit path (py_expression_eval) to the path directly then (assuming py_expression_eval.py or py_expression_eval/__init__.py file is in that folder) then it should be able to import it. Perhaps there is some dependency that can't be found that's causing the import error. Checking the log file should tell you what's going wrong.

Best regards,
Tony