Advice on importing python modules: ImportError: cannot import name 'Literal' from 'typing'

Hi! I was wondering if any python aficionados might be able to give me a hand. I’ve been following Matthew Ragan’s great tutorial on using external python libraries. (TD Summit 2019 | External Python Libraries — MIR) I followed along had no problems using the qrcode library shown in the tutorial.

I’m now trying to use a different library: pandas-datareader. I installed it in the same way but I get an error importing it (see screenshot).

I have read that ‘typing.Literal’ is only available in Python 3.8 and up. (https://stackoverflow.com/…/importerror-cannot-import…) so I tried importing it from the ‘typing-extensions’ module. ‘typing_extensions.Literal’ imports fine, but I still run into the error when importing ‘pandas-datareader’.

On the system command line (I’m using Python 3.7.2 to match Touchdesigner’s version), I can import and use ‘pandas-datareader’ without issue (and without needing to import any extra modules)

While researching the issue, I found several other modules that would suit my needs, but they all fail to import with the same error message.

I’m almost out of ideas – any suggestions would be very welcome.

Many thanks!
J.

For a better overview, I’ve pushed the project repo to github https://github.com/jahnertz/touchdesigner-vix-visualiser :slightly_smiling_face:

Hey @jahnertz

It could be some version compatibility issues.

It seems that a dependency of pandas-datareader is panda (pandas-datareader · PyPI), the doc state that the minimum officially supported version is Python 3.8 Installation — pandas 1.5.3 documentation

I have a feeling from your screenshot that you are on MacOS ?

The documentation was recently updated to cover using Homebrew with TouchDesigner: Category:Python - Derivative

Note that if you are on the latest TouchDesigner version (2022.24200, May 25th 2022), the Python version is now 3.9.5.

Best,
Michel

1 Like

Thanks Michel!
Yep — turns out I had last updated touchdesigner a couple of hours before the latest release. Just updating it and the libraries are importing without any issues. It was definitely the Python version being incompatible with the module.

You are correct, I’m on MacOS but I’m using pyenv (installed via homebrew) to install and use different Python versions for different projects.

Cheers!
J.

1 Like