[Django]-Can't "activate" virtualenv

11👍

There’s a lot of confusing information out there on virtual environments, because of how they have evolved. Since Python 3.3, the venv module is available with Python as part of the standard library to create virtual environments, and if you’re just getting started, I’d recommend learning it first. There’s nothing extra to install after you’ve installed Python 3.8.

From your project’s home directory in the VSCode terminal, try this:

python3 -m venv venv
. venv/bin/activate
pip install Django

Here’s what the three lines do:

  1. Call the Python module venv and create a new virtual environment in the directory venv
  2. Run the script to activate the virtual environment that is located in the path venv/bin/activate
  3. Now that the venv is activated, install Django.

After the first time install, you’ll just need to repeat step (2) to activate it. You can also point VSCode to automatically start it when you fire up the IDE. You can click the bar at the bottom of VSCode after installing the Python plugin to select the Python version in the venv you’ve created. Good luck!

Update:

Here’s an example of it working in zsh on my machine:

$ zsh
% python3 --version
Python 3.8.2
% python3 -m venv venv
% . venv/bin/activate
(venv) % pip install Django
Collecting Django
Collecting pytz (from Django)
Collecting asgiref~=3.2.10 (from Django)
Collecting sqlparse>=0.2.2 (from Django)
Installing collected packages: pytz, asgiref, sqlparse, Django
Successfully installed Django-3.1.1 asgiref-3.2.10 pytz-2020.1 sqlparse-0.3.1

3👍

I was stuck on this for a good while
but you can try venv:

python -m venv virtualenvname

#to activate the virtual environment

source virtualenvname/Scripts/activate

2👍

Solution of the problem of virtual environment created but not activated.

to make activate just add a space between .(dot) and your venv path. i,e $ . yourvirtualenv/bin/activate Hope this will work. But not use like: $ yourvirtualenv/bin/activate or $ /yourvirtualenv/bin/activate Here is my command and the output: admin@osboxes:~/pysrc$ . my_env/bin/activate (my_env) admin@osboxes:~/pysrc$
Output of the wrong command: admin@osboxes:~/pysrc$ my_env/bin/activate bash: my_env/bin/activate: Permission denied admin@osboxes:~/pysrc$ sudo my_env/bin/activate [sudo] password for admin: sudo: my_env/bin/activate: command not found admin@osboxes:~/pysrc$ my_env/bin/activate bash: my_env/bin/activate: Permission denied admin@osboxes:~/pysrc$

1👍

Navigate to your venv folder. You will find pyvenv.cfg

With

sudo change set parameter "include-system-site-package" = "true" 

and then execute your

source venv/bin/activate

0👍

I just prefer using ‘venv’ as a name for all my virtual environments, so always I’ll use the same command to activate environments in my machine.

Try:

# Create the virtual environment inside your project's folder
$ python3 -m venv venv

#Activate it
$ source venv/bin/activate

As I need to change projects and environments quite often, I created two alias in the system (ubuntu 20.04), one for creating and another to activate it, as shown above:

To create I chose ‘venv’ as my alias name. Before creating I certified that an existing ‘venv’ folder was deleted.

venv='rm -rf venv && python3.9 -m venv venv'

To activate I chose ‘activate’ as my alias name

activate='source venv/bin/activate'

Window commands to create and activate are a little different as you can notice in this answer.

0👍

I had the same problem. It came right out of nowhere. To keep it simple please use source for running the activate script. In Linux e.g.

source .virtualenvs/test/bin/activate

I don’t know why but these became crucial.

Code up Donald

0👍

this works for me
cd to your folder with .bin folder
activate – . bin/activate

Leave a comment