When I try to activate a virtual environment with venv I get an error
Asked Answered
B

8

5

I am following this tutorial on how to set up a virtual environment in Python3.6 using the windows command prompt. I had no problem generating the necessary file by running this:

python3 -m venv venv-test

The tutorial then advises to activate the virtual environment by running this code:

venv-test/Scripts/activate

But when I do this , I get the error...

 File "venv-test/Scripts/activate", line 4
    deactivate () {
              ^ SyntaxError: invalid syntax

I opened the generated 'activate' file and this seems to be the part that's causing the problem but I'm not sure how to correct it.

deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
    PATH="${_OLD_VIRTUAL_PATH:-}"
    export PATH
    unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
    PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
    export PYTHONHOME
    unset _OLD_VIRTUAL_PYTHONHOME
fi

Thanks in advance!

Buxtehude answered 12/4, 2018 at 14:35 Comment(2)
Please provide all necessary information in your question. External links may go offline, rendering your question useless to people coming here in the futurePictograph
You got quite a few answers, and you also answered your question yourself. Please don't forget to accept an answer (tick the check-mark next to an answer) if it answers your question. In this way your question stops from showing up as unanswered in the question searches. After a 2-days wait period you can also accept your own answer.Blase
D
6

Try this:

source venv-test/bin/activate

It worked here. Make sure you're in the folder that contains your venv, otherwise just mention its full path.

Demented answered 27/5, 2018 at 6:8 Comment(0)
T
2

I haven't got access to a windows machine at the moment but if I remember correctly you need to run activate.bat and I think you need the full path.

So something like:

C://code/project/venv-test/Scripts/activate.bat
Tyche answered 27/4, 2018 at 0:22 Comment(0)
I
2

On Python 3.8 just go to the folder containing the virtual environment and type

source venv-test\scripts\activate
Imray answered 30/7, 2020 at 6:57 Comment(0)
A
1

The same thing happen to me with one environment, and just adding ./ to the begining of the path solved it. So in your case it would be

./venv-test/Scripts/activate

instead of

venv-test/Scripts/activate
Andalusite answered 7/9, 2023 at 18:51 Comment(1)
This worked for me, I was in the Script folder and "activate" is giving me the OP's error. It's worked with past environments, but not this one. Using ./activate works for some reason, which is a pain, but it'll do for now.Halsted
B
0

not sure the reason why running

venv-test/Scripts/activate

doesn't work but if you go into the directory venv-test/Scripts and THEN type activate it works fine.

Buxtehude answered 13/4, 2018 at 1:14 Comment(0)
B
0

change directory to scripts directory as follows:

cd venv-test/Scripts

and run the activate file by typing

activate 

at the prompt

Bobbibobbie answered 23/7, 2020 at 10:47 Comment(1)
thank you for sharing your information. it seems you are new. please see this link to see how to write a good answer: stackoverflow.com/help/how-to-answerHypabyssal
P
0

you have to run source venv-test/bin/activate not venv-test/Scripts/activate

Pierpont answered 27/6, 2021 at 10:17 Comment(1)
Please explain how your post differs from a copy of the upvoted already existing answer by Luiz Gabriel. I do not see it.Moose
M
0

I had the same problem before, try typing :

venv-test/Scripts/activate.bat,

it worked for me

Martino answered 3/9, 2021 at 11:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.