Skip to content

ImportError: cannot import name ensure_file_on_disk #1876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jecummin opened this issue Jun 25, 2020 · 4 comments
Closed

ImportError: cannot import name ensure_file_on_disk #1876

jecummin opened this issue Jun 25, 2020 · 4 comments
Labels

Comments

@jecummin
Copy link

Issue

Originally, when I ran virtualenv test this afternoon I received the error ImportError: No module named via_app_data.via_app_data but after reading through #1875 I decided to uninstall and reinstall virtualenv with pip. Now, when I run virtualenv test I get ImportError: cannot import name ensure_file_on_disk with no other output. Running pip install virtualenv -U will not change the output of virtualenv test. I have even run pip install git+https://github.com/pypa/virtualenv.git@master but the import error persists.

I did some investigation of my own and saw that a pushed commit to this repository's master branch just 5 days ago included both a removal of an import statement including via_app_data.via_app_data and another line importing ensure_file_on_disk. Since version 20.0.25 was released after this commit and my version is up-to-date, I am at a loss as to why virtualenv test fails in this way.

Environment

  • OS: Ubuntu 18.04 (Debian)
  • pip list of the host python where virtualenv is installed:
Package                            Version
---------------------------------- ---------------------
agate                              1.6.1
agate-dbf                          0.2.1
agate-excel                        0.2.3
agate-sql                          0.5.4
antlr                              2.7.5rc1
appdirs                            1.4.4
arrow                              0.12.1
asn1crypto                         0.24.0
attrs                              17.4.0
Babel                              2.8.0
backports.functools-lru-cache      1.5
backports.shutil-get-terminal-size 1.0.0
beautifulsoup4                     4.7.1
blessings                          1.7
blis                               0.2.4
callable-pip                       1.0.0
certifi                            2019.6.16
chardet                            3.0.4
configparser                       4.0.2
contextlib2                        0.6.0.post1
cryptography                       2.1.4
cssselect                          1.0.3
csvkit                             1.0.4
cvxopt                             1.1.9
cycler                             0.10.0
cymem                              2.0.2
cytoolz                            0.9.0.1
dbfread                            2.0.7
decorator                          4.4.1
dill                               0.3.0
distlib                            0.3.0
docopt                             0.6.2
edn-format                         0.6.3
entrypoints                        0.3
enum34                             1.1.6
et-xmlfile                         1.0.1
filelock                           3.0.12
flake8                             3.7.8
funcsigs                           1.0.2
functools32                        3.2.3.post2
future                             0.18.2
fuzzywuzzy                         0.17.0
gmpy                               1.17
google-api-python-client           1.4.2
html5lib                           0.999999999
httplib2                           0.15.0
idna                               2.8
importlib-metadata                 1.6.1
importlib-resources                2.0.1
inquirer                           2.6.3
invoke                             1.2.0
ipaddress                          1.0.17
ipython                            5.5.0
ipython-genutils                   0.2.0
isodate                            0.6.0
jdcal                              1.4.1
joblib                             0.11
keyring                            10.6.0
keyrings.alt                       3.0
leather                            0.3.3
linecache2                         1.0.0
lxml                               4.3.4
matplotlib                         2.1.1
mccabe                             0.6.1
mercurial                          4.5.3
mock                               2.0.0
mpmath                             1.0.0
murmurhash                         0.28.0
mwparserfromhell                   0.5.1
namedentities                      1.9.4
networkx                           2.2
nltk                               3.4.4
nose                               1.3.7
numexpr                            2.6.4
numpy                              1.16.4
oauth2client                       4.1.3
olefile                            0.45.1
openpyxl                           2.6.4
pandas                             0.22.0
parsedatetime                      2.5
pathlib                            1.0.1
pathlib2                           2.3.5
patsy                              0.4.1+dev
pbr                                5.4.5
peewee                             3.9.6
pexpect                            4.2.1
pickleshare                        0.7.4
Pillow                             5.1.0
pip                                20.1.1
plac                               0.9.6
pluggy                             0.6.0
ply                                3.11
preshed                            2.0.1
prompt-toolkit                     1.0.15
psutil                             5.4.2
psycopg2                           2.8.3
py                                 1.5.2
pyasn1                             0.4.8
pyasn1-modules                     0.2.7
pycodestyle                        2.5.0
pycrypto                           2.6.1
pyflakes                           2.1.1
pyglet                             1.3.0
Pygments                           2.2.0
pygobject                          3.26.1
pyparsing                          2.4.6
pyRFC3339                          1.1
pystart                            0.1.13
pytest                             3.3.2
python-dateutil                    2.8.0
python-editor                      1.0.4
python-Levenshtein                 0.12.0
python-slugify                     4.0.0
pytimeparse                        1.1.8
pytz                               2019.3
pyxdg                              0.25
rdflib                             4.2.2
readchar                           2.0.1
redis                              3.2.1
regex                              2019.6.8
requests                           2.22.0
rsa                                4.0
scandir                            1.10.0
scipy                              0.19.1
SecretStorage                      2.3.1
semantic-version                   2.8.4
setuptools                         44.1.0
simplegeneric                      0.8.1
simplejson                         3.13.2
singledispatch                     3.4.0.3
six                                1.15.0
soupsieve                          1.9.5
spacy                              2.1.6
SPARQLWrapper                      1.8.5
SQLAlchemy                         1.3.12
sqlitedict                         1.6.0
srsly                              0.2.0
statsmodels                        0.8.0
stevedore                          1.32.0
subprocess32                       3.2.7
sympy                              1.1.1
tables                             3.4.2
termcolor                          1.1.0
text-unidecode                     1.3
thinc                              7.0.8
toolz                              0.10.0
tqdm                               4.43.0
traceback2                         1.4.0
traitlets                          4.3.2
typing                             3.7.4.1
ujson                              1.35
Unidecode                          1.1.1
unittest2                          1.1.0
uritemplate                        3.0.1
urllib3                            1.25.3
v                                  0.0.0
validate-email                     1.3
virtualenv                         20.0.26.dev1+g02b197e
virtualenv-clone                   0.5.3
virtualenvwrapper                  4.8.4
wasabi                             0.4.2
wcwidth                            0.1.7
webencodings                       0.5
wheel                              0.24.0
Wikidata                           0.6.1
wikiextractor                      0.1
wikipediabase                      0.1.0
wikiscout                          0.1.0
wordnet                            0.0.1b2
wrapt                              1.11.2
xlrd                               1.2.0
xlwt                               0.7.5
xmltodict                          0.10.1
zipp                               1.2.0

