Problems executing jupyter notebook script from cmd in windows - python

First I added the 2 directory paths where I installed Anaconda3 in the Path system variable because I was getting this error:
'jupyter' is not recognized as an internal or external command.
i.e. 1. C:\ProgramData\Anaconda3
C:\ProgramData\Anaconda3\Scripts
However, I still cannot execute the script. I get a bunch of Tracebacks and the error at the end:
ImportError: DLL load failed: The specified module could not be found.
I am not sure where my script file needs to be but I tried 2 directories. First the initial directory where jupyter creates it and next I moved it inside the \Anaconda3\Scripts folder but both to no avail. I am also getting the same error if I try to run jupyter from cmd.

IPython notebooks are stored in .ipynb formats. While python files are of .py format. This being said, you'll have to convert the notebook to a python file.
cd into the directory your notebook exists and type the following in your command prompt
$ jupyter nbconvert --to script [NOTEBOOK_NAME].ipynb
A .py file with the same name should now be there in the same directory.
You can find other export options available, and the examples mentioned in their docs

Related

How do you open Jupyter Notebook without Anaconda and from any directory?

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!
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.
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.
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

Run python module commands on Windows

I installed Sphinx using pip install sphinx command in Windows Terminal and I want to run sphinx-quickstart to make documentation in my docs directory but it doesn't work.
I get this error instead:
sphinx-quickstart : The term 'sphinx-quickstart' 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.
If I try to run it via GitBash or using py or python at the beginning that says:
\path_to_python\python.exe: can't open file '\My_working_directory\docs\sphinx-quickstart': [Errno 2] No such file or directory
How can I solve this problem?
The easiest way to do it is to create simple virtual environment and you will able to install packages you want and run it.
Just create folder and run command to create virtual environment then just activate it using .bat file.
Read the docs but it can differ in future versions of Python.

Can't launch Jupyter Notebook from the command line in Windows 7

On a Windows 7 machine, I installed Python 3.8.5, pip using the get-pip.py installation script from here, and Jupypter Lab + Jupyter Notebook following the instructions here. When trying to launch Jupyter Notebook, I get the following error message:
C:\jupyter notebook
'jupyter' is not recognized as an internal or external command,
operable program or batch file.
What is the problem? I verified that both Python and pip was successfully installed by launching the Python console and doing pip -V.
https://jupyter.org/install is general installation instructions, but assume some familiarity with Python, pip, and system execution path searching.
You need to add the location where pip installed jupyter to you system PATH environment variable.
To test this theory, try seeing if you have jupyter.exe in a folder similar to C:\Program Files\Python38\Scripts.
Answers to questions like this one, explain ways to edit the PATH variable.
Screenshot example of editing user's PATH:
I don't know the exact condition but try this..
"jupyter notebook"
and if it doesn't work then you might want to add installation location to your environment variables.

How to run .py files on Windows/Anaconda terminal?

So I installed Anaconda on my computer, and use Jupiter notebook to write a script.
I have some .py files I want to run from Windows or Anaconda Terminal, just out of curiosity.
Here are the error message I got -
C:\Users\xxx\Documents>python ex1.py
'python' is not recognized as an internal or external command,
operable program or batch file.
Is there a way that I can run python on Windows without messing up the path?
I guess you are using Command prompt to parse python files.
Open Anaconda Prompt,
navigate to the folder containing your python files cd c:\path\to\python\folder
execute using python ex1.py where ex1.py is your filename
in the anaconda terminal

How to interpret .py files as jupyter notebooks

I am using an online jupyter notebook that is somehow configured to read all .py files as jupyter notebook files:
I am a big fan of this setup and would like to use it everywhere. On my own jupyter installation however, .py files are just interpreted as test files and are not by default loaded into jupyter cells. How can I achieve the same configuration for my jupyter notebook?
What you're looking for is jupytext.
You just need to install it into python env from which you're running your jupyter notebooks:
pip install jupytext --upgrade
And you get this:
That's not exactly what you asked, but you can achieve something close to that by using the magic %load FILE.py in a new jupyter notebook.
%load FILE.py will copy the contents of FILE.py in the current cell upon executing it.
You use the python code in your Jupyter Notebook by just pasting the whole code in a cell OR :
%load pythonfile.py to load code from a file (not necessarily .py files) into a jupyter notebook cell;
%run pythonfile.py in order to execute the file instead of loading it (outputs whatever that file outputs).
Also, pythonfile.py should exist in the cd or you can use its full path.

Categories