Forums

Trouble activating an existing virtual environment

So I created a virtual env and it all worked fine:

~/afi (master) $ source virtualenvwrapper.sh
~/afi (master) $ mkvirtualenv --python=/usr/bin/python3.4 venv
Running virtualenv with interpreter /usr/bin/python3.4
<stuff>
Installing setuptools, pip...done.
(venv) $ deactivate
~/afi (master) $ workon venv
(venv)... $ pip install flask
Cleaning up...
(venv)... $ deactivate
~/afi $

Then I closed my Bash console, started a new one, just to make sure I could return later. And here I ran into the problem. I am unable to activate the virtual environment again.

~/afi $ activate
~/afi $ workon venv
~ $ activate
~ $ workon venv

All generate a command like "bash: workon: command not found"

I've read through the help topic

https://www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango

as well as threads 1251 (making a venv with Python 3), 827 (auto activate venv) and 1658 (getting PA to server). Nothing has helped yet.

What am I missing?

Hi there -- just one thing -- you need to run the command source virtualenvwrapper.sh again in any new consoles you create to get access to the workon command.

If you want to skip that, you can make it automatically run in every new console by adding the command to the end of the file .bashrc in your home directory.

It still does not work. I unfortunately closed my bash console and cannot get back to the same environemtn. Was this issue resolved?

What kind of error do you get? Paste it here, please.

Hi pyenthu,

We do already automatically run source virtualenvwrapper.sh for you in your default bashrc. So unless you have changed your bashrc, you should be able to run workon my-virtual-env and have that work.

Another quick way to get back to your virtualenv if you are also using it for your webapp is to click on the "start console in this virtualenv" button form your webapp page.

I muddled through it and gave up. Made the virtual envirponment all over again. It is working now. Added the source virtualenvwrapper.sh to my .bashrc file and it seems to be working now.

             / ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄\    
<<<<<<:>~  <   Yay!          |   
             \_________/

Thanks a lot conrad.

When I try to switch environments within a script it fails

source virtualenvwrapper.sh
workon dev

What is the error that you are getting?