0

I just recently uninstalled python and anaconda and reinstalled Anaconda3 only (I read that Anaconda installs python for you). I'm using Python 3.8.3 through Spyder in Anaconda3.

Previous to the reinstall, I never had issues with the pip and conda commands in spyder

Now I'm getting these errors:

runcell(0, 'C:/Users/user1/.spyder-py3/temp.py')
  File "C:\Users\user1\.spyder-py3\temp.py", line 9
    pip install fastai
        ^
SyntaxError: invalid syntax


runcell(0, 'C:/Users/user1/.spyder-py3/temp.py')
  File "C:\Users\user1\.spyder-py3\temp.py", line 8
    conda install -c fastai fastai

These posts have been unhelpful: Pip install in Spyder What is the difference between pip and conda?

Is there some simple solution for this? E.g when I installed Anaconda for the first time I never had these issues.

AMC
  • 2,642
  • 7
  • 13
  • 35
RTrain3k
  • 845
  • 1
  • 13
  • 27

1 Answers1

1

Based on your output, which says

runcell(0, 'C:/Users/user1/.spyder-py3/temp.py')

and this, it is evident that you are trying to run the

pip install fastai

inside a python script. The pip command is a command line command, pointing to certain pip.exe, and it should be ran from the command line (or, you may use the IPython shell of Spyder if you want). Therefore, just run the pip install command in the IPython console of Spyder (or a cmd prompt).


In IPython shell, it is also possible to install packages using the %pip magic:

%pip install fastai

You can also run operating system commands by adding ! before your command. For example

!pip install fastai

Edit: Although, seems that pip works in my IPython shell with or without the % or !.

Niko Föhr
  • 28,336
  • 10
  • 93
  • 96
  • Hi, in an anaconda prompt I typed: python --version and it said "python is not recognized as an internal or external command, operable program or batch file". Does that mean that my anaconda installed failed? – RTrain3k Jul 29 '20 at 19:59
  • What do you mean by anaconda prompt? Could you use normal command prompt (cmd.exe or powershell)? The error text "python is not recognized as an internal or external command, operable program or batch file" usually means that the `python.exe` is not found by Windows. Windows tries to find executables from list of folders in PATH. Check your windows User PATH if it has folder that contains python.exe. You can locate the folder with `import sys; print(sys.executable)` from your python script. – Niko Föhr Jul 29 '20 at 20:02
  • I wish I could show a picture. The prompt says "Anaconda Prompt (anaconda3)" at the top. looks like this is my issuehttps://stackoverflow.com/questions/49616399/windows-anaconda-python-is-not-recognized-as-an-internal-or-external-command – RTrain3k Jul 29 '20 at 20:07
  • Did you try adding the python folder to the PATH? You can paste pictures to your question, if you edit it. – Niko Föhr Jul 29 '20 at 20:35