Skip to content
Advertisement

Visual Studio Code Terminal keeps running Python script in Powershell

I recently installed both Python and Visual Studio Code. After taking an intro class I wrote a basic script and ran it in Visual Studio Code. That’s when I noticed a problem with the way Python is setup in my Visual Studio code. Problem: When I start Visual Studio Code and open a python file, the Terminal defaults to “C:Usersmy_nameDocuments Python” (this is the folder my python files are stored in). From what I understand, when you’re in Python, the prompt should be “>>>”. I am able to run my script but i cannot run any other Python code (ie something as simple as z = 5) in the terminal. If I type in “Python”, I am prompted with “>>>” but can no longer run my script.

I thought this was an installation issue so i uninstalled and reinstalled both Python and Visual but the problem persists.

I tried adding the Python file path to where the program is installed to the windows environment under system settings and also clicked “Add to Path” when reinstalling Python but none of these solutions seemed to work.

when basic python code (ie z=5) doesn’t seem to work but the script runs fine I get the error message below:

PS C:Usersmy_nameDocumentsPython 2> z=5
z=5 : The term 'z=5' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ z=5
+ ~~~
    + CategoryInfo          : ObjectNotFound: (z=5:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Below is the error message I get after I switch to python and try running my script

PS C:Usersmy_nameDocumentsPython 2> python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> & C:/Users/my_name/AppData/Local/Programs/Python/Python37-32/python.exe "c:/Users/my_name/Documents/Python 2/new2.py"
  File "<stdin>", line 1
    & C:/Users/my_name/AppData/Local/Programs/Python/Python37-32/python.exe "c:/Users/my_name/Documents/Python 2/new2.py"
    ^
SyntaxError: invalid syntax
>>>

Advertisement

Answer

I figured out what the issue was here. Visual code thought Python was installed in the directory that my .py files are saved in as opposed to the actual location under program files. The path had to be edited under settings.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement