PTVS icon indicating copy to clipboard operation
PTVS copied to clipboard

Running Main.py files in Shift+Alt+F5 does not work but does work for F5.

Open moritzmcgarrie opened this issue 9 years ago • 4 comments

I would like to replicate the behaviour of Spyder IDE: press F5 and runfile('Main.py, wdir= 'MainFolder') runs all the code and charts inside the interactive window. In Visual studio 2017 my Main.py file runs with F5 fine and it finds my classes and modules within the project/solution (of course the charts and stuff pop up and pauses the debugger which is why I also want the interactive window working). However if I run the same Main.py using Shift+Alt+F5 it runs the file but immediately stops at the first 'import Mylib as mylib' and ModuleNotFoundError: No module named 'Mylib' . It would seem that the Debugger (F5) and the interactive (Shift+Alt+F5) have different default working directories in Visual Studio. I have tried adding in Project -> Properties -> Working Directory and also tried adding my Folder to the search Paths and this did not fix it, but intuitively F5 and Shift+Alt+F5 should run EXACTLY the same code with the same configurations.

moritzmcgarrie avatar Oct 02 '17 09:10 moritzmcgarrie

Hi Moritz, Two things are likely the problem.

  1. You have installed two conflicting IDEs. Maybe you have Anaconda and also have the Original Python IDE installed. That error occurs when there're conflicting folders.

  2. Check to make sure your VS has also not installed its own Class of modules separate from what you have installed through pip. This can also be the case.

The case is most likely the 1st point. Cheers.

davik4life avatar Oct 02 '17 10:10 davik4life

Hi , I specifically deleted all python/Anaconda before installing VS2017 with Anaconda bundled as part of the install. I have a work-around to first right click the project and click Open Interactive. Then Shift+Alt+F5 goes to that 'projectname' interactive window. It seems that in VS with different Python Environments it may route to the Anaconda Interactve window or to the 'projectname' interactive window. While intuitively the interactive working directory should be same (Shift+Alt+F5 should have consistent behaviour) , how does one set the working directory of the Interactive window in VS, before runtime?

moritzmcgarrie avatar Oct 02 '17 11:10 moritzmcgarrie

This is the same as #2449 - we're going to look into it. The problem is exactly what you describe: they should run with the same configuration, but right now they do not.

zooba avatar Oct 02 '17 16:10 zooba

Can u please solve this issue of mine... In 3.4.0 shell , when I click

  1. shift+alt+fn+5 invalid error is seen.
  2. fn+5 invalid error is seen.

For the first time nothing change is seen. After closing and opening the shell window ,run the program observed a new empty window and Invalid syntax error window.

NOTE: Error red mark is seen on 4 in the 3.4.0 CalculatorPythonError

saathvika avatar Jul 21 '19 09:07 saathvika