Notepad++/Visual Studio 2019/Python
-
I am trying to get NPP to execute python and run a script that I am editing from run menu. I am using the command line
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python “$(FULL_CURRENT_PATH)”
Which stops with an error code of 2. But, if I use nppexec and use the command line
cd C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64
python “$(FULL_CURRENT_PATH)”it works. ANy ideas as to why the single line command fails, but the 2 line command works?
Thanks
-
By “Error code 2” I assume you mean N++ is popping a window with that error code? If that’s the case, it’s explaining that it can’t find the command “C:\Program” and the rest as the arguments since there’s a space.
Try wrapping the python command in double quotes in your Run menu config in shortcuts.xml:
<Command name="Run Python" Ctrl="no" Alt="no" Shift="no" Key="0">"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python" $(FULL_CURRENT_PATH)</Command>
Interestingly, NppExec doesn’t need quotes around the path even with spaces.
Cheers.
-
Mark,
“C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python” “$(FULL_CURRENT_PATH)” should fix the problem. When you cd to the Visual Studio installation directory for Python, the spaces in the path are no longer an issue as you are in the same directory as the Python executable.
Personally, I would not have Visual Studio install Python and instead use the Python installer. The Visual Studio installer (I am still on Visual Studio 2017), will allow you to install Python support without installing Python. I have the following Python installations on my computers:
- C:\Python27 - for legacy programs
- C:\Python37 - for current programs
For many years at work, my main software used Python 2.N and had the option to not install it because I already had it installed under C:\Python27. I have NppExec set up to run Python scripts (with arguments) and to also run the Python debuggers/linters Pylint and Flake8.
Steve
-
@Steven-Haymes said:
“C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python” “$(FULL_CURRENT_PATH)”
It seems like this should be better than Michael’s suggestion in the event that there are any spaces in
$(FULL_CURRENT_PATH)
. Michael left wrapping double quotes out of that, even though the OP had them there in 2 places. Interesting. :)When you cd to the Visual Studio installation directory for Python, the spaces in the path are no longer an issue
Not sure I’m following this part as the OP was only doing the
cd
for purposes of trying an equivalent thing with NppExec. There should be nocd
in what the OP is finally trying to get to? -
I agree that there should be no cd. I was not thinking about how NppExec works when I mentioned about cd’ing to the directory where the Python executable is located. I was thinking more about how the Windows command prompt works. Maybe, I should have been thinking about NppExec? IMHO, spaces in file and directory names was never a good idea.
S
-
@Alan-Kilborn said:
Michael left wrapping double quotes out of that, even though the OP had them there in 2 places
purely an oversight - thanks. Corrected below:
<Command name="Run Python" Ctrl="no" Alt="no" Shift="no" Key="0">"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python" "$(FULL_CURRENT_PATH)"</Command>