3

I have created a python3 virtual environment "test" inside "~/.virtualenvs" using virualenv. But, I got the following error when I tried to activate.

bash: /home/ubuntu/.virtualenvs/test/bin/activate: line 4: syntax error near unexpected token `(' 
bash: /home/ubuntu/.virtualenvs/test/bin/activate: line 4: `deactivate () {'

I tried to use virtualenv on ubuntu container and cloud9 ide also but got the same error.

picklu
  • 875
  • 11
  • 21
  • we need to see the code inside virtualenvs – John Joe Mar 23 '17 at 01:42
  • What was the exact command line you ran to activate it? This seems like incorrect activation, if anything, or possibly sourcing the wrong script for your shell (though `activate` should match `bash`). – ShadowRanger Mar 23 '17 at 01:50
  • I run the following command: source ~/.virtualenvs/test/bin/activate – picklu Mar 23 '17 at 01:57
  • Here is the command and corresponding output to create "test" environment: $ virtualenv ~/.virtualenvs/test Using base prefix '/usr' New python executable in /home/ubuntu/.virtualenvs/test/bin/python3 Also creating executable in /home/ubuntu/.virtualenvs/test/bin/python Installing setuptools, pip, wheel...done. – picklu Mar 23 '17 at 02:20
  • @ShadowRanger, It works if I run ` source /home/ubuntu/.virtualenvs/test/bin/activate` from root. – picklu Mar 23 '17 at 02:34
  • Hi @ShadowRanger and @John Joe, I have figured out that the cause of the problem was in my .bash_alias file. There was an alias "deactivate" that I created long before to deactivate conda environment but I forgot that. And in all my ubuntu containers and pcs I used the same ~.bash_alias file. After deleting that from the .bash_alias file the command `source ~/.virtualenvs/test/bin/activate` works fine. I am extremely sorry for wasting your time. Thanks. – picklu Mar 23 '17 at 07:55

2 Answers2

2

It seems, the question is being viewed frequently. Even though I put a comment regarding the solution, I think, it is better to answer here. I have figured out that the cause of the problem was in my ~.bash_alias file. There was an alias "deactivate" that I created long before to deactivate conda environment but I forgot that. And in all my ubuntu containers and pcs I used the same ~.bash_alias file. After deleting that from the ~.bash_alias file the command source ~/.virtualenvs/test/bin/activate worked fine.

picklu
  • 875
  • 11
  • 21
1

Maybe you have an alias in your .bashrc file, that's why bash takes deactivate like a command, not like a function

instead

deactivate() {

use this

function deactivate() {
Glassy
  • 39
  • 4