15

So, I installed virtualenv in ubuntu terminal. I installed using the following commands:

sudo apt install python3-virtualenv
pip install virtualenv

But when I try creating a new virtualenv using:

virtualenv -p python3 venv

I am getting the following error:

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

How can I solve it?

Phoenix
  • 373
  • 1
  • 4
  • 20

8 Answers8

32

I had a similar experience. The reason for this is that I did it by installing two virtualenv with apt and pip3. This seems to be a known bug (See also here)

Another way a second (or third) instance of virtualenv might have come to your system is via sudo pip install.

So, to be sure you only have one version, you can remove all of them:

pip3 upip3 uninstall virtualenvninstall virtualenv
sudo pip3 uninstall virtualenv
sudo apt purge python3-virtualenv

...and then pick one and re-install it (my preference is userspace pip install virtualenv).

Zak
  • 3,063
  • 3
  • 23
  • 30
daesoo9200
  • 366
  • 1
  • 2
  • 3
  • 2
    I got the error while updating dependencies with poetry. Uninstalling `virtualenv` package that was present in the venv (probably as subdependency of other packages) solved the issue for me. – mattiatantardini May 03 '22 at 13:45
  • This should be the accepted answer. It is the one that actually addresses the problem in the question. – Saul Aryeh Kohn Feb 16 '23 at 15:13
15

You don't need to use virtualenv. You can use this:

python3 -m venv ./some_env
bichanna
  • 954
  • 2
  • 21
4

First off, just one of

sudo apt install python3-virtualenv
pip install virtualenv

should do. You do not need the pip command if the apt installation worked.

Second, you should be able to create one where you can write:

edd@rob:/tmp$ mkdir venvdemo
edd@rob:/tmp$ cd venvdemo/
edd@rob:/tmp/venvdemo$ virtualenv -p python3 venv
created virtual environment CPython3.9.5.final.0-64 in 162ms
  creator CPython3Posix(dest=/tmp/venvdemo/venv, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/edd/.local/share/virtualenv)
    added seed packages: pip==20.3.4, pkg_resources==0.0.0, setuptools==44.1.1, wheel==0.34.2
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
edd@rob:/tmp/venvdemo$ 
edd@rob:/tmp/venvdemo$ ls -a 
.  ..  venv
edd@rob:/tmp/venvdemo$ ls -a venv/
.  ..  bin  .gitignore  lib  pyvenv.cfg
edd@rob:/tmp/venvdemo$ 

(and I did this on an Ubuntu machine).

Third, something is still very wrong because with Ubuntu you should not get an error message for CPython2macOsArmFramework.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
2

There is no need to use virtualenv anymore. Since Python3.3, you can use venv to create virtual environments.

python3 -m venv ./desired_name_of_env
gold_cy
  • 13,648
  • 3
  • 23
  • 45
2

It works for me for recent Ubuntu 22.04 Jammy:

start with installing pip:

sudo apt install python3-pip
sudo apt-get update

Now try installing virtual env:

sudo apt install python3.10-venv

create virtual env:

python3 -m venv venv
Deepanshu Mehta
  • 1,119
  • 12
  • 9
1

I got the same error when creating the environment.

However, I was trying to create it through my WSL Ubuntu 20.04 LST.

After some research, someone in the comment section of this post suggested adding sudo when creating the environment could resolve the issue, which works for me.

sudo virtualenv venv

Now, I am not sure why adding sudo works. My guess is that without superuser permission, WSL cannot create a folder for the local machine.

AsukaMinato
  • 1,017
  • 12
  • 21
Mike Chen
  • 11
  • 2
0

I had a similar problem, use:

sudo virtualenv venv
Freddy Mcloughlan
  • 4,129
  • 1
  • 13
  • 29
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 03 '22 at 18:09
0

I know that many people use venv nowdays but the functionality of just using mkvirtualenv to make a new virtual environment and just using workon to get a list of available envs and working on them has prompted me to stick to virtualenv itself.

What worked for me in my Ubuntu 20.04 LTS:

sudo apt install virtualenv

Don't use pip install virtualenv as it does not automatically set the path.

Create a directory to store all your virtual envs using:

mkdir .virtualenv

Install the virtualenvwrapper using:

pip3 install virtualenvwrapper

Modify your .bashrc file by adding the following commands:

export WORKON_HOME=$HOME/.virtualenvs

export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3

source ~/.local/bin/virtualenvwrapper.sh

Source the .bashrc file using : . ~/.bashrc in your terminal.

Restart your terminal and create a virtual environment using:

mkvirtualenv name-of-env

The environment is activated upon creation and appears as (name-of-environment)user@sys-name:~$

To deactivate the environment just use : deactivate in your terminal.

Now you can access the list of environments using workon and activate them by simply using: workon name-of-environment