poetry: poetry env use python3.7 gives error No module named 'virtualenv.seed.via_app_data'

Hi,

I found issue on poetry 1.0.10 when I run poetry env use python3.7 as follows:

Traceback (most recent call last): File “<stdin>”, line 1, in <module> NameError: name ‘PosixPath’ is not defined

So I tried to upgrade to poetry preview version by:

poetry self update --preview ∞ Updating to 1.1.0b4

  • Downloading poetry-1.1.0b4-darwin.tar.gz 100%

Then I tried to execute poetry env use python3.7, now I am getting a different error:

ModuleNotFoundError

No module named ‘virtualenv.seed.via_app_data’

at <frozen importlib._bootstrap>:973 in _find_and_load_unlocked

  • OS version and name: MacOS Mojave
  • Poetry version: 1.1.0b4

Any help is really appreciated. Please let me know if anymore information is needed.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 11
  • Comments: 34 (6 by maintainers)

Most upvoted comments

Well no, I finally found out: when installing via pip after having deleted /usr/local/bin/virtualenv, it just kept using the wrong libraries. What I had to do was sudo apt remove --purge python3-virtualenv virtualenv, and then install virtualenv via pip3.

I did not actually installed these packages myself, they were installed as dependencies of tox and nothing else. So actually what I did was to remove tox from the apt installed packages list, and did sudo pip3 install tox tox-pyenv.

So, @demangejeremy I don’t know how it is with your MacOS / Anaconda platform, but it would be an incredible coincidence to get exactly the same problem at the same time but from a totally different cause. I’d suggest you to not give up and hunt for packages like python3-virtualenv and virtualenv (maybe the names on MacOS differ from the ones on Ubuntu) that would have been installed by your package manager (maybe as dependencies), remove them and replace them by pip3 installed ones.

sudo apt remove --purge python3-virtualenv virtualenv

I can confirm that deleting virtualenv installed via apt on Ubuntu 20.04.1 LTS by doing sudo apt remove --purge python3-virtualenv virtualenv and then installing virtualenv via pip by doing pip install -U virtualenv results in the virtualenv.seed.via_app_data error disappearing and poetry install behaving normally.

pip install -U virtualenv works

@zoopp Please try this steps.

If you installed virtualenv with a package manager something different than PIP (like brew,apt,yum, etc.)

  • Find it and delete it
  • You can locate it via which virtualenv
  • If you are unable to delete it, try installing your current version from pip

had the same issue on ubuntu 20.04 LTS via wsl2, I also have a few package managers that I use so I wondered if that caused an issue, but I had the same issue in docker.

$ sudo apt remove --purge python3-virtualenv did the trick, cheers my man!

@ycd Your suggestion fixes the issue in my case, thank you! I see I should have read the previous comments more carefully. 😅

I didn’t have a global version of virtualenv installed. However, a fresh install of it worked: pip install --force-reinstall virtualenv

I also had this issue, or a variant of it.

Installed poetry

Used poetry lockfor one app and everything worked fine

Used poetry lock for a second app and received the following error message:

$ poetry lock      
Creating virtualenv mytestapp-vm7OCEgV-py3.8 in /home/alexb7217/.cache/pypoetry/virtualenvs

  ModuleNotFoundError

  No module named 'virtualenv.seed.via_app_data'

  at <frozen importlib._bootstrap>:973 in _find_and_load_unlocked

Followed the most simple suggestion:

$ sudo apt remove --purge python3-virtualenv

Re-ran poetry-lock

$ poetry lock  
Updating dependenciesResolving dependencies... (1.1s)

Everything works great, that’s it! :👍:

OS: Ubuntu 20.04.1 LTS x86_64

I was experiencing this with 3.6 in pyenv, on Ubuntu 18.04 in WSL, and upgrading virtualenv worked for me.

$ pyenv local 3.6.10
$ poetry env use $(which python)
  ModuleNotFoundError

  No module named 'virtualenv.seed.via_app_data'

  at <frozen importlib._bootstrap>:953 in _find_and_load_unlocked

$ python -m pip install -U virtualenv
$ python -m virtualenv --version
virtualenv 20.0.21 from ~/.local/lib/python3.6/site-packages/virtualenv/__init__.py
$ python -m pip install -U virtualenv
Successfully installed virtualenv-20.2.2
$ poetry env use $(pyenv which python)
--success!--

For some reason, it was enough to just uninstall python3-virtualenv using system package manager and the error disappeared (I’m on Ubuntu).

Like @abn mentioned(In that issue you can see my comment from Jul 15) it’s a problem with virtualenv more specifically if you have two virtualenv installed (In my case i installed one with APT, and one with PIP) that’s causing the error.

@FelixKJose looks like your original issue is an upstream issue with virtualenv, see https://github.com/pypa/virtualenv/issues/1873

I’m on an arch-based system, I had to do the opposite of what was suggested above.

For me, I had to install python-poetry and python-virtualenv through pacman and uninstall the poetry I installed via the shell script and/or pip.

