Error: Environment /Users/myuser/.virtualenvs/iron does not contain activation script
Asked Answered
A

9

9

I am running python 3.7.6 on macOS Catalina version 10.15.1 and I am trying to install and set up virtualenvwrapper which I have installed with pip3 install virtualenvwrapper.

I have the following lines in my .bash_profile:

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/Users/maxcarey/Library/Python/3.7/bin/virtualenv
export WORKON_HOME=$HOME/.virtualenvs 
source /Users/maxcarey/Library/Python/3.7/bin/virtualenvwrapper.sh

These are configuration steps I have followed from: https://mcmap.net/q/369758/-terminal-issue-with-virtualenvwrapper-after-mavericks-upgrade. As well as other tutorials (like this one)

So you can see I'm attemping to point these export variables to the right place, in my terminal, the output of which python3 is /usr/local/bin/python3 The output of which virtualenv is: /Users/maxcarey/Library/Python/3.7/bin/virtualenv. The output of which virtualenvwrapper.sh is /Users/maxcarey/Library/Python/3.7/bin/virtualenvwrapper.sh

Here is the problem: when I run: mkvirtualenv iron to create a new virtual environment (called iron in this case), the output of the command is:

created virtual environment in 193ms CPython3Posix(dest=/Users/maxcarey/.virtualenvs/iron, clear=False, global=False) with seeder FromAppData pip=latest setuptools=latest wheel=latest app_data_dir=/Users/maxcarey/Library/Application Support/virtualenv/seed-v1 via=copy virtualenvwrapper.user_scripts creating /Users/maxcarey/.virtualenvs/iron/bin/predeactivate ERROR: Environment '/Users/maxcarey/.virtualenvs/iron' does not contain an activate script.

You can see that a virtual environment is indeed created, however, I get an error saying there is no activation script. However, when I navigate to ~/.virtualenvs, I can indeed see the activation scripts. Here is the output of tree inside the new folder iron/local/:

└── local
    └── bin
        ├── activate
        ├── activate.csh
        ├── activate.fish
        ├── activate.ps1
        ├── activate.xsh
        ├── activate_this.py
        ├── easy_install
        ├── easy_install-3.7
        ├── easy_install3
        ├── pip
        ├── pip-3.7
        ├── pip3
        ├── python -> /Library/Developer/CommandLineTools/usr/bin/python3
        ├── python3 -> python
        ├── python3.7 -> python
        ├── wheel
        ├── wheel-3.7
        └── wheel3

It does indeed appear that there are activation scripts. So I am stumped about why I get the activation script error (which I also get when running workon iron). I have tried simply destroying and recreating the virtual environment with rmvirtualenv iron, which works, however, when creating the environment again I still get the same error. Thank You

Adur answered 16/2, 2020 at 19:1 Comment(0)
L
4

My solution was to add export VIRTUALENVWRAPPER_ENV_BIN_DIR=usr/local/bin to my shell startup file after the virtualenvwrapper.sh script gets called.

I figured out this fix after looking at the source and seeing that it was creating the activate script in usr/local/bin, but the virtualenvwrapper.sh script was looking in just bin for some reason.

My full shell startup config is now this:

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_ENV_BIN_DIR=usr/local/bin
Lyndsaylyndsey answered 24/2, 2020 at 18:28 Comment(0)
D
16

I'm running on a raspbian buster with Python 3.7.3. I ran into the same issue, "ERROR...no activation script". I tried @Lombax answer but it didn't work.

However, I noticed that the version of virtualenvwrapper I had installed was 5.0.0. I checked on PyPi and it's still at version 4.8.4. So I uninstalled virtualenv and virtualenvwrapper: sudo pip3 uninstall virtualenv virtualenvwrapper.

Then I reinstalled both and specified the version: sudo pip3 install virtualenv virtualenvwrapper=='4.8.4' I sourced my .bashrc, in which I had appended the settings:

VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export PATH=/usr/local/bin:$PATH
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

And now mkvirtualenv test works. Not sure what's the bug with version 5.x of virtualenvwrapper, in the meantime, this got around the problem for me, hope this helps.

Defector answered 19/2, 2020 at 2:59 Comment(3)
Hi @simon. Thanks for your response. In my case, I am getting the same activation script error after downgrading. One thing to note is that I am not using sudo to install these packages because then I run into another problem: #33217179Adur
this worked for me with opencv 4.2.0 and raspberry pi 4Fourinhand
worked for me with opencv 3.3 downgraded virtualenvwrapper to 4.8.4Pubilis
N
10

I had the same error message when I used mkvirtualenv on a new RPI4. I added these lines to my .bashrc and it fixed the problem for me:

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_ENV_BIN_DIR=bin  # <== This line fixed it for me

