1

I need help opening Python using the command line from other folders. Currently, I can only open Jupyter Notebook via the command line in the directory that Python was installed in. The following commands worked:

python -m jupyter notebook

or

python -m notebook

Excluding python -m or -m results in an error.

When trying to access python from any other folders using the same commands, I get the following error:

'python' is not recognized as an internal or external command,
operable program or batch file.

A similar error is thrown when I use jupyter notebook or notebook.

I have downloaded Python and have used it using IDLE. I also installed Jupyter Notebook using pip; I did this by accessing Windows Powershell in the folder where Python is located.

Would appreciate it also if someone could explain what was happening and what I could do in the future to avoid this. Thank you for the help!

Meggy
  • 67
  • 1
  • 9
  • 1
    Does this answer your question? [How to add to the PYTHONPATH in Windows, so it finds my modules/packages?](https://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-so-it-finds-my-modules-packages) – python_user Apr 21 '21 at 07:59
  • I think it should, but I need admin user rights to be sure. Thank you for the help! – Meggy Apr 21 '21 at 08:11

2 Answers2

2

Python is not recognised outside its own folder (as you mention). To 'expose' the Python command to the console, you can add it to your Windows environment variables, as per the Python documentation.

To permanently modify the default environment variables, click Start and search for ‘edit environment variables’, or open System properties, Advanced system settings and click the Environment Variables button. In this dialog, you can add or modify User and System variables. To change System variables, you need non-restricted access to your machine (i.e. Administrator rights).

Concretely, in the environment variables of your system, edit the 'PATH' variable and add the folder with your Python executable to the path. After restarting your command prompt you should now be able to execute python commands.

fravolt
  • 2,565
  • 1
  • 4
  • 19
  • I'm working on an office-owned machine, so it seems I will have to request for administrator rights to fix this. Thank you for your help! – Meggy Apr 21 '21 at 08:11
  • No worries! The documentation page also mentions the way to export the path only once, which shouldn't require admin rights. While you leave the command prompt open, the command should remain accessible in this case. – fravolt Apr 21 '21 at 08:16
  • I tried the method in what you linked and it worked for me! Thank you so much! – Meggy Apr 21 '21 at 08:29
1

While installing the Python, you can choose to add Python to PATH, if you check this while installing, you will have environment PATH variable in the machine.

enter image description here

Then you can just install notebook as you install any other packages/libraries in python.

pip install notebook

Once you do that, you should be able to start notebook from any folder/directory in your machine. the command is pretty simple.

jupyter notebook
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45