Skip to content

Conversation

@remlapmot
Copy link
Contributor

@remlapmot remlapmot commented Oct 24, 2025

Hi Tim

I have had a go at this.

I used your ChatGPT suggestions.

I have tested on the most recent versions of Python 3.10, 3.11, 3.12, and 3.13 and they all pass nbdev_test (as you can see from the GitHub Actions workflow I've amended) and a quarto render of a test Quarto document.

However, I have a mysterious problem. When I run this under the recently released Python 3.14.0 I obtain some sort of problem originating from within Stata's pystata. Weirdly nbdev_test passes. But when I run a test quarto render the kernel hangs at the first Stata chunk. To see more I converted my test qmd file to a Jupyter notebook.

First create a UV virtual environment with Python 3.14.0 and activate it

uv venv --python 3.14.0
source .venv/bin/activate

Then add the packages in the pyproject.toml and nbstata

uv sync

Install the kernel

python -m nbstata.install

Then this will hang, where my test.qmd is simply

---
jupyter: nbstata
format:
  html:
    embed-resources: true
---

```{stata}
about
```

```{stata}
twoway function x^2
```
quarto render test.qmd

Kill that with Ctrl+C and convert qmd file to ipynb

quarto convert test.qmd

Then open the ipynb in JupyerLab

jupyter lab test.ipynb

Then executing a stata chunk, the error I obtain is:

[I 2025-10-24 19:55:21.654 ServerApp] Connecting to kernel bbee13b3-64d2-4006-baf2-5ade854c5cbb.
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
  File "/Users/tom/Documents/GitHub/nbstata/.venv/lib/python3.14/site-packages/ipykernel/kernelbase.py", line 469, in dispatch_shell
    await result
  File "/Users/tom/Documents/GitHub/nbstata/.venv/lib/python3.14/site-packages/ipykernel/ipkernel.py", line 379, in execute_request
    await super().execute_request(stream, ident, parent)
  File "/Users/tom/Documents/GitHub/nbstata/.venv/lib/python3.14/site-packages/ipykernel/kernelbase.py", line 896, in execute_request
    reply_content = self.do_execute(**do_execute_args)
  File "/Users/tom/Documents/GitHub/nbstata/nbstata/kernel.py", line 166, in do_execute
    code_cell.run()
    ~~~~~~~~~~~~~^^
  File "/Users/tom/Documents/GitHub/nbstata/nbstata/cell.py", line 29, in run
    self.stata_session.dispatch_run(self.code,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
        quietly=self.quietly, echo=self.echo, noecho=self.noecho)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tom/Documents/GitHub/nbstata/nbstata/stata_session.py", line 185, in dispatch_run
    run_noecho(code, self.sc_delimiter, run_as_prog=self._run_as_program_w_locals)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tom/Documents/GitHub/nbstata/nbstata/noecho.py", line 88, in run_noecho
    run_non_prog_noecho(block['std_code'], run_as_prog=run_as_prog)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tom/Documents/GitHub/nbstata/nbstata/noecho.py", line 65, in run_non_prog_noecho
    run_direct(valid_single_line_code(std_non_prog_code),
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
               quietly=False, inline=True, echo=False)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tom/Documents/GitHub/nbstata/nbstata/stata.py", line 68, in run_direct
    return pystata.stata.run(cmds, quietly, echo, inline)
           ^^^^^^^^^^^^^
AttributeError: module 'pystata' has no attribute 'stata'

Would you have any ideas? I might ask StataCorp. Tech Support about it.

Anyway even if you don't take this, maybe a useful starting place for your own commits.

Closes #58

Closes #65 (because it includes those commits)

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@remlapmot remlapmot changed the title Attempt to eplace pkg_resources uses, generally bump to Python 3.10+ maintenance Fixes to DeprecationWarning's and the like Attempt to replace pkg_resources uses, generally bump to Python 3.10+ maintenance etc. Oct 24, 2025
@hugetim
Copy link
Owner

hugetim commented Oct 28, 2025

Thank you! I've been delayed on reviewing but maybe by the end of this week.

@remlapmot
Copy link
Contributor Author

I've been trying to think about the reason for the problem on Python 3.14. My best guess is that it's some problem to do with the filenames being the same, i.e. stata.py in nbstata trying to import something from stata.py in pystata. But so far I don't know how to fix.

Also I wasn't sure if I needed to add corresponding notebooks for the new _resources.py and _version_helper.py files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace pkg_resources uses, generally bump to Python 3.10+

2 participants