Output of the virtual environment creation

Make sure to run the creation with -vvv --with-traceback:

$ virtualenv test -vvv --with-traceback
63 setup logging to NOTSET [DEBUG report:42]
126 find interpreter for spec PythonSpec(path=/usr/bin/python) [INFO builtin:44]
126 proposed PythonInfo({'base_exec_prefix': None, 'system_stdlib': u'/usr/lib/python2.7', 'sysconfig': {u'makefile_filename': u'/usr/lib/python2.7/config-x86_64-linux-gnu/Makefile'}, 'prefix': u'/usr', 'stdout_encoding': u'UTF-8', 'executable': '/usr/bin/python', 'implementation': u'CPython', 'exec_prefix': u'/usr', 'platform': u'linux2', 'version': u'2.7.17 (default, Apr 15 2020, 17:20:14) \n[GCC 7.5.0]', 'sysconfig_paths': {u'platstdlib': u'{platbase}/lib/python{py_version_short}', u'platlib': u'{platbase}/local/lib/python{py_version_short}/dist-packages', u'purelib': u'{base}/local/lib/python{py_version_short}/dist-packages', u'stdlib': u'{base}/lib/python{py_version_short}', u'scripts': u'{base}/local/bin', u'include': u'{base}/local/include/python{py_version_short}', u'data': u'{base}/local'}, 'base_prefix': None, 'system_stdlib_platform': u'/usr/lib/python2.7', 'file_system_encoding': u'UTF-8', 'version_info': VersionInfo(major=2, minor=7, micro=17, releaselevel=u'final', serial=0), 'sysconfig_vars': {u'base': u'/usr', u'platbase': u'/usr', u'PYTHONFRAMEWORK': u'', u'py_version_short': u'2.7'}, 'path': [u'/usr/local/bin', u'/usr/lib/python2.7', u'/usr/lib/python2.7/plat-x86_64-linux-gnu', u'/usr/lib/python2.7/lib-tk', u'/usr/lib/python2.7/lib-old', u'/usr/lib/python2.7/lib-dynload', u'/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages', u'/usr/local/lib/python2.7/dist-packages', u'/usr/local/lib/python2.7/dist-packages/wikiscout-0.1.0-py2.7.egg', u'/usr/local/lib/python2.7/dist-packages/wordnet-0.0.1b2-py2.7.egg', u'/usr/local/lib/python2.7/dist-packages/Wikidata-0.6.1-py2.7.egg', u'/usr/local/lib/python2.7/dist-packages/wikiextractor-0.1-py2.7.egg', u'/usr/local/lib/python2.7/dist-packages/wikipediabase-0.1.0-py2.7.egg', u'/usr/lib/python2.7/dist-packages'], 'max_size': 9223372036854775807, 'has_venv': False, 'real_prefix': None, 'distutils_install': {u'purelib': u'lib/python2.7/site-packages', u'headers': u'include/python2.7/UNKNOWN', u'platlib': u'lib/python2.7/site-packages', u'data': u'', u'scripts': u'bin'}, 'architecture': 64, 'original_executable': u'/usr/bin/python', 'os': u'posix', 'system_executable': u'/usr/bin/python'}) [INFO builtin:50]
126 accepted PythonInfo({'base_exec_prefix': None, 'system_stdlib': u'/usr/lib/python2.7', 'sysconfig': {u'makefile_filename': u'/usr/lib/python2.7/config-x86_64-linux-gnu/Makefile'}, 'prefix': u'/usr', 'stdout_encoding': u'UTF-8', 'executable': '/usr/bin/python', 'implementation': u'CPython', 'exec_prefix': u'/usr', 'platform': u'linux2', 'version': u'2.7.17 (default, Apr 15 2020, 17:20:14) \n[GCC 7.5.0]', 'sysconfig_paths': {u'platstdlib': u'{platbase}/lib/python{py_version_short}', u'platlib': u'{platbase}/local/lib/python{py_version_short}/dist-packages', u'purelib': u'{base}/local/lib/python{py_version_short}/dist-packages', u'stdlib': u'{base}/lib/python{py_version_short}', u'scripts': u'{base}/local/bin', u'include': u'{base}/local/include/python{py_version_short}', u'data': u'{base}/local'}, 'base_prefix': None, 'system_stdlib_platform': u'/usr/lib/python2.7', 'file_system_encoding': u'UTF-8', 'version_info': VersionInfo(major=2, minor=7, micro=17, releaselevel=u'final', serial=0), 'sysconfig_vars': {u'base': u'/usr', u'platbase': u'/usr', u'PYTHONFRAMEWORK': u'', u'py_version_short': u'2.7'}, 'path': [u'/usr/local/bin', u'/usr/lib/python2.7', u'/usr/lib/python2.7/plat-x86_64-linux-gnu', u'/usr/lib/python2.7/lib-tk', u'/usr/lib/python2.7/lib-old', u'/usr/lib/python2.7/lib-dynload', u'/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages', u'/usr/local/lib/python2.7/dist-packages', u'/usr/local/lib/python2.7/dist-packages/wikiscout-0.1.0-py2.7.egg', u'/usr/local/lib/python2.7/dist-packages/wordnet-0.0.1b2-py2.7.egg', u'/usr/local/lib/python2.7/dist-packages/Wikidata-0.6.1-py2.7.egg', u'/usr/local/lib/python2.7/dist-packages/wikiextractor-0.1-py2.7.egg', u'/usr/local/lib/python2.7/dist-packages/wikipediabase-0.1.0-py2.7.egg', u'/usr/lib/python2.7/dist-packages'], 'max_size': 9223372036854775807, 'has_venv': False, 'real_prefix': None, 'distutils_install': {u'purelib': u'lib/python2.7/site-packages', u'headers': u'include/python2.7/UNKNOWN', u'platlib': u'lib/python2.7/site-packages', u'data': u'', u'scripts': u'bin'}, 'architecture': 64, 'original_executable': u'/usr/bin/python', 'os': u'posix', 'system_executable': u'/usr/bin/python'}) [DEBUG builtin:52]
128 filesystem is case-sensitive [DEBUG info:28]
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 11, in <module>
    sys.exit(run_with_catch())
  File "/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages/virtualenv/__main__.py", line 63, in run_with_catch
    run(args, options)
  File "/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages/virtualenv/__main__.py", line 17, in run
    session = cli_run(args, options)
  File "/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages/virtualenv/run/__init__.py", line 24, in cli_run
    session = session_via_cli(args, options)
  File "/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages/virtualenv/run/__init__.py", line 32, in session_via_cli
    parser, elements = build_parser(args, options)
  File "/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages/virtualenv/run/__init__.py", line 60, in build_parser
    SeederSelector(interpreter, parser),
  File "/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages/virtualenv/run/plugin/seeders.py", line 8, in __init__
    possible = self.options("virtualenv.seed")
  File "/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages/virtualenv/run/plugin/base.py", line 39, in options
    cls._OPTIONS = cls.entry_points_for(key)
  File "/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages/virtualenv/run/plugin/base.py", line 18, in entry_points_for
    return OrderedDict((e.name, e.load()) for e in cls.entry_points().get(key, {}))
  File "/usr/lib/python2.7/collections.py", line 69, in __init__
    self.__update(*args, **kwds)
  File "/usr/lib/python2.7/_abcoll.py", line 571, in update
    for key, value in other:
  File "/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages/virtualenv/run/plugin/base.py", line 18, in <genexpr>
    return OrderedDict((e.name, e.load()) for e in cls.entry_points().get(key, {}))
  File "/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages/importlib_metadata/__init__.py", line 96, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages/virtualenv/seed/via_app_data/via_app_data.py", line 11, in <module>
    from virtualenv.seed.embed.wheels.acquire import WheelDownloadFail, get_wheels
  File "/afs/csail.mit.edu/u/j/jecummin/.local/lib/python2.7/site-packages/virtualenv/seed/embed/wheels/acquire.py", line 17, in <module>
    from virtualenv.util.zipapp import ensure_file_on_disk