This is a variation of the answer from @maxmcmahon, above, but setting VIRTUALENVWRAPPER_ENV_BIN_DIR to "bin". I did not need to change the versions of either virtualenv or virtualenvwrapper; the current versions installed by default were fine.

Novia answered 1/3, 2020 at 21:24 Comment(3)
This worked but i'm not sure that I understand why...thank you.Polychaete
@Rob, when I got the error, I went to the GitHub and looked at the virtualenvwrapper source code(github.com/bernardobarreto/virtualenvwrapper/blob/master/…). I found the error I was getting in the source code and then searched for where my activation script had been placed. I found where the activate script actually was. I then set VIRTUALENVWRAPPER_ENV_BIN=bin in order to point to it. It had to be a relative reference because the virtualenvwrapper.sh script used it inside a directory specification and a leading / caused 2 //'s in a row which lead to the error.Novia
In my case the bins were located at local/bin instead, so setting VIRTUALENVWRAPPER_ENV_BIN_DIR=local/bin fixed it for me.Flagging
L
4

My solution was to add export VIRTUALENVWRAPPER_ENV_BIN_DIR=usr/local/bin to my shell startup file after the virtualenvwrapper.sh script gets called.

I figured out this fix after looking at the source and seeing that it was creating the activate script in usr/local/bin, but the virtualenvwrapper.sh script was looking in just bin for some reason.

My full shell startup config is now this:

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_ENV_BIN_DIR=usr/local/bin
Lyndsaylyndsey answered 24/2, 2020 at 18:28 Comment(0)
T
3

Assume that you run the mkvirtualenv <your venv name> command and failed.

What you want to do is locating the activate script in your WORKON_HOME path (aka the path to .virtualenv folder). Here go to your new venv folder and find the activate script.

For example, mine is in .virtualenv/<my venv name>/local/bin. Here you would add to your .bashrc file: export VIRTUALENVWRAPPER_ENV_BIN_DIR=local/bin.

Titbit answered 28/8, 2022 at 7:13 Comment(0)
S
1

The error show because the virtual environment which created is not activated.
Don't panic, you just need to activate it by running a particular command.
For me after doing $mkvirtualenv cv -p python3, the virtual env has created, but not been activated.
After the above command you type source /home/pi/.virtualenvs/cv/bin/activate, it will activate the virtual environment variable.
It worked for me.
Now my command line looks like:

(cv) pi@raspberrypi:~ $
Subsume answered 6/4, 2020 at 8:11 Comment(0)
A
0

I was just hitting this, downgrading my virtualenv version to 20.0.3 allowed me to get around the issue.

pip3 uninstall virtualenv && pip3 install 'virtualenv==20.0.3'

Affairs answered 17/2, 2020 at 20:2 Comment(1)
Thanks for your answer, after following your steps still getting exact same issue described above :(Adur
P
0

I would like to comment on maxmcmahon's answer above. The solution seems to NOT be backwards compatible with python3.9. I tested this with homebrew on macOS. Possibly depending on your platform according to https://docs.python.org/3/library/sysconfig.html#sysconfig._get_preferred_schemes which seems to build scripts under usr/local/bin instead of bin as of python 3.10. So one might have to shift the VIRTUALENVWRAPPER_ENV_BIN_DIR variable on and off. I noticed that setting it only in the current shell I could run

mkvirtualenv -p /usr/local/opt/[email protected]/bin/python3 devel3.10

without issues, but when not set I could no longer active devel3.10.

workon devel3.10
ERROR: Environment '~/.virtualenvs/devel3.10' does not contain an activate script.

And when set I can't create another python3.9 venv. It fails with the same error message.

Paradise answered 10/8, 2022 at 13:28 Comment(2)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewImco
You are right that it's not an answer and I'm sorry, it was never meant to be an answer. I don't have reputation to comment and I found no other way to report my findings.Paradise
I
0

It happened with me. Python3.7 to Python3.8 is generating a venv containing a bin directory. But Python3.11 is generating with a local/bin directory.

To fix it I have to run the creation for python3.11 like this:

VIRTUALENVWRAPPER_ENV_BIN_DIR=local/bin mkvirtualenv -p python3.11 my-app

And when creating for other pythons:

VIRTUALENVWRAPPER_ENV_BIN_DIR=bin mkvirtualenv -p python3.7 my-app

Indiscernible answered 27/12, 2022 at 20:37 Comment(0)
T
0

For me

pip install --force-reinstall virtualenvwrapper
. ~/.bashrc

fixed the issue.

Greetings, Peter

Transparency answered 6/12, 2023 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.