Unable to run python script in Jupyter Notebook

Hi,

I am new to Python and Jupyter Notebook. The code is supposed to open a CSV or Excel file, plot the data and to perform analysis. I was able to run a python script successfully on Anaconda Powershell. However, when I run the same script in Jupyter Notebook, I am running into difficulties.

Pl see below for error message when I run the script in the terminal.

Note: when I run the same script from within Jupyter Notebook cell, I get
error: (25, ‘inappropriate ioctl for device’) error.


jovyan@jupyter-ramacs:~/Error_Analysis_Data/physerror$ python physerror.py
[?] Select a data file type:

CSV
Excel

Please choose a csv file:
Traceback (most recent call last):
File “/home/jovyan/Error_Analysis_Data/physerror/physerror.py”, line 1544, in
_user_cli()
File “/home/jovyan/Error_Analysis_Data/physerror/physerror.py”, line 1541, in _user_cli
inq.inq_prompt(inq)
File “/home/jovyan/Error_Analysis_Data/physerror/physerror.py”, line 1026, in inq_prompt
tempdata = Data(data_type=data_ans)
File “”, line 6, in init
File “/home/jovyan/Error_Analysis_Data/physerror/physerror.py”, line 80, in post_init
cls._colname1, cls._colname2 = cls._initdata(cls.user_x_data, cls.user_y_data)
File “/home/jovyan/Error_Analysis_Data/physerror/physerror.py”, line 147, in _initdata
x_data, y_data = reader.csvreader()
File “/home/jovyan/Error_Analysis_Data/physerror/physerror.py”, line 1495, in csvreader
tk = Tk()
File “/opt/conda/lib/python3.10/tkinter/init.py”, line 2299, in init
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
jovyan@jupyter-ramacs:~/Error_Analysis_Data/physerror$

How are you accessing Jupyter? Did you install it on your machine? Is it running on a remote system?

That is interesting, but what exactly happens in detail? How do you specify what to open? Does it open a window to do that? Is that window on your system like any other program or in the browser? Consider if that would be compatible with use in Jupyter, which granted may be difficult for you as you say you are new to both Python and to Jupyter. Based on the limited details you are you are sharing, it looks like the code you are trying to work with is not set up to be compatible with running in a Jupyter setting by default. (I see tkinter and Tk which tells me it is using older ways to run a graphical user interface (GUI) on a machine. A system that long predates Jupyter and works in very different ways.) Or at least the way you are triggering it to run in Jupyter which you provide no details about? (Are you using %run magic? Importing?) You show only trying to run it in what I assume is the associated terminal of the session.

Jupyter and Python are not synonymous. Jupyter can run a lot of other languages. All of them, including Python, do it through a language based kernel that communicates with Jupyter running in the browser. The way it runs things has to be compatible with this situation. And if you are running where Jupyter is installed in a remote machine on a full server or virtual remote machine, the situation is even more complex to consider.

You can think of Jupyter as an Integrated Development Environment (IDE) of sorts. In general it runs in your browser and so has limitations of what it can access imposed by browser workings & security concerns. For example, you wouldn’t want sites on the internet to be able to launch things and access your devices and files, right? And if you are running this Jupyter session remotely, those restrictions are even more important. Because if it is a remote server, it may not have access to a display device at all.

Contrast that with Anaconda PowerShell situation which I think is running as a program in your computer with full permissions to access your system and open windows and run devices, like display stuff in your system? It isn’t restricted by going through your browser I suspect?


Please read Getting good answers to your questions. I especially like the section in [the last link]( How do I ask a good question? ) with the heading ‘Help others reproduce the problem’.

If you need more specifics, compare what that says with what you have provided and reply with more information or a link or the code and/or link to it

1 Like