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'
2
Answers
This may not be an optimal answer, but for people struggling like I did,for the time being, I propose try another alternative of virtualenv called pyenv, so follow these steps
update the system
install dependencies
install pyenv
configure environment (open the bashrc file via sudo gedit ~/.bashrc and save the following)
after making the changes, run the following command to apply them
verify the install by
install the python version
the above command will install the python 3.10.13 you could use it in your project folder by the command
now we need to install pyenv-virtualenv which is a tool to create virtual environments integrated with pyenv it can be done via https://www.liquidweb.com/kb/how-to-install-pyenv-virtualenv-on-ubuntu-18-04/
then once the Python version is installed, you can create a virtual environment using pyenv-virtualenv by
activate the virtual environment by running
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
:My virtualenv installed under miniconda was giving the error, but using system python worked:
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.