Using Python functions within Excel - python

I've been searching for the best way to use Python functions within excel/VBA. I tried pyxll for a month (their free trial), but I found it very unreliable.
I've found now three other possibilities: ExcelPython, DataNitro and xlwings. Any suggestions? Which one is the most widely used in the Python community?

I have settled on xlwings for right now. I had to go through the following steps to get xlwings setup, maybe it'll help someone else down the road to have a more clear roadmap of needed items.
Process for my setup to get XLWINGS running
Python 3.4
MS C++ 2010
Pywin32
pip install xlwings

Related

How to use pyleargist in python 3?

Whenever i try to pip install pyleargist, it gives me this issue.
Is there a version compatible with python 3 ?
Can someone help on this ?
The library was last updated in 2012, see the pypi page and as you already noticed, the issue you are seeing is based on the fact that it was written for python 2. In this case, file seems to be used in the setup.py, which was removed in python3. For this exact library, it seems to be stale, so no other versions.
You have two options:
It does not look to be a large library, you could download the source code from pypi and try to fix the python 2/3 issues.
Search for another library. A google search shows several options for python libraries that can compute the GIST descriptor. Just look for another one that fits your requirements

no soundex on python

I use the sqlite3 librairy on python to interact with a .db file.
With this request:
SELECT * FROM LesFilms F JOIN LesRealisateurs R ON (F.film_id=R.film_id) WHERE realisateur="Tim Burtyn" or soundex("Tim Burtyn")=soundex(R.realisateur) or realisateur like"T%m Burtyn" or realisateur like"Tim B%rtyn" or realisateur like"Tim Burt%n";
I got this error:
sqlite3.OperationalError: no such function: soundex
Do someone already face this problem? I share the whole request in case, I'm a total beginner.
Thank you,
Elias
I think you are out of luck, as you have probably gathered from the comments. The Python standard library module sqlite3 generally provides an up-to-date version of sqlite.
In Python 3.9 it is 3.32.3 from June 2020.
In Python 3.8 it is 3.31.1 from January 2020.
In Python 3.7 and Python 2.7.17 it is 3.28.0 from April 2019.
But the Python sqlite3 library does not provide optional sqlite features that come switched off by default. This includes the soundex function. I can't recommend that you try building your own version of the Python standard library module with the option switched on. That sort of thing is best left to Python implementers.
As an alternative you might try the levenshtein module: pip install python-Levenshtein or the metaphone module: pip install Metaphone.
To use either you would need to fetch more records from the database than you really want, for example where realisateur like "T%" and then discard the mismatches in Python code rather than in the where clause.
This is not as bad as it sounds, and may have benefits. Soundex was developed in the early 20th century and so it was intended for people to be able to compute it quickly by hand. It has significant deficiencies, as shown by the many attempts in the subsequent 100 years to improve it. The primary reason for its popularity is because it is provided by many SQL implementations, not because it is particularly good.
load your data into a dataframe then use fuzzywuzzy to find similar string words

Using Pandas with FreeCAD

I am brand new to FreeCAD and fairly new to python in general.
I have a project going on in which I have a list of several hundred (x,y) coordinates stored in two columns in an Excel doc. These points define a slice of an elevation profile. What I'm needing to do is draw a line/shape in FreeCAD using these points that can then be extruded into an extended version of this shape. Since the data is currently in excel, I'm leaning towards using pandas to access it, but I'm open to other ideas.
The problem I'm having with this line of thinking so far is that I can't figure out a way to access pandas from inside FreeCAD, so I've been attempting to use Winpython(2.7.10) through the Spyder ide to import FreeCAD(0.16) and pandas into the same script. I've tried adding both the Freecad/bin and Freecad/lib folders to my path (using this recommended method https://www.freecadweb.org/wiki/Embedding_FreeCAD/en), but have yet to have any success importing.
The error is: "DLL load failed: The specified procedure could not be found." .... Searching around, I can't seem to find FreeCad.dll or FreeCAD.so anywhere in my install, yet FreeCAD runs normally when used independently.
To summarize: Wanting to run FreeCAD through an external python console in order to access excel data through pandas (which doesn't seem to be available within FreeCAD itself). In doing so, I get an error and FreeCAD isn't accessible. It might be a version compatibility issue, or something more complex.
If you made it here, thank you for taking the time to read through my fairly complex/niche problem. Please feel free to suggest any more elegant alternatives, as I said, I'm new to this and likely haven't come across all possible solutions.
Thank you
I'm not exactly certain what "pandas" is - a quick search didn't reveal anything except the game engine Panda3D and the animal itself...
As for accessing data external to FreeCAD, this is something I've been exploring myself lately. At the moment, some success has been achieved by starting FreeCAD in server mode and having it watch an excel file, then running python script when it changes.
This approach would allow you to parse an Excel file using commonly available python libraries for that purpose.
EDIT:
Having been informed on just what pandas is, it seems odd you can't make it work with FreeCAD. However, there could be a number of causes:
Old version. FreeCAD is undergoing really significant change right now. Ensure you're using the latest stable release (0.17 - Roland), but I'd recommend getting your hands on the latest 0.18-dev release
Incorrect python version - FreeCAD currently is built on Py2, though Py3 builds are possible (I run FreeCAD / Py3 on my linux machine). Ensure you've installed pandas appropriately to match the python version FreeCAD depends upon (Py2, most likely).
Invalid install - If you know pandas imports and works in the python interpreter itself, try importing and running pandas code from the FreeCAD python console.

Python xlwings VBA reference not loading

I want to run a python script from VBA using xlwings. I have installed the excel add-in by running
xlwings addin install
from the command prompt, however, the 'xlwings' reference is not showing up in the list of available references in my VBA project. (As a separate but perhaps connected issue, the xlwings add-in in the ribbon is only partly showing: it only shows the 'Active Workbook' and 'Advanced' subcategory.)
I am on Windows 7 Enterprise and Excel 2016
I came across the same problem. However, there was a work around. Since ultimately you want the work without alerting "no xlwings moduldes", you can manually import xlwings and xlwings_udfs modules into your current workbook then it will work. Those two modules should be available on any example spreadsheet from xlwings official website.
I just had the same issue. xlwings seems to be in the list, if you have "VBAProject (Book1)" selected before going to Tools->References.
You have to make sure that you do not have the "xlwings (xlwings.xlam)" module selected, before selecting Tools-> References.
Try removing the xlwings module from the VBA project(must be empty to remove...you should only have config settings there anyways) and installing the add-in via command line(xlwings addin install). Now when you try to edit your references, first confirm the xlwings project is visible in the VBA project directory on the left, and then select your current project and try to add a reference. Xlwings should now be in that list. I managed to resolve several issues by upgrading to the latest xlwings version - the older version Anaconda came with seemed to be missing a fair amount of functionality, mainly concerning the add-in(which as far as I can tell is superior to the module.)

How can I run online python code that requires a set of modules?

How can I run online python code that owns/requires a set of modules? (e.g. numpy, matplotlib) Answers/suggestions to questions 2737539 and 3356390 about interpreters in python 3, are not useful because those compilers don't work properly in this case.
I found one that supports multiple modules, i checked numpy, scipy, psutil, matplotlib, etc and all of them are supported. Check out pythonanyware compiler, a sample console is here, however you can signup for accounts here, i believe there is a free version. I remember i used that that online compiler last year and it worked quite well, but for a free account it has certain limits. It also has a bash console, which allows you to run the python files.
You may try this as sandbox, it support numpy as well: http://ideone.com
You can try one of the best editors I found on internet , which has not only your requirements but more than that.
Here is the link - Replit

Categories