Issue
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'
Solution
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
sudo apt update
sudo apt upgrade
install dependencies
sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \ xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
install pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
configure environment (open the bashrc file via sudo gedit ~/.bashrc and save the following)
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
after making the changes, run the following command to apply them
source ~/.bashrc
verify the install by
pyenv --version
install the python version
pyenv install 3.10.13
the above command will install the python 3.10.13 you could use it in your project folder by the command
pyenv local 3.10.13
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
pyenv virtualenv 3.10.13 env_name
activate the virtual environment by running
pyenv activate env_name
Answered By - Avin Mathew Answer Checked By - Pedro (WPSolving Volunteer)