I experience this issue with Python 3.8.5 as well (when running poetry install). I’ll attach the stack trace in case it’s relevant:

 Stack trace:

  23  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/console_application.py:131 in run
       129│             parsed_args = resolved_command.args
       130│ 
     → 131│             status_code = command.handle(parsed_args, io)
       132│         except KeyboardInterrupt:
       133│             status_code = 1

  22  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/command/command.py:120 in handle
       118│     def handle(self, args, io):  # type: (Args, IO) -> int
       119│         try:
     → 120│             status_code = self._do_handle(args, io)
       121│         except KeyboardInterrupt:
       122│             if io.is_debug():

  21  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/command/command.py:163 in _do_handle
       161│         if self._dispatcher and self._dispatcher.has_listeners(PRE_HANDLE):
       162│             event = PreHandleEvent(args, io, self)
     → 163│             self._dispatcher.dispatch(PRE_HANDLE, event)
       164│ 
       165│             if event.is_handled():

  20  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/event/event_dispatcher.py:22 in dispatch
        20│ 
        21│         if listeners:
     →  22│             self._do_dispatch(listeners, event_name, event)
        23│ 
        24│         return event

  19  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/event/event_dispatcher.py:89 in _do_dispatch
        87│                 break
        88│ 
     →  89│             listener(event, event_name, self)
        90│ 
        91│     def _sort_listeners(self, event_name):  # type: (str) -> None

  18  ~/.poetry/lib/poetry/console/config/application_config.py:119 in set_env
       117│ 
       118│         env_manager = EnvManager(poetry)
     → 119│         env = env_manager.create_venv(io)
       120│ 
       121│         if env.is_venv() and io.is_verbose():

  17  ~/.poetry/lib/poetry/utils/env.py:645 in create_venv
        643│             )
        644│ 
     →  645│             self.build_venv(venv, executable=executable)
        646│         else:
        647│             if force:

  16  ~/.poetry/lib/poetry/utils/env.py:686 in build_venv
        684│         if isinstance(executable, Path):
        685│             executable = executable.resolve().as_posix()
     →  686│         return virtualenv.cli_run(
        687│             [
        688│                 "--no-download",

  15  ~/.poetry/lib/poetry/_vendor/py3.8/virtualenv/run/__init__.py:26 in cli_run
        24│     :return: the session object of the creation (its structure for now is experimental and might change on short notice)
        25│     """
     →  26│     of_session = session_via_cli(args, options, setup_logging)
        27│     with of_session:
        28│         of_session.run()

  14  ~/.poetry/lib/poetry/_vendor/py3.8/virtualenv/run/__init__.py:42 in session_via_cli
        40│     :return: the session object of the creation (its structure for now is experimental and might change on short notice)
        41│     """
     →  42│     parser, elements = build_parser(args, options, setup_logging)
        43│     options = parser.parse_args(args)
        44│     creator, seeder, activators = tuple(e.create(options) for e in elements)  # create types

  13  ~/.poetry/lib/poetry/_vendor/py3.8/virtualenv/run/__init__.py:69 in build_parser
        67│     elements = [
        68│         CreatorSelector(interpreter, parser),
     →  69│         SeederSelector(interpreter, parser),
        70│         ActivationSelector(interpreter, parser),
        71│     ]

  12  ~/.poetry/lib/poetry/_vendor/py3.8/virtualenv/run/plugin/seeders.py:8 in __init__
        6│ class SeederSelector(ComponentBuilder):
        7│     def __init__(self, interpreter, parser):
     →  8│         possible = self.options("virtualenv.seed")
        9│         super(SeederSelector, self).__init__(interpreter, parser, "seeder", possible)
       10│ 

  11  ~/.poetry/lib/poetry/_vendor/py3.8/virtualenv/run/plugin/base.py:39 in options
       37│     def options(cls, key):
       38│         if cls._OPTIONS is None:
     → 39│             cls._OPTIONS = cls.entry_points_for(key)
       40│         return cls._OPTIONS
       41│ 

  10  ~/.poetry/lib/poetry/_vendor/py3.8/virtualenv/run/plugin/base.py:18 in entry_points_for
       16│     @classmethod
       17│     def entry_points_for(cls, key):
     → 18│         return OrderedDict((e.name, e.load()) for e in cls.entry_points().get(key, {}))
       19│ 
       20│     @staticmethod

   9  ~/.poetry/lib/poetry/_vendor/py3.8/virtualenv/run/plugin/base.py:18 in <genexpr>
       16│     @classmethod
       17│     def entry_points_for(cls, key):
     → 18│         return OrderedDict((e.name, e.load()) for e in cls.entry_points().get(key, {}))
       19│ 
       20│     @staticmethod

   8  /usr/lib/python3.8/importlib/metadata.py:77 in load
        75│         """
        76│         match = self.pattern.match(self.value)
     →  77│         module = import_module(match.group('module'))
        78│         attrs = filter(None, (match.group('attr') or '').split('.'))
        79│         return functools.reduce(getattr, attrs, module)

   7  /usr/lib/python3.8/importlib/__init__.py:127 in import_module
       125│                 break
       126│             level += 1
     → 127│     return _bootstrap._gcd_import(name[level:], package, level)
       128│ 
       129│ 

   6  <frozen importlib._bootstrap>:1014 in _gcd_import

   5  <frozen importlib._bootstrap>:991 in _find_and_load

   4  <frozen importlib._bootstrap>:961 in _find_and_load_unlocked

   3  <frozen importlib._bootstrap>:219 in _call_with_frames_removed

   2  <frozen importlib._bootstrap>:1014 in _gcd_import

   1  <frozen importlib._bootstrap>:991 in _find_and_load

  ModuleNotFoundError

  No module named 'virtualenv.seed.via_app_data'

  at <frozen importlib._bootstrap>:973 in _find_and_load_unlocked

I’ve been iterating stable release versions backwards starting from v1.1.2 and the latest one in which this doesn’t happen is 1.0.10.

@FelixKJose can you run that with -vvv and provide the stack trace please?

@mbelang the loop could when the project was locked using 1.1 and you are attempting to install the project using 1.0.