ImportError: cannot import name ensure_file_on_disk
@jecummin jecummin added the bug label Jun 25, 2020
@EdNoepel
Copy link

Same issue with python 3.6:

$ virtualenv test --with-traceback
Traceback (most recent call last):
  File "/home/ed/.local/bin/virtualenv", line 11, in <module>
    sys.exit(run_with_catch())
  File "/home/ed/.local/lib/python3.6/site-packages/virtualenv/__main__.py", line 63, in run_with_catch
    run(args, options)
  File "/home/ed/.local/lib/python3.6/site-packages/virtualenv/__main__.py", line 17, in run
    session = cli_run(args, options)
  File "/home/ed/.local/lib/python3.6/site-packages/virtualenv/run/__init__.py", line 24, in cli_run
    session = session_via_cli(args, options)
  File "/home/ed/.local/lib/python3.6/site-packages/virtualenv/run/__init__.py", line 32, in session_via_cli
    parser, elements = build_parser(args, options)
  File "/home/ed/.local/lib/python3.6/site-packages/virtualenv/run/__init__.py", line 60, in build_parser
    SeederSelector(interpreter, parser),
  File "/home/ed/.local/lib/python3.6/site-packages/virtualenv/run/plugin/seeders.py", line 8, in __init__
    possible = self.options("virtualenv.seed")
  File "/home/ed/.local/lib/python3.6/site-packages/virtualenv/run/plugin/base.py", line 39, in options
    cls._OPTIONS = cls.entry_points_for(key)
  File "/home/ed/.local/lib/python3.6/site-packages/virtualenv/run/plugin/base.py", line 18, in entry_points_for
    return OrderedDict((e.name, e.load()) for e in cls.entry_points().get(key, {}))
  File "/home/ed/.local/lib/python3.6/site-packages/virtualenv/run/plugin/base.py", line 18, in <genexpr>
    return OrderedDict((e.name, e.load()) for e in cls.entry_points().get(key, {}))
  File "/home/ed/.local/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 96, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ed/.local/lib/python3.6/site-packages/virtualenv/seed/via_app_data/via_app_data.py", line 11, in <module>
    from virtualenv.seed.embed.wheels.acquire import WheelDownloadFail, get_wheels
  File "/home/ed/.local/lib/python3.6/site-packages/virtualenv/seed/embed/wheels/acquire.py", line 17, in <module>
    from virtualenv.util.zipapp import ensure_file_on_disk
