Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am running Ubuntu 20.04.6 LTS and wanted to create a project with python3.10, so I installed the python using the deadsnakes PPA, it works fine

$ python3.10 Python 3.10.13 (main, Aug 25 2023, 13:20:03) [GCC 9.4.0] on linux Type 
"help", "copyright", "credits" or "license" for more information.
>>>

but when I try to create a virtualenv using the command

$ virtualenv -p python3.10 test_env

I get the error

AttributeError: module 'virtualenv.create.via_global_ref.builtin.cpython.mac_os' has no attribute 'CPython3macOsBrew'
like image 226
Avin Mathew Avatar asked Sep 07 '25 17:09

Avin Mathew


2 Answers

Had this error message show up in PyCharm while trying to build venv's for my project.

I rolled back virtualenv in my local Python3.9.1 install to version 20.23.0, then restarted PyCharm which fixed my problem.

pip uninstall virtualenv

pip install virtualenv==20.23.0

like image 156
Aaron Wright Avatar answered Sep 10 '25 06:09

Aaron Wright


UPDATED ANSWER 2023-09-26:

It happened again. But, I was able to resolve the problem much more easily as follows:

pip uninstall virtualenv
pip install virtualenv

Original answer follows:


I'm hitting this error too, albeit actually on Mac OS.

Some searching turned up some similar issues (different missing attribute, however) in this github issue.

I'm working under the assumption it's a broken install of virtualenv:

~$ ~/miniconda3/envs/ManyFEWS/bin/python3.9 -mvirtualenv

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

My virtualenv installed under miniconda was giving the error, but using system python worked:

~$ /usr/bin/python3 -mvirtualenv

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-mac-framework,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

virtualenv was perfectly happy in my Conda base environment too.

So, I wiped out my miniconda install and reinstalled, and didn't have the error any more. Musing on a root cause, I wonder if it was because I've been using PyCharm with that environment. Something's been altered by something. Apologies that I can't be more specific!

I appreciate there's several differences in your setup (using a ppa instead of miniconda, as in my case), but I'd encourage you to look at your install.

Instead of using a PPA, could you use a tool like miniconda to manage your environments? This did make it a lot easier for me to wipe mine out and try different things to resolve the error.

like image 21
Sam Finnigan Avatar answered Sep 10 '25 08:09

Sam Finnigan