Can't use tkinter in virtual environment created by poetry

See original GitHub issue

Issue

I have several python installations. Using one that I have compiled myself (*Python 3.9.6) with support of latest stable tk/tcl (8.6.11). This python when invoked directly has full support for tkinter library. However, when I create new virtual environment using:

poetry env use /path/to/my/python3.9.6
poetry shell
python -m tkinter

I get the error that python was not configured to use tkinter module.

When I manually add links lib/tcl8.6 and lib/tk8.6 to the virtual environment in ~/.cache/pypoetry/virtualenvs/mleo.../lib/, python can use tkinter afterwards.

I was expecting that poetry would add those links when creating new virtual environment.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
BD103commented, Jan 3, 2022

I too have had this issue. After some testing, it seems fixed with the current version of Poetry. Try reinstalling it. Here are some fixes…

  • I had Poetry 1.1.8 installed and had this error, 1.1.12 fixed it
  • Check your virtualenv’s pyvenv.cfg and look for the virtualenv version.
    • Run poetry env info -p for the path to your virtualenv
    • The virtualenv version should look like virtualenv = 20.*.*
      • 20.7.2 was broken, while 20.10.0 was fixed
  • Ensure that Tkinter worked with other Python versions
    • You may have to rebuild / reinstall your version
    • I ran Python 3.9.6 for both broken and fixed versions

I hope this helped you. I know it is a bit late, but hopefully someone else stumbles upon this and it fixes their issue. 😄

My working version of pyvenv.cfg…

0reactions
rben01commented, Oct 9, 2022

Ok, I tracked this down to poetry seemingly ignoring poetry env use /path/to/python in some cases. That is, you can have the following (pseudo-bash):

$ readlink "$(poetry run which python)"
/path/a/python3.10

$ poetry env use /path/b/python3.10

$ readlink "$(poetry run which python)"
/path/a/python3.10

Perhaps you have to poetry env use /path/to/python before even creating the environment? If so, it’s incredibly misleading that poetry env use is a no-op once the environment has been created.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImportError: No module named 'Tkinter' - Stack Overflow
As you are using Python 3, the module has been renamed to tkinter ... in a virtualenv using for example python 3.7 was...
Read more >
ModuleNotFoundError: No module named 'tkinter' in Python
The Python "ModuleNotFoundError: No module named 'tkinter'" occurs when tkinter is not installed in our Python environment. To solve the error, ...
Read more >
Python - NixOS Wiki
Python 3.3-3.4 (old): the recommended way to create a virtual environment was to use the pyvenv command-line tool that also comes included with...
Read more >
Installation - Streamlit Docs
Below are a few tools you can use for environment management: pipenv · poetry · venv · virtualenv · conda. Install Streamlit on...
Read more >
pipenv · PyPI
You no longer need to use pip and virtualenv separately. They work together. · Managing a requirements. · Hashes are used everywhere, always....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found