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.

virtualenv can't be installed as `--user` when an older global installation exists.

See original GitHub issue

Issue

I have the following:

$ virtualenv --version
virtualenv 20.0.18 from /cvmfs/soft.computecanada.ca/easybuild/software/2020/avx2/Core/python/3.8.10/lib/python3.8/site-packages/virtualenv/__init__.py
$ virtualenv
usage: virtualenv [--version] [--with-traceback] [-v | -q] [--app-data APP_DATA] [--clear-app-data] [--discovery {builtin}] [-p py] [--creator {builtin,cpython3-posix,venv}] [--seeder {app-data,pip}] [--no-seed]
                  [--activators comma_sep_list] [--clear] [--system-site-packages] [--symlinks | --copies] [--download | --no-download] [--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip]
                  [--no-setuptools] [--no-wheel] [--symlink-app-data] [--prompt prompt] [-h]
                  dest
virtualenv: error: the following arguments are required: dest

if I now try to upgrade virtualenv in my user account:

$ pip install --user --upgrade virtualenv
Ignoring pip: markers 'python_version < "3"' don't match your environment
Looking in links: /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/avx2, /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/generic, /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/virtualenv-20.13.1+computecanada-py2.py3-none-any.whl
Collecting filelock<4,>=3.2
  Using cached filelock-3.5.0-py3-none-any.whl (10.0 kB)
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/platformdirs-2.5.0+computecanada-py3-none-any.whl
Requirement already satisfied, skipping upgrade: six<2,>=1.9.0 in /cvmfs/soft.computecanada.ca/easybuild/software/2020/avx2/Core/python/3.8.10/lib/python3.8/site-packages (from virtualenv) (1.14.0)
Collecting distlib<1,>=0.3.1
  Using cached distlib-0.3.4-py2.py3-none-any.whl (461 kB)
Installing collected packages: filelock, platformdirs, distlib, virtualenv
Successfully installed distlib-0.3.4 filelock-3.5.0 platformdirs-2.5.0+computecanada virtualenv-20.13.1+computecanada

and then rerun the same:

$ virtualenv --version
virtualenv 20.13.1 from /home/mboisson/.local/lib/python3.8/site-packages/virtualenv/__init__.py
$ virtualenv
ModuleNotFoundError: No module named 'virtualenv.seed.via_app_data'

Environment

Provide at least:

  • OS: irrelevant
$ pip list
Package        Version
-------------- ---------------------
appdirs        1.4.3
distlib        0.3.4
filelock       3.5.0
more-itertools 8.2.0
pip            20.0.2
platformdirs   2.5.0+computecanada
setuptools     45.2.0
setuptools-scm 3.5.0
six            1.14.0
virtualenv     20.13.1+computecanada
wheel          0.34.2

I believe this issue is caused by the switch from importlib_metadata to importlib.metadata in PR https://github.com/pypa/virtualenv/pull/2246

In importlib_metadata’s version of entry_points, there is a step to make the imported entry points unique: https://github.com/python/importlib_metadata/blob/main/importlib_metadata/__init__.py#L995

This ensures that only the highest priority entry_points.txt from virtualenv*.dist_info is considered.

This is also the case in importlib.metadata’s latest version: https://github.com/python/cpython/blob/main/Lib/importlib/metadata/__init__.py

but it was not the case in: Python 3.8: https://github.com/python/cpython/blob/3.8/Lib/importlib/metadata.py#L541 Python 3.9: https://github.com/python/cpython/blob/3.9/Lib/importlib/metadata.py#L569 It was not until Python 3.10 that this was taken up: https://github.com/python/cpython/blob/3.10/Lib/importlib/metadata/__init__.py#L978

I believe importlib_metadata should be used for Python < 3.10.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mboissoncommented, Feb 16, 2022

Not supporting it is simply something not possible in cluster and in shared environments. Having some central packages and some user-packages is common place. This behavior is simply broken for virtualenv. It works for everything else, and it works with python 3.10, so I’m not sure what is the issue.

0reactions
gaborbernatcommented, Feb 16, 2022

Not supporting it is simply something not possible in cluster and in shared environments.

pipx installs content into user space virtual environments, so solves the problem better than the --user flag. I know it’s commonplace but it’s not a good solution to the problem. I rather not add support for something that happens to work now, but is brittle in general.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pip default behavior conflicts with virtualenv? - Stack Overflow
When I got to virtualenv flask command, I received this error message: Can not perform a '--user' install. User site-packages are not visible...
Read more >
PIP not installing to virtualenv directory - Server Fault
It appears that it is trying to install it to the global directory. I do not have sudo privileges. Am I doing something...
Read more >
Manage Python environments and interpreters - Visual Studio ...
Use the Python Environments window to manage global, virtual, and conda environments. Install Python interpreters and packages and assign ...
Read more >
pip install - pip documentation v22.3.1
pip install has several stages: Identify the base requirements. The user supplied arguments are processed here. Resolve dependencies. What will be installed is ......
Read more >
ansible.builtin.pip module – Manages Python library ...
It cannot be specified together with the 'executable' parameter (added in 2.1). If the virtualenv does not exist, it will be created before...
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