skip to Main Content

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


  1. Chosen as BEST ANSWER

    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
    

  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search