I'm new to xlwings - started with trying to understand basics but it is not working ...
Created .py and .xlsx files (with same name) in same folder; inserted basic "Hello World" code as main() in .py file.
Using Run main button in Excel file gives:
Run-time error '53': File not found
Tried to trouble-shoot why this could be: debugging via VBA interface found that the routine was searching in the folder C:\Users\MYNAME\AppData\LocalTemp\ (not the project's folder) and coming up with a very long .log filename which changes each time I attempt to run it (eg. xlwings-374ABEE7-4C51-8622-AB5B-D42C5294C2B8.log)
Is this a bug which needs to be corrected? or have I done something incorrectly?
Using:
Windows 10;
MS Office 365;
xlwings ver: 0.19.5
Related
TL;DR
My project uses a custom script file at runtime.
My project builds fine in VS and runs on the command line.
However when running in VS an error is thrown implying the file doesn't exist.
Full Details
My c++ project uses a custom scripting file to apply some settings at run time:
these are javascript like but not actual javascript
having these settings not in compiled files means they may be changed without recompiling
Everything builds fine, the script is copied using xcopy in a post build event.
When running in VS2019 it doesn't seem to be able to find the scripting file.
An opaque, library specific error is issued: A GenApi error has occurred
But when running the resulting .exe from cmd everything works, the script is used no problem.
If the script file is removed from the output dir and the .exe is run again I get the same A GenApi error has occurred.
I have tried:
running in release and debug.
including and excluding the file from the build.
I don't want to debug the script, I just need it to be used during start up so I can debug the rest of the program which is in C++.....
Example Code
Main.cpp
#include <iostream>
#include <EGrabber.h>
void configure() {
Euresys::EGenTL gentl;
Euresys::EGrabber<> grabber(gentl);
grabber.runScript("config.js");
}
int main() {
try {
configure();
} catch (const std::exception &e) {
std::cout << "error: " << e.what() << std::endl;
}
}
config.js
var grabber = grabbers[0];
var FPS = 150;
// camera configuration
grabber.RemotePort.set("TriggerMode", "On");
grabber.RemotePort.set("TriggerSource", "CXPin");
grabber.RemotePort.set("ExposureMode", "TriggerWidth");
// frame grabber configuration
grabber.DevicePort.set("CameraControlMethod", "RG");
grabber.DevicePort.set("CycleTriggerSource", "Immediate");
grabber.DevicePort.set("CycleMinimumPeriod", 1e6 / FPS);
More info:
script documentation
based on #john 's comment:
There is a different current working directory when running from VS and when running from the command line.
When run from VS the current working directory is the project directory not the output directory.
The script was in project-dir\src not the immediate project dir.
Moving the script up to the project directory solved everything.
Alternative solutions, which worked:
Use the full path: C:\\full\\path\\config.js
(the application startup path can be extracted from argv[0])
Change the debug working directory in VS:
Project -> Properties -> Configuration Properties -> Debugging -> Working Directory
Enter output path, eg: $(SolutionDir)bin$(Platform)$(Configuration)\
I am new to C++ and I am using the free version of Microsoft Visual Studio 2019.
I have written a small code which I use to integrate some differential equations (by using odeint libraries provided by Boost).
After the integration process ends, the time evolutions of the state variables are stored in the matrix mat (I use the Eigen libraries to define it row by row):
MatrixXd mat(t,4);
for (int i = 0; i <= t-1; i++)
{
mat.row(i) << times[i], x_vec[i][0], x_vec[i][1], x_vec[i][2] ;
};
Then I save the content of the matrix in a .txt file:
ofstream file("mat_save.txt");
if (file.is_open())
{ file << mat << '\n'; }
file.close();
However the .txt file is created only if I run the code in Debug mode, while if I only compile it the file is no longer created and no output can be displayed in the Console, since it is only opened when Debug mode is chosen.
Is there a way to make the Console appear and remain open and also to make the .txt file to be successfully saved, simply "compiling" the code avoiding debugging?
If so, I would save lot of time because the debugging is quite slow.
Thanks in advance!!
I'm not sure if by debug you mean running the code in Visual Studio vs compiling and then running the created exe. It Kind of sounds like a relative path issue.
Try using a full path. Or try opening a command prompt, cding to the path with the exe and then running it and check to see if the file is created in the folder you cded to.
You can also try opening the exe in Visual Studio like it was a project. Another thing to try is attaching VS to a running process to debug: http://msdn.microsoft.com/en-us/library/c6wf8e4z.aspx
The Windows Powertool "Handle" can display what handles a process is currently using which could be useful in determining if it is writing a file somewhere unexpected: https://learn.microsoft.com/en-us/sysinternals/downloads/handle
I really like Sublime Text 2 for HTML/CSS and Python and I'm starting to learn C++ and I want to use Sublime Text 2. I have looked at a few tutorials on installing g++ in order to run C++ in Sublime Text 2.
This is my code:
// my first program in C++
#include <iostream>
int main()
{
std::cout << "Hello World!";
}
And when I run it it says [Finished in 1.5s] but nothing got printed. I have added the environment variables path but nothing gets printed.
The problem is that you are pressing build, which compiles your source code into an executable but does not run it. The [Finished in ...s] you are seeing is how long the program took to compile.
What you need to do is build like you currently are, but then go to the directory where your source code is and run the executable file that's in there*. There is a run option within the editor, but it doesn't always work on Windows**.
*if the program closes instantly, try running it from the console or adding std::cin.get() to the end of your program
**often due to incorrect configuration
I'm getting started with C++ and I use Qt Creator (I run Lubuntu 13.04).
Today, as any good start with programming, I wrote my Hello World program to see if things work after installing Qt5 and Qt Creator.
I created a new Console Application project and wrote:
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World!";
return 0;
}
Saved my project as Test, and tried to run it.
I just keep getting
Starting /home/MYUSERNAME/Qt Programming/Test/Test...
Cannot change to working directory '/home/MYUSERNAME/Qt Programming/Test': No such file or directory
/home/MYUSERNAME/Qt Programming/Test/Test exited with code -1
Any ideas on how to fix this?
Thanks in advance.
Just maybe problem is a space in 'MYUSERNAME/Qt Programming/Test'.
Anyway take a look in project build settings. Something is wrong with path where compiler is looking for your project
Are you sure there is a "Test" directory in the "/home/MYUSERNAME/Qt Programming/Test" directory ?
Using my qt4 installation I've tried starting a new Qt Console Application, chosen the folder to create project in, typed out Test for the Project name hit next, deselected Debug, but kept release. Hit next. chose none for version control, hit finish.
Program skeleton shows up. Must delete the include statement for QCoreApplication. Replace it with iostream. Deleted "QCoreapplication a" and "return a.exec". put in std::cout<<"Hello World \n"; and return 0;. Then I saved everything hit the play button and xterm is opened and displays hello world. No problems here. I even tried with spaces in directory names. Again no problems.
Then I tried creating project non-qt-project->plain c++ project. After the same menus as above, found a skeleton with exactly your code except with an endl at the end of cout statement. Hit the play button. Again no problems here. Again it opened up xterm and printed out Hello World!
Don't know what else to tell you. If you changed the name to Test AFTER you created the project, I would say, start again and this time don't change the name.
I may install qt5 on my opensuse 12.3 x86_64 installation and will be able to see if there are problems with it.
Linux seems to be easy: xdg-open <file/directory/URL>.
Apparently, Mac is similar: open should be used instead of xdg-open. I don't have access to a Mac so I couldn't test it.
For Windows, I found 4 different suggestions and those that I have tried failed.
Is there a non-java, cross platform way to launch the associated application for a certain file type?
suggests start
How to give focus to default program of shell-opened file, from Java? suggests
cmd /c start ...
How to open user system preferred editor for given file?
How to Find Out Default File Opener with Java?
suggest RUNDLL32.exe
What is the correct way to use ShellExecute() in C to open a .txt
Open file with Windows' native program within C++ code
How to use ShellExecute to open html files in Windows using C++? suggest
ShellExecute
I have tried the first 3 with system() and QProcess::startDetached() and "http://www.stackoverflow.com" as argument but they all failed; start works just fine from the command line though. I haven't tried ShellExecute yet.
What is the Windows equivalent of xdg-open? It seem to me, it is start but why did my attempts with start fail?
Is ShellExecute my only option?
EDIT I thought QDesktopServices::openUrl() was for web pages only because it did not work for files or directories.
After some debugging I figured out that if I replace \\ with / in the path on Windows, it works for files but the directories are still not opened. Any ideas what I am doing wrong?
QDir dir("C:/Documents and Settings/ali");
qDebug() << "Exists? " << dir.exists();
qDebug() << dir.absolutePath();
QDesktopServices::openUrl(QUrl(dir.absolutePath()));
qDebug() << "External app called";
Application Output:
Exists? true
"C:/Documents and Settings/ali"
External app called
But nothing happens, the directory is not opened. On Linux, directories are opened with the default file manager as expected.
SOLUTION: Due to the Qt bug and Windows quirks (malformed application window), I ended up using ShellExecute. That gives me enough flexibility to achieve exactly what I want at some expense...
Why don't you just use Qt's support for this? For example:
QDesktopServices::openUrl(QUrl("/home/realnc/test.pdf"));
This opens the document in Acrobat Reader. In general, it obeys the preferred application settings in my OS for all file types that have one or more applications associated with them. Best of all, it's platform-independent.
Edit:
The fact that it opens directories on Linux but not on Windows smells like a bug. It might be best to report this on Qt's bug tracker. In the meantime, you could have a workaround for Windows for when the file is a directory:
#ifdef Q_WS_WIN
if (QFileInfo(path).isDir())
QProcess::startDetached("explorer", QStringList(path));
else
#endif
QDesktopServices::openUrl(QUrl(path));
You can also do it with cmd.exe's start command, but you'll get an ugly terminal pop up for a few fractions of a second:
QProcess::startDetached("cmd", QStringList() << "/C" << "start"
<< QDir::toNativeSeparators(path));