Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Tony

Pages: 1 ... 26 27 [28] 29 30 ... 41
406
General Discussion / Re: Portability of PyXLL
« on: February 12, 2014, 11:58:38 AM »
Hi,

this is not really the intended use-case for pyxll. The end user needs to have python installed and no code is ever embedded in the spreadsheet, it is all in external python modules and so the end user needs to have access to those modules as well (either deployed as eggs or your own distribution mechanism such as putting the code on a network drive).

This is by design as having code saved in spreadsheets causes more problems than it solves when it comes to releasing updates to that code. Spreadsheets that include VBA code and get sent around can result in inconsistent behavior as changes can be made in some copies of the sheet and not in others. Keeping the code separate from the sheet itself ensures that can never happen.

If you want your code embedded in the sheet you are better off sticking with VBA.

Best regards,
Tony

407
Help and Support / Re: pyxll cell with macro formulas
« on: February 01, 2014, 01:45:32 PM »
Hi,

just to let you know, those two new functions are in the latest release (2.1) as well as an additional property 'sheet_name' added to the XLCell class.

Best regards,
Tony

408
Help and Support / Re: Problem with empy cells and numpy_array<float>
« on: February 01, 2014, 01:43:57 PM »
Hi,

just to let you know, this has been changed in the latest release 2.1.0.

Best regards,
Tony

409
Hi,

if you can import the module from a normal python prompt take a look at where it's been imported from, eg

> import win32com
> print(win32com.__file__)
C:\VirtualEnvs\dev\lib\site-packages\pywin32-218-py3.2-win-amd64.egg\win32com\__init__.py

Now print out the python path when pyxll starts, eg in one of your modules add:

import sys
print ("\n".join(sys.path))

And then check that the location the module was previously found in is in your pythonpath.

Best regards,
Tony




410
Hi,

yes, you want the 'Run' method from the Excel application object. The automation example shows how to get the application object (see the function 'xl_app').

Details of the Run method are on msdn here:
http://msdn.microsoft.com/en-us/library/office/ff197132.aspx

cheers,
Tony

411
Help and Support / Re: Debugging with Eclipse and PyDev
« on: January 29, 2014, 04:28:30 PM »
I think it might have moved - try looking in the main pydev plugin folder (C:\Program Files\Brainwy\LiClipse 0.9.7\plugins\org.python.pydev_3.3.3.201401272005). Alternatively you could always try just searching for a file named 'pydevd.py' in your eclipse install.

regards,
Tony

412
Help and Support / Re: Debugging with Eclipse and PyDev
« on: January 28, 2014, 11:05:20 PM »
Hi,

you need to modify the example so that it can find pydevd.py, which is installed as part of the pydev eclipse plugin.

As the log says, look at H:\VBA_Python\pyxll\pkg2.7\examples\tools\eclipse_debug.py - in there near the top you'll find the following:

Code: [Select]
##
## UPDATE THIS TO MATCH WHERE YOU HAVE ECLIPSE AND PYDEV INSTALLED
##
## The following code tries to guess where Eclipse is installed
eclipse_roots = [r"C:\"Program Files*\Eclipse"]
if "USERPROFILE" in os.environ:
    eclipse_roots.append(os.path.join(os.environ["USERPROFILE"],
                                      ".eclipse",
                                      "org.eclipse.platform_*"))

for eclipse_root in eclipse_roots:
    pydev_src = os.path.join(eclipse_root, r"plugins\org.python.pydev.debug_*\pysrc")
    paths = glob.glob(pydev_src)
    if paths:
        paths.sort()
        _log.info("Adding PyDev path '%s' to sys.path" % paths[-1])
        sys.path.append(paths[-1])
        break

Change "eclipse_roots" to include wherever you've installed eclipse and then it should find the pysrc folder (which is where the pydevd.py file that is  imported should be) and add it to the path. If it still doesn't then you can always add the pysrc folder to the python path manually.

Best regards,
Tony

413
Help and Support / Re: Dealing with arrays
« on: January 24, 2014, 03:52:21 PM »
Hi,

try printing out what the range's Value actually is. You should see it's a list of lists - not a 1d list as you think it is. This makes sense as you are actually dealing with a 2d grid of data, even if you are only selecting a single row from it.

len(contracts) is 1 because it's a list of lists, of length 1 (1 row). Then length of (contracts[0]) is what you're looking for.

If you set Value to a list of lists it will do what you expect.

You should read this:
https://www.pyxll.com/docs/udfs.html#using-arrays

You can also use pyxll's get_type_converter function to convert from a numpy array to a list of lists, eg:

r.Value = pyxll.get_type_converter("numpy_array", "float[]")(my_numpy_array)

