Majid Rajabi
Majid Rajabi

Reputation: 1775

add environment variables to activate file in a virtualenv for a Django project

I recently clone a django project and in the README file said that :

Edit .venv/bin/activate and add this environment variables.

::

  export DJANGO_SETTINGS_MODULE="thissite.settings.development"
  export LD_LIBRARY_PATH=/usr/local/lib
  export LC_ALL='en_US.UTF-8'
  export LANG='en_US.UTF-8'

So i built this virtual env and in this step should i just simply copy and past this environment variables to the activate file(where exactly?) or what?

The activate file :

# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly

deactivate () {
unset -f pydoc >/dev/null 2>&1

# reset old environment variables
# ! [ -z ${VAR+_} ] returns true if VAR is declared at all
if ! [ -z "${_OLD_VIRTUAL_PATH+_}" ] ; then
    PATH="$_OLD_VIRTUAL_PATH"
    export PATH
    unset _OLD_VIRTUAL_PATH
fi
if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+_}" ] ; then
    PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
    export PYTHONHOME
    unset _OLD_VIRTUAL_PYTHONHOME
fi

if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
    hash -r 2>/dev/null
fi

if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then
    PS1="$_OLD_VIRTUAL_PS1"
    export PS1
    unset _OLD_VIRTUAL_PS1
fi

unset VIRTUAL_ENV
if [ ! "${1-}" = "nondestructive" ] ; then
# Self destruct!
    unset -f deactivate
fi
}

# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="/home/majid/Documents/Website/.venv"
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH

I really appreciate if anyone help me to solve this issue.

Upvotes: 1

Views: 4632

Answers (2)

Raja Simon
Raja Simon

Reputation: 10315

export KEY=VALUE is the terminal command. Just copy paste this on terminal will work. If you want more control for your Django project I suggest you to install pipenv and create the file called .env in your root folder where manage.py present. The pipenv is recommended way to work with virtualenv and managing environment.

.env

 DJANGO_SETTINGS_MODULE="thissite.settings.development"
 LD_LIBRARY_PATH=/usr/local/lib
 LC_ALL='en_US.UTF-8'
 LANG='en_US.UTF-8'

Upvotes: 2

RHSmith159
RHSmith159

Reputation: 1592

If you are using virtualenvwrapper, there will be a postactivate file in which you can put your env variables.

Depends on how you have it set up, but its probably located somewhere like:

/Users/<me>/.virtualenvs/<my_project>/bin

Just paste those export statements in and they'll be available in you env when you activate it.

Upvotes: 0

Related Questions