Dear Stackoverflow members
I've been trying to install and use the xlwings addin for several days now but I am not able to get it running... I really would like to use xlwings, but it is being painfully difficult.
I am using Anaconda.
xwlings is installed and works perfectly (I can read/write from/to an .xlsx file) but what I want to really do is to call python functions from excel and for that I need the addin.
The docs are not super useful here and I've tried to follow this guide (from https://newtonexcelbach.com/2017/07/30/installing-xlwings-0-11-4/):
" Run xlwings addin install from a command prompt. Reopen Excel and check if the xlwings Ribbon appears. If not, copy xlwings.xlam (from your xlwings installation folder under addin\xlwings.xlam manually into the XLSTART folder. You can find the location of this folder under Options > Trust Center > Trust Center Settingsā¦ > Trusted Locations, under the description Excel default location: User StartUp. Restart Excel and you should see the add-in"
When I opened excel I did not see the addin. I put the xlwings .xlam file into the XLSTAR folder... reopened excel and the addin was still not there. Then I put the .xlam file also in this folder : "C:\Users\UserName\AppData\Roaming\Microsoft\AddIns".
The .xlam file is now in both folders, and now I can see the xlwings addin.
then I create a folder with myproject.xlsm and myproject.py files by running "xlwings quickstart myproject" from the anaconda promt. The files are there but then when I try to call any python function/Script from the vba modules I always get this error:
"Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\joanc\myproject\myproject.py", line 1, in <module>
import xlwings as xw
ModuleNotFoundError: No module named 'xlwings'"
for example, I get this error when I try to run the code that is already available when myproject.xlsm is created. The code looks like this:
sub SampleCall()
mymodule=Left(ThisWorkbook.Name, (InStrRev(ThisWorkbook.Name, ".",-1, vbTextCompare)
RunPython("import " & mymodule & ";" & mymodule ".hello_xlwings()")
end sub
I tried to run this code directly from the developer tab and also from a button created in sheet1 and assigning its corresponding macro...
As a side note if I go to the developer tab>tools>references i can see the xlwings checkbox active... so this should not be a problem.
Well, this is all I've done so far... no idea what I am doing wrong and what to do next. I would really like to use this package but if anyone knows a good alternative I am totally open (not only to read/write from/to excel but also to call python scripts/functions directly from excel)
Thank you very much for your help
Related
I'm a beginner programmer and I'm trying to import a CSV file into Jupyter Notebook. I am following the instruction on this article link. However when I change the file used on the link to my file I get this error Error Image. How should I go about addressing this issue?
Carry your .csv file to the same directory with your notebook (If you use windows as OS, it probably will be in C:\Users\your username as default). Then you better call your data file by pandas.read_csv()
I've written a simple python script that uses openpyxl to read IP's out of an excel file and does a whois lookup on it and writes the results to a new excel file. Everything works great in Spyder but when I package it as an exe using pyinstaller I get an error when I run the exe.
The traceback says "'Worksheet' object has no attribute 'values'" like it's not reading the values from the original excel file. I've tried using the full path of the file but still get the same error. The excel file is in the same directory as the exe. Do I need to package the exe in a different way? Specifically tell it to package the openpyxl library?
I've done a lot of googling and can't find much info. Any help is appreciated! Thank you
I'm new to Pandas and I was beginning to run a simple code to work with this CSV file I downloaded from the government portal. Here's my code -
import pandas as pd
df = pd.read_excel(r'C:\Users\ADMIN\Desktop\Abhishek')
print(df.head)
The path is correct and it didn't work without adding the r at the beginning so I used that. However, this code results in these errors and I'm not sure how to handle any of them.
I've opened the file on Excel and I don't think there's any problem with it. What am I doing wrong?
Python doesn't have permission to open the file. Run your interpreter as administrator, or adjust permissions.
Right click your python shell and select "run as administrator".
So, I have an Excel workbook that I originally created on Windows 7 running Anaconda 4.1.1 (Python 3.5) and Excel 2013. Everything was working great in that environment. I am now trying to work on it remotely using a computer running Windows 10, Anaconda 4.1.1, and Excel 2016. I downloaded the workbook and its corresponding .py file, but when trying to import the UDFs in the .py file I get the following error:
(link to image)
If for some reason the link is broken, the error text is basically
ImportError: No module named 'C:\\Anaconda3\\custom_scripts\\loop_parameters'
The file's name is "loop_parameters.py" and it is found in the path "C:\Anaconda3\custom_scripts". It seems to me that somehow the name of the module (loop_parameters) is getting conflated with the path associated with it. But I have no idea how to fix that. I tried changing the UDF_PATH variable with no change in the error message at all. Thoughts?
So I ended up just starting a new project in xlwings on the new machine, copying over the python code into the new .py file, importing the UDFs, then copying the entire workbook from the old (non-functioning) book to the new one, where the UDFs worked fine. I'm still not sure what the error was or why it was happening. The workaround does seem clucky, but it only took a few minutes.
I am getting the following error when I run my python script:
/Documents/stage/crocus/python$ python bonaiguaforcing.py
sh: 1: ncks: not found
sh: 1: ncatted: not found
Traceback (most recent call last):
File "bonaiguaforcing.py", line 142, in <module>
creatforc('/home/chomette/Documents/stage/crocus/bonaigua2.txt','/home/chomette/Documents/stage/crocus/FORCING_bonaigua.nc')
File "bonaiguaforcing.py", line 46, in creatforc
meteo=netCDF4.Dataset(net_out,'a')
File "netCDF4/_netCDF4.pyx", line 1746, in netCDF4._netCDF4.Dataset.__init__ (netCDF4/_netCDF4.c:10983)
RuntimeError: No such file or directory
In my python script I create a netCDF file to copy data and then I create a new netCDF file with a new variable, it seems that python didn't find the first netCDF file created.... but I'm not sure.
Thanks for your help =)
Without seeing the code producing the error, this looks like an environment definition problem. Your shell can't find where NCO is installed (if you don't have NCO then this is a dependency problem and you need to install it for your script to work).
Have you tried in bash :
which ncks
which ncatted
If these are not in your path, you are going to need to add aliases pointing to them in your bash rc, execute under your home directory the following (with vi or another editor) :
vi .bashrc
then add to the file:
alias ncks='/usr/bin/ncks'
alias ncatted='/usr/bin/ncatted'
You will need to change /usr/ to the location of your NCO installation. Also, don't forget to source . .bashrc before testing your program again. You can also just type your aliases into the shell, but you will need to do this each time you open a new terminal.
Updated answer (based on your comment below):
now it appears that your script is not finding part of the netCDF4 module (the part of it written in c, hence the .pyx extension). You'll need to make sure that your environment is correctly defined and that the netCDF module has been correctly compiled. Before going any farther, type the following commands in a terminal:
python
from netCDF4 import Dataset
to make sure that the module exists. If that works, then you can follow the instructions on https://netcdf4-python.googlecode.com/svn/trunk/docs/netCDF4-module.html to create a dataset in order to make sure that the module was correctly compiled.
For information, are your porting the crocus model to a new machine ? If so, that might explain why you are missing so many dependencies (modules, libraries and operators that your code needs in order to function). If not, there may be another error in your script which is making this look like a dependency problem. Please post part of your script for generating the crocus forcings if you do not think this is a problem with your environment/dependencies (ie if someone has already run the same script on your machine and it worked). Thanks!
You're seeing a RuntimeError because the filename specified in netout does not exist--the 'a' mode (append) requires that the file exist.