virtualenv "workon" doesn't work

18,946

Solution 1

Since I don't have enough reputation to comment I'll simply attempt an answer as I think I know what the issue is.

Firstly, if you could provide more details as to what you mean by "not working" I will edit my answer if need be and attempt to help more.

Typically this happens because virtualenvwrapper is a shell script that needs to be sourced before you have access to commands like "workon" and "mkvirtualenv". My virtualenvwrapper.sh script is installed in /usr/local/bin so I simply run:

$ source /usr/local/bin/virtualenvwrapper.sh

Typically I add this line to my ~/.bashrc or ~/.profile file to ensure these commands are always available in the shell. You can find more specific information for your setup in the Installation Documentation. Not having it sourced would definitely cause the commands to stop working after a shutdown.

Solution 2

In my case I need to do the following steps (on Mac OS X 10.11):

I added this line:

source "/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh"

to my ~/.bash_profile

And afterwards, following Eric Scrivner instructions, I created a folder at /opt/ called virtual_env using sudo mkdir /opt/virtual_env

And finally, I run the command sudo chown -R youruser /opt/virtual_env

And than: source ~/.bash_profile

Share:
18,946
user3368526
Author by

user3368526

Updated on June 04, 2022

Comments

  • user3368526
    user3368526 almost 2 years

    I made a virtualenv environment for a project. "workon projectname" worked and activated the environment but after I shut down my laptop it starts not working. Could someone tell me how to fix this?

  • user3368526
    user3368526 almost 9 years
    Thanks, Eric! I ran the code "source /usr/local/bin/virtualenvwrapper.sh" but it it gave me the below error. mkdir: /opt/virtual_env/: Permission denied Also, I included the code in .bashrc and .profile. It seems that it didn't work.
  • Eric Scrivner
    Eric Scrivner almost 9 years
    It sounds like you may have created the virtualenv as another user or as root. Let me know if running the following command helps: $ sudo chown -R youruser:youruser /opt/virtual_env
  • user3368526
    user3368526 almost 9 years
    Thanks again :) I ran the command but I got the error below. chown: youruser: illegal group name
  • Eric Scrivner
    Eric Scrivner almost 9 years
    You should replace youruser with your actual username, that was just a placeholder value I used.
  • user3368526
    user3368526 almost 9 years
    Thanks again but I still get illegal group name.. Would you still have other ideas to fix?
  • Eric Scrivner
    Eric Scrivner almost 9 years
    You might just try $ sudo chown -R youruser /opt/virtual_env
  • Sabri Özgür
    Sabri Özgür almost 2 years
    Virtualenwrapper was working earlier for my case but yesterday I've made some additions to .bashrc file to get a project which required pyenv and saw the suspect immediately once I opened the file. pyenv virtualenv-init conflicts with this