Home > Net >  VS Code always gives error when trying to run code after switching to virtual env in python
VS Code always gives error when trying to run code after switching to virtual env in python

Time:09-27

the error:

PS C:\Users\Prashant(Gaz)\fieldrocket-pygame\fieldrocket> & c:/Users/Prashant(Gaz)/fieldrocket-pygame/fieldrocket/pyfr/Scripts/Activate.ps1
Gaz : The term 'Gaz' 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:21
  & c:/Users/Prashant(Gaz)/fieldrocket-pygame/fieldrocket/pyfr/Scripts/ ...
                      ~~~
      CategoryInfo          : ObjectNotFound: (Gaz:String) [], CommandNotFoundException
      FullyQualifiedErrorId : CommandNotFoundException
 
PS C:\Users\Prashant(Gaz)\fieldrocket-pygame\fieldrocket> 

so i made a virtual env through cmd, and then opened vs code, tried to switch the interpreter to the venv one, but it just gives me this error for no reason when i click on new terminal or runcode from right click menu.... this obviously works if i use the command as a string so why is vs code doing this please help...

If i manually activate venv it works just fine, but i cant quick run code because of this, idk why this happens sometimes....a few works ago i was working with django and never had this issue at all whilst using venv all the time

edit : the command is not something i typed it, i just opened a new terminal, even after activating venv manually if i re-open a new terminal, it gives the same error

CodePudding user response:

You should move your virtual environment to some other place, which path without contains the ( or ).

Update:

If you want to avoid automatically activate the virtual environment when you create a new terminal. you can add this in your settings.json file:

"python.terminal.activateEnvironment": false,
  • Related