Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'virtualenv.create.via_global_ref.builtin.cpython.mac_os' has no attribute 'CPython2macOsArmFramework'

I was trying to configure pre-commit hooks and while running pre-commit run --all-files I got this error:

[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/Users/dark_matter88/opt/anaconda3/bin/python3.8', '-mvirtualenv', '/Users/dark_matter88/.cache/pre-commit/repojfgkwtv7/py_env-python3.8')
return code: 1
stdout:
    AttributeError: module 'virtualenv.create.via_global_ref.builtin.cpython.mac_os' has no attribute 'CPython2macOsArmFramework'

I've tried to upgrade pip to resolve this issue pip install --upgrade pip and I received another error:

Traceback (most recent call last):
  File "/Users/admin/opt/anaconda3/bin/pip", line 5, in <module>
    from pip._internal.cli.main import main
  File "/Users/admin/.local/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 9, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/Users/admin/.local/lib/python3.8/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/Users/admin/.local/lib/python3.8/site-packages/pip/_internal/cli/main_parser.py", line 9, in <module>
    from pip._internal.build_env import get_runnable_pip
  File "/Users/admin/.local/lib/python3.8/site-packages/pip/_internal/build_env.py", line 15, in <module>
    from pip._vendor.packaging.requirements import Requirement
ModuleNotFoundError: No module named 'pip._vendor.packaging'

I tried to check versions of both pip and pip3, and now I'm also getting the same No module named 'pip._vendor.packaging' error. I've tried all the solutions I could find, but nothing's helped. I'm thinking if it's related to having several versions of python installed.

like image 414
dark_matter88 Avatar asked Mar 29 '26 01:03

dark_matter88


2 Answers

For me on Debian after a OS upgrade, the global python3-virtualenv package had been installed, which was causing the same issue:

$ pipenv install
Creating a virtualenv for this project...
Pipfile: /tmp/test/Pipfile
Using default python from /usr/bin/python3 (3.9.2) to create virtualenv...
⠹ Creating virtual environment...AttributeError: module 'virtualenv.create.via_global_ref.builtin.cpython.mac_os' has no attribute 'CPython2macOsFramework'

✘ Failed creating virtual environment
[pipenv.exceptions.VirtualenvCreationException]: 

After a sudo apt remove python3-virtualenv and python3 -m pip install -U virtualenv pipenv error was gone for me.

like image 183
Sean Breckenridge Avatar answered Mar 31 '26 04:03

Sean Breckenridge


Got the same error on Python 3.9.2 and virtualenv==20.23.0.

▶ virtualenv   
AttributeError: module 'virtualenv.create.via_global_ref.builtin.cpython.mac_os' has no attribute 'CPython2macOsFramework'
▶ virtualenv --version
virtualenv 20.23.0 from ~/.local/lib/python3.9/site-packages/virtualenv/__init__.py

For some reason, after I uninstalled virtualenv with pip uninstall virtualenv -y, the server also had v20.4.0 still installed and this version worked without the error. I assume the v20.4.0 is a global package for all users of our server, the v20.23.0 was probably installed with the --user flag.

▶ virtualenv --version    
/usr/local/lib/python3.9/dist-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
virtualenv 20.4.0+ds from /usr/lib/python3/dist-packages/virtualenv/__init__.py
▶ virtualenv              
/usr/local/lib/python3.9/dist-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
usage: virtualenv [--version] [--with-traceback] [-v | -q] [--read-only-app-data] [--app-data APP_DATA] [--reset-app-data] [--upgrade-embed-wheels] [--discovery {builtin}] [-p py] [--try-first-with py_exe]
                  [--creator {builtin,cpython3-posix,venv}] [--seeder {app-data,pip}] [--no-seed] [--activators comma_sep_list] [--clear] [--no-vcs-ignore] [--system-site-packages] [--symlinks | --copies] [--no-download | --download]
                  [--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip] [--no-setuptools] [--no-wheel] [--no-periodic-update] [--symlink-app-data] [--prompt prompt] [-h]
                  dest
virtualenv: error: the following arguments are required: dest
SystemExit: 2
▶ git commit -v
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /home/user/<user>/.cache/pre-commit/patch1684867373-780959.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
like image 21
dvdblk Avatar answered Mar 31 '26 05:03

dvdblk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!