question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImportError: cannot import name 'ensure_text'

See original GitHub issue

Apologies I don’t have a completely reproducible environment yet, but since virtualenv==20.0.0 was released 3 hours ago I wanted to get this reported as soon as I could as it likely could affect others.

I’m not 100% certain this is virtualenv’s fault, but I have previous builds that worked and the only major difference between them (and last week) was virtualenv being updated to a new major version.

If submitting a BUG please provide:

Operating System:

  • ubuntu1804 Docker Image on gitlab-runner 12.3.0
  • Python 3.6
  • Running with a tox environment
$ apt-get update && apt-get install -y python3-pip python3-dev apt-rdepends libpq-dev libffi-dev && /usr/bin/python3 -m pip install tox && /usr/bin/python3 -m tox -e job
...
...
932 Collecting tox
933   Downloading https://files.pythonhosted.org/packages/77/a7/a5b721d9bf955edfe36013e5ecc9136fc6b2fef622ab1797ff0560273d8e/tox-3.14.3-py2.py3-none-any.whl (80kB)
934 Collecting virtualenv>=16.0.0 (from tox)
935   Downloading https://files.pythonhosted.org/packages/62/89/72ab7d18e001a23b25eb75ce71bbf9e2a3c142e2dad2e4e2b88012e4ca25/virtualenv-20.0.0-py2.py3-none-any.whl (4.6MB)
936 Collecting importlib-metadata<2,>=0.12; python_version < "3.8" (from tox)
937   Downloading https://files.pythonhosted.org/packages/8b/03/a00d504808808912751e64ccf414be53c29cad620e3de2421135fcae3025/importlib_metadata-1.5.0-py2.py3-none-any.whl
938 Requirement already satisfied: six<2,>=1.0.0 in /usr/lib/python3/dist-packages (from tox)
939 Collecting filelock<4,>=3.0.0 (from tox)
940   Downloading https://files.pythonhosted.org/packages/93/83/71a2ee6158bb9f39a90c0dea1637f81d5eef866e188e1971a1b1ab01a35a/filelock-3.0.12-py3-none-any.whl
941 Collecting toml>=0.9.4 (from tox)
942   Downloading https://files.pythonhosted.org/packages/a2/12/ced7105d2de62fa7c8fb5fce92cc4ce66b57c95fb875e9318dba7f8c5db0/toml-0.10.0-py2.py3-none-any.whl
943 Collecting packaging>=14 (from tox)
944   Downloading https://files.pythonhosted.org/packages/98/42/87c585dd3b113c775e65fd6b8d9d0a43abe1819c471d7af702d4e01e9b20/packaging-20.1-py2.py3-none-any.whl
945 Collecting py<2,>=1.4.17 (from tox)
946   Downloading https://files.pythonhosted.org/packages/99/8d/21e1767c009211a62a8e3067280bfce76e89c9f876180308515942304d2d/py-1.8.1-py2.py3-none-any.whl (83kB)
947 Collecting pluggy<1,>=0.12.0 (from tox)
948   Downloading https://files.pythonhosted.org/packages/a0/28/85c7aa31b80d150b772fbe4a229487bc6644da9ccb7e427dd8cc60cb8a62/pluggy-0.13.1-py2.py3-none-any.whl
949 Collecting importlib-resources<2,>=1.0; python_version < "3.7" (from virtualenv>=16.0.0->tox)
950   Downloading https://files.pythonhosted.org/packages/2f/f7/b4aa02cdd3ee7ebba375969d77c00826aa15c5db84247d23c89522dccbfa/importlib_resources-1.0.2-py2.py3-none-any.whl
951 Collecting appdirs<2,>=1.4.3 (from virtualenv>=16.0.0->tox)
952   Downloading https://files.pythonhosted.org/packages/56/eb/810e700ed1349edde4cbdc1b2a21e28cdf115f9faf263f6bbf8447c1abf3/appdirs-1.4.3-py2.py3-none-any.whl
953 Collecting zipp>=0.5 (from importlib-metadata<2,>=0.12; python_version < "3.8"->tox)
954   Downloading https://files.pythonhosted.org/packages/46/42/f2dd964b2a6b1921b08d661138148c1bcd3f038462a44019416f2342b618/zipp-2.2.0-py36-none-any.whl
955 Collecting pyparsing>=2.0.2 (from packaging>=14->tox)
956   Downloading https://files.pythonhosted.org/packages/5d/bc/1e58593167fade7b544bfe9502a26dc860940a79ab306e651e7f13be68c2/pyparsing-2.4.6-py2.py3-none-any.whl (67kB)
957 Installing collected packages: zipp, importlib-metadata, importlib-resources, appdirs, filelock, virtualenv, toml, pyparsing, packaging, py, pluggy, tox
958 Successfully installed appdirs-1.4.3 filelock-3.0.12 importlib-metadata-1.5.0 importlib-resources-1.0.2 packaging-20.1 pluggy-0.13.1 py-1.8.1 pyparsing-2.4.6 toml-0.10.0 tox-3.14.3 virtualenv-20.0.0 zipp-2.2.0
959 job create: /builds/.tox/job
960 ERROR: invocation failed (exit code 1), logfile: /builds/.tox/job/log/job-0.log
961 ================================== log start ===================================
962 ERROR:root:ImportError: cannot import name 'ensure_text'

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:32 (19 by maintainers)

github_iconTop GitHub Comments

3reactions
asottilecommented, Feb 10, 2020

One fix would be to not depend on ensure_text here – almost all of the cases should use six.text_type(...) anyway

2reactions
ssbarneacommented, Feb 12, 2020

Can we please reopen this bug? The reality is that is perfectly possible to end-up with a newer virtualenv with a six version that is too old.

Here is an example: https://logserver.rdoproject.org/16/24916/5/check/check-centos-8/595187c/job-output.txt

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python pip: ImportError cannot import name 'ensure_str' from ...
I had this problem within my virtual environment when installing from the requirements.txt file that came with the code.
Read more >
ERROR:root:ImportError: cannot import name ensure_text
started returning 'ensure_text' module not found. Here is the related issue: https://github.com/pypa/virtualenv/issues/1551. In order to fix ...
Read more >
Bug #44063: tox: ImportError: cannot import name 'ensure_text'
tox: ImportError: cannot import name 'ensure_text' ; Status: Resolved ; Priority: Urgent ; Assignee: Kefu Chai ; Category: Testing & QA ; Target ......
Read more >
pip 报错- cannot import name 'ensure_text' 的解决办法
ImportError : cannot import name 'ensure_text'原因是出于我自己的一个python3.5的conda环境pip版本比较低正常人的思维是upgred pip 用如下 ...
Read more >
error:root:importerror cannot import name ensure_text - Gankrin
This post is about to see how to fix - Python 'ImportError: cannot import name IncompleteRead' . This occurs while trying to install...
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