1

In a project, I noticed that conda was not activated in my PowerShell, Whenever I attempt to run the

conda activate base

command I get the following set of errors;

Invoke-Expression : At line:1 char:295
+ ... conda3\condabin;C:\Python310\Scripts;C:\Python310;"C:\Program Files\n ...
+                                                        ~~~~~~~~~~
Unexpected token 'C:\Program' in expression or statement.
At C:\ProgramData\Anaconda3\shell\condabin\Conda.psm1:101 char:9
+         Invoke-Expression -Command $activateCommand;
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ParserError: (:) [Invoke-Expression], ParseException
    + FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.InvokeExpressionCommand

A previous post has a very similar question, with one of the comments informing me to check the double quotes on C:\Program files...

I couldn't understand which file this has occurred, A glance through the .psm1 file informed under the unexpected token error does not show any of the above-mentioned paths.

2 Answers2

1

I find that it has nothing to do with the Conda.psm1 despite the error message, but rather on the format of our path variable.

What works for me (Windows):

  1. Go to your Control Panel and then to the Advanced System Setting
  2. Go to the advanced tab of the system properties, you should see the 'Environment Variables' button, click that
  3. You should be able to find a variable called 'Path' in the top box user variable
  4. Double-click on that to edit your path statement to get rid of any unnecessary quotation or double semicolon (whatever is causing your error).
  5. Make sure to close all terminals before you try to 'conda activate' again
0

I ran into a similar issue and was able to solve it by inspecting the Windows PATH variables.

Offending quote in user variable PATH In Windows 10:

  1. in PowerShell, type $Env:Path
  2. inspect the output for unexpected quotes or other odd characters
  3. open "Edit the system environment variables" from Control Panel (or search for "environ" using the windows search
  4. PATH may be present in the top and bottom sections - User variables, System variables
  5. in my case, I had pasted a quoted path in user variables
  6. remove the quotes or offending characters
  7. open PowerShell again (no errors should appear now)
  8. run conda activate base if it does not happen automatically (no errors should appear)

Cause: After running the CUDA 11.8 installer on Windows 10, it informed me that it was unable to update the PATH variable due to it being the maximum length. I manually edited the PATH and then noticed Powershell was producing errors related to conda trying to activate base. I must have pasted a quoted string in the user variables PATH.