Best regards,
Tony



414
Hi,

have you got more than one version of python installed? Are you sure the one that you've installed pywin32 into is the version that pyxll is using?

If you are using 64 bit excel and python then those dlls need to be in C:\Windows\SysWOW64 instead of System32 (or elsewhere on your PATH). You also need to be sure they are the 64 bit dlls as that would be another reason for them not to load.

I just noticed that "Python33/DLLs" and "Python33/lib/site-pacakages/win32/lib" are missing from your python path. Have you set your python path up manually? You might want to try having the python installer set it up for you if you're not sure exactly what paths you should have added, as you may be missing some others too.

If that doesn't solve it I'd suggest un-installing all versions of python and re-installing only the one you want and trying again. If you have both 32 bit and 64 bit versions installed make sure that you install the one matching the version of pyxll and excel you have.

Best regards,
Tony

415
Hi,

those dlls need to be somewhere on your PATH, usually c:\Windows\System32. Wherever excel loads the pyxll addin from isn't automatically on the system path, and neither is the python path - it's the system path that windows uses when looking for dlls.

Best regards,
Tony

416
Help and Support / Re: Using Pyxll with Numba
« on: January 01, 2014, 03:53:43 PM »
Hi,

I'm not sure why calling a function from VBA should cause it to get recompiled... PyXLL takes a reference to the python function and simply calls it from the stub C function that's generated for it. You should make sure that the function you're decorating with @xl_func or @xl_macro is the compiled numba function - i.e. make sure the numba decorator is applied before the xl_func decorator, e.g.:

@xl_func(...)
@numba.autojit(...)
def func(...):

Alternatively you could try having another function that gets jitted and a wrapper function that calls it, e.g.:

@xl_func(...)
def func(...):
    return other_func(...)

@autojit
def other_func(...):
   ....

You could use the pyxll.on_reload callback to get notified when a reload occurs and recompile your functions then. As the callback's called after the reload happened you'll have to tell pyxll that the functions have changed (again!) by calling the pyxll_rebind macro (https://www.pyxll.com/docs/developertools.html#reloading). You could even write your own macro to do all that in one and call it from your editor. I find that having an ipython prompt open with a few functions set up for doing stuff like that is quite a good way of working.

Best regards,
Tony


417
Hi,

the config file is only ready after python has been initialized, therefore you need to have the PATH and PYTHONPATH environment variables (or registry entry in the case of the python path) set correctly regardless of what you put in the config file. Usually the python installer will do this for you.

When the config file is read the environment variables are updates, so any code run after python has started will see those environment variables. They are set before any of the python modules listed in the config are imported.

If the python dll could not be loaded that could be a problem other than the dll couldn't be found. If there are any dependencies that can't be loaded then that would cause that error. Using the python installer should set everything up correctly for you and is the easiest way to make sure everything can be loaded. Using depends.exe (www.dependencywalker.com) will show you what dependencies the python dll has.

Even if you don't have admin access you can still set user environment variables. You only need to be a local admin to set system environment variables usually. Alternatively you can use a batch script to launch Excel and set the environment variables in the script before launching excel. I would have thought that the simplest thing to do would be to have python installed on your PC for you by someone that does have local admin and then everything should 'just work'.

Best regards,
Tony

418
Hi,

oh that's interesting. I've not come across that problem before! I don't suppose it's a very common use-case but I'll take a look at that anyway. Thanks for letting me know.

cheers,
Tony

419
Help and Support / Re: Using xlcell for getting data
« on: December 14, 2013, 10:07:36 PM »
Hi,

you can't get an XLCell object, but you can use the Excel COM api and get a Range object that has a Value property.

Use pyxll.get_active_object to get the Excel application object (see automation.py example, xl_app function). The you can do something like app.ActiveSheet.Range("A1") to get the range you want. If you want to get the sheet the function is called with you can use pyxll.xlfCaller.

Best regards,
Tony

420
Help and Support / Re: Question about the thread_safe switch in pyxll
« on: December 14, 2013, 10:04:38 PM »
Hi Jack,

PyXLL uses the same python runtime as the normal CPython interpreter (in fact it even just uses the same dll). So, all the usual rules apply, an in this particular case the GIL is the reason you see the performance you do.

http://dabeaz.com/python/UnderstandingGIL.pdf

Excel will call your code from multiple real OS threads, but because of the GIL you don't see any benefit if only using plain python. To see any benefit you would be having to call some code that frees the GIL while it does something (eg IO code using the socket module or some cython or C code that explicitly releases the GIL).

Best regards,
Tony

Pages: 1 ... 26 27 [28] 29 30 ... 41