Not reading file after opening console / Variable explorer

Hey,
I’m using Python 3.9.18, Jupyter Notebook 7.0.6 in Spyder 5.5.0 (set up through anaconda) on Linux Mint 21.1 Cinnamon.

Whenever I want to read a file using glob and os (posix) while I have a Console open (because I would like to use the variable explorer) I loose the ability to read a file from my drive (Code see below). When I restart the kernel and I run the code without opening a console, it works just fine. If I then start a console and run the import-cell again, the problem is back. Can anybody reproduce this or is there something not working in my setup?

Code to reproduce:
Cell 1

import geopandas as gpd
import glob
import os

Cell 2

path = ‘…/FOLDER/*.gpkg’ #<-- this needs to point to a folder with gpkg-file on local drive
files = glob.glob(path)
read_file = max(files, key=os.path.getctime)
read_file

Optional Cell 3

gdf=gpd.read_file(read_file)

The error it throws is

Traceback (most recent call last):
Cell In[6], line 3
read_file = max(files, key=os.path.getctime)
ValueError: max() arg is an empty sequence

because files will be empty…

I’ve kind of accepted it for now, but if others have the same issue this could maybe go on github to be fixed in the future?

Just so I’m following fully, can you clarify you are opening the console at that point after you restart the kernel by right-clicking and choosing ‘New Console for Notebook’?

Is that path an absolute or relative path? Have you tried changing to whatever it isn’t and see if ti changes things?

You can test some of the universality of this yourself, perhaps. I’ve tried so far sort of (I didn’t bother involving geopandas) with 7.1.0 and I’m not seeing it but maybe I’m not understanding as of yet.

You can try Jupyter Notebook 7.1.0 by going here and clicking ‘launch binder’.

You can try Jupyter Notebook version 7.0.4 by going here and clicking ‘launch binder’.
Unfortunately, I am not seeing 7.0.6 but you could copy the gist and make one with that version.

Just to clarify: I’m using the notebook as a Spyder-Add-On. I think that has a lot to do with it! Am I even in the right forum here? That’s where I got following the link from inside my Spyder-notebook to github and then to here… :thinking:

To your questions:
It doesn’t matter when exactly I open the console. If it is open, it won’t work.

I start the console using the menu like so:
grafik

The code is a relative one (there should only be two points at the beginning :see_no_evil:). If I use an absolute path it works!

Using binder brings the error message even with the absolute path and without a console - but I think that’s because my path isn’t correct in relation to wherever binder executes the software :worried:

The absolute path working vs. relative is interesting.

Hmmm…if it happens in MyBinder then the issue would belong here in this forum; however, I cannot still tell if that is the case. For the path in my test I used path = ‘.' so it would be where I was making notebooks. I didn’t notice any issue but if you want to use .gpkg stuff that may be different. And it also may mean it is very edge case.

I’d expect it has nothing to do with using gpkg, I have the problem even when I don’t import geopandas.

I don’t get MyBinder to work - specifically: I couldn’t figure out where I need to have things on my local drive in order for it to find stuff :grimacing: I even created a new file, saved it and then did a search for the name - but I couldn’t find it. It doesn’t help that Binder doesn’t have a normal file-open dialog (can’t think of the right term right now)… Also don’t really have time right now to do more testing :frowning:

And as I said: I wouldn’t be surprised if the problem lies in the combination of notebook and spyder.

MyBinder runs on a remote computer. It’s like JupyterHub. You upload your local files to the remote system for it to be able to use them.

For Jupyter Notebook, you initiate upload in the Jupyter Dashboard. When you first click on the Notebook 7.1 link I sent you it start out in the Jupyter Dashboard. There’s an ‘Upload’ button in the upper right side.

In JupyterLab, initiating the upload is as easy as drag-and-drop into the file browser panel on the left side of the JupyterLab interface. That’s why a lot of users prefer the more feature-rich interface.

1 Like