I am trying pip commands. I am installing OpenAI Gym. I wrote the following command in a notebook cell and run it: pip install gym
It worked and gave me a message of successful installation.
But when I tryed typing the same command in a .py
script file and run it, it gives me an error:
pip install gym
^
SyntaxError: invalid syntax
I know that I already have the gym package installed on my machine since the successful execution in notebook. However, I think it should give me different message that it is already installed or updated like when I rerun the command again in notebook cell:
Requirement already satisfied: gym in c:\users\osama\anaconda3\lib\site-packages (0.20.0)
Requirement already satisfied: numpy>=1.18.0 in c:\users\osama\anaconda3\lib\site-packages (from gym) (1.20.3)
Requirement already satisfied: cloudpickle>=1.2.0 in c:\users\osama\anaconda3\lib\site-packages (from gym) (1.6.0)
Note: you may need to restart the kernel to use updated packages.
I just need to understand !
CodePudding user response:
pip
is a command line utility that works only on a terminal or command prompt window. Your .py script is a file for python code, and the pip command is not python code, therefore python does not recognize it and it gives you an error.
Here is an official guide on how to get started using pip
CodePudding user response:
pip install gym
is not python script.You should run it in system terminal like Bash
, PowerShell
,Cmd
and so on to install required package.