ImportError: cannot import name 'ensure_file_on_disk'

@unexploredtest
Copy link

unexploredtest commented Jun 26, 2020

I also have the same issue in linux mint 19.3, python 3.6

Traceback (most recent call last):
  File "/home/alipmpaint/.local/bin/virtualenv", line 11, in <module>
    sys.exit(run_with_catch())
  File "/home/alipmpaint/.local/lib/python3.6/site-packages/virtualenv/__main__.py", line 63, in run_with_catch
    run(args, options)
  File "/home/alipmpaint/.local/lib/python3.6/site-packages/virtualenv/__main__.py", line 17, in run
    session = cli_run(args, options)
  File "/home/alipmpaint/.local/lib/python3.6/site-packages/virtualenv/run/__init__.py", line 24, in cli_run
    session = session_via_cli(args, options)
  File "/home/alipmpaint/.local/lib/python3.6/site-packages/virtualenv/run/__init__.py", line 32, in session_via_cli
    parser, elements = build_parser(args, options)
  File "/home/alipmpaint/.local/lib/python3.6/site-packages/virtualenv/run/__init__.py", line 60, in build_parser
    SeederSelector(interpreter, parser),
  File "/home/alipmpaint/.local/lib/python3.6/site-packages/virtualenv/run/plugin/seeders.py", line 8, in __init__
    possible = self.options("virtualenv.seed")
  File "/home/alipmpaint/.local/lib/python3.6/site-packages/virtualenv/run/plugin/base.py", line 39, in options
    cls._OPTIONS = cls.entry_points_for(key)
  File "/home/alipmpaint/.local/lib/python3.6/site-packages/virtualenv/run/plugin/base.py", line 18, in entry_points_for
    return OrderedDict((e.name, e.load()) for e in cls.entry_points().get(key, {}))
  File "/home/alipmpaint/.local/lib/python3.6/site-packages/virtualenv/run/plugin/base.py", line 18, in <genexpr>
    return OrderedDict((e.name, e.load()) for e in cls.entry_points().get(key, {}))
  File "/home/alipmpaint/.local/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 96, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/alipmpaint/.local/lib/python3.6/site-packages/virtualenv/seed/via_app_data/via_app_data.py", line 11, in <module>
    from virtualenv.seed.embed.wheels.acquire import WheelDownloadFail, get_wheels
  File "/home/alipmpaint/.local/lib/python3.6/site-packages/virtualenv/seed/embed/wheels/acquire.py", line 17, in <module>
    from virtualenv.util.zipapp import ensure_file_on_disk
ImportError: cannot import name 'ensure_file_on_disk

@gaborbernat
Copy link
Contributor

gaborbernat commented Jun 26, 2020

This likely means you have virtualenv installed both under Pythons global site package and user-level (pip install virtualenv and pip install virtualenv --user). And then the two start conflicting with each other. You need to ensure you uninstall from both locations and then install it only in one of them. Alternatively, install it into a virtual environment (e.g. via pipx) to defend against such issues. See https://virtualenv.pypa.io/en/latest/installation.html#via-pipx

PS. In case of such issues, it's helpful to always include how you installed the package, what's the status of the installed packages (both before and after installation), and as final frontier what is the site-packages content both globally and under your user profile. Use python -m site to see a location of all potential installation paths.

@ygorcanalli
Copy link

This likely means you have virtualenv installed both under Pythons global site package and user-level (pip install virtualenv and pip install virtualenv --user). And then the two start conflicting with each other. You need to ensure you uninstall from both locations and then install it only in one of them. Alternatively, install it into a virtual environment (e.g. via pipx) to defend against such issues. See https://virtualenv.pypa.io/en/latest/installation.html#via-pipx

PS. In case of such issues, it's helpful to always include how you installed the package, what's the status of the installed packages (both before and after installation), and as final frontier what is the site-packages content both globally and under your user profile. Use python -m site to see a location of all potential installation paths.

Same issue with Python 3.6.9 on Ubuntu 20.04 (WSL). @gaborbernat solution worked for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants