I've a Django project which runs in virtual environment.
Also there is line export ENV=staging in .bashrc file.
And in settings I try to read this using os.getenv('ENV') but it returns None.
settings_staging.py
...
ENV = os.getenv('ENV')
...
.bashrc
...
export ENV=staging
...
Error
[dev.gipi] out: File "/home/ubuntu/projects/deeyoon/settings/settings.py", line 61, in <module>
[dev.gipi] out: raise Exception('Environment variable ENV is requried!')
[dev.gipi] out: Exception: Environment variable ENV is requried!
What may cause the problem or what is goin wrong with?
Sultan.
There is one more case when fabric ignores .bashrc.
Often .bashrc contains following line:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
Comment it out.
Common problem is that .bashrc file is never executed. Type env and check if ENV variable is there.
Related
I currently have this script to show my GitHub branch and virtual env:
setopt PROMPT_SUBST
autoload -Uz vcs_info
precmd() { vcs_info }
zstyle ':vcs_info:git:*' formats '(%b)'
MYPS1=''
MYPS1+='%F{green}'
MYPS1+='${${(%):-%n}:0:1}'
MYPS1+='#'
MYPS1+='${${(%):-%m}:(-4)}' # Get last 4 chars of var machine name
MYPS1+=':'
MYPS1+='%F{yellow}'
MYPS1+='%1~' # Show only the name of the working directory or ~ if it is the home directory
MYPS1+='%F{magenta}'
MYPS1+='${vcs_info_msg_0_}' # Show git branch if any
MYPS1+='%f'
MYPS1+='%# '
PS1=$MYPS1
Sometimes I need to update my .zshrc so I run:
source ~/.zshrc
The problem is, whenever I reload my shell, I cannot see my Python virtual environment anymore even though it's still active.
# After activating virtual env
(my-ve-3.7.13) u#m1:repo-name(github-branch)%
# After reloading my zsh
u#m1:repo-name(github-branch)%
I use pyenv and virtualenvs.
How can I keep the virtual env name in my prompt?
Following #chepner's comment, I figured it out:
Use env to see the list of all env vars. pyenv uses PYENV_VERSION.
Add it to the prompt, use () to have the same look as pyenv does.
...
MYPS1=''
MYPS1+='($PYENV_VERSION) '
MYPS1+='%F{green}'
...
I have installed virtualenv and the virtualwrapper via apt-get, I got to a point where I created a virtual enviroment but however later on during that same day when I used the workon command it was not found. I further on went and inspected my home directory and .virtualenvs dir and the virtualenv I created earlier were still there.
Solving this problem took two steps:
Add this to your .bashrc / .bash_profile / .zshrc:
# load virtualenvwrapper for python (after custom PATHs)
venvwrap="virtualenvwrapper.sh"
/usr/bin/which -s $venvwrap
if [ $? -eq 0 ]; then
venvwrap=`/usr/bin/which $venvwrap`
source $venvwrap
fi
Then use:
source .bash_profile
# or .bashrc / .zshrc
to reflect the changes.
Additionally, if the terminal still sometimes cant find workon, use source .bash_profile to reset and find it again.
type source .profile in home directory from terminal.
Read the readme in the top of which virtualenvwrapper.sh
You need to source it inside bashrc
open ~/.profile
cd ~
nano .profile
add at the end
#virtualenvwrapper setup
export WORKON_HOME=$HOME/envs
export PROJECT_HOME=$HOME/dev
source /usr/local/bin/virtualenvwrapper.sh
to load your .profile file you just edited:
$ . .profile
I ran in to this problem too and I simply needed to logout and log back in.
This read in the changes which the debian package manager made to my system at /etc/bash_completion.d/virtualenvwrapper
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!
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.
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
On Python 3.8 just go to the folder containing the virtual environment and type
source venv-test\scripts\activate
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.
change directory to scripts directory as follows:
cd venv-test/Scripts
and run the activate file by typing
activate
at the prompt
you have to run source venv-test/bin/activate not venv-test/Scripts/activate
I had the same problem before, try typing :
venv-test/Scripts/activate.bat,
it worked for me
I have an access to a Dreamhost subdomain on which I'm trying to run a Django REST app. The server runs on Ubuntu 12.04.5 LTS. Something went wrong in my virtual environment, so I'm trying to follow Dreamhost's instructions to install Python again. I get stuck at step 4:
. ~/.bash_profile
The command doesn't return, and I have to interrupt it to get back. Here's my .bashrc:
# ~/.bashrc: executed by bash(1) for non-login shells.
export NVM_DIR="/home/julius/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
source .bash_profile
and here's my .bash_profile:
# ~/.bash_profile: executed by bash(1) for login shells.
umask 002
PS1='[\h]$ '
. $HOME/.bashrc
export PATH=$HOME/opt/python-3.5.1/bin:$PATH
What am I doing wrong?
It never returns because it can never complete. Your .bash_profile sources your .bashrc, which in turns sources (.s) your .bash_profile, which sources your .bashrc, which ...
The bash source command (or ., which is just another name for the same thing) is not like a require or import statement that only happens once. It is an runtime command that executes the sourced file every time it's encountered.
You have infinite recursion when loading .bashrc or .bash_profile since they both source each other. You should probably remove the call to . $HOME/.bashrc to prevent this.
I trying to setup virtualenvwrapper in GitBash (Windows 7). I write the next lines:
1 $ export WORKON_HOME=$HOME/.virtualenvs
2 $ export MSYS_HOME=/c/msys/1.0
3 $ source /usr/local/bin/virtualenvwrapper.sh
And the last line give me an error:
source /usr/local/bin/virtualenvwrapper.sh
sh.exe: /usr/local/bin/virtualenvwrapper.sh: No such file or directory
I find, where on my drive is virtualenvwrapper.sh and change directory name. On my computer it's /c/Python27/Scripts/virtualenvwrapper.sh. When I again run command
$source /c/Python27/Scripts/virtualenvwrapper.sh
I get the next ERROR message:
sh.exe":mktemp:command not found ERROR: virtualenvwrapper could not create a temporary file name
I check my enviroment variable: C:\python27\;C:\python27\scripts\;C:\python27\scripts\virtualenvwrapper.sh\;C:\msys;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\Git\bin\
I don't know where i made a mistake
The error is saying that sh.exe (the shell) can't find a command matching mktemp, which means it's not present in GitBash, at least not in your environment.
One option is you could download a Windows version of mktemp, such as http://gnuwin32.sourceforge.net/packages/mktemp.htm and then place it in the C:\Program Files (x86)\Git\bin directory. The shell should then be able to match the mktemp command and be able to proceed.
I've found a fix for this problem on a Windows 8 machine using GitBash.
TL;DR:
Get mktemp for windows, put it somewhere that can be used by GitBash, then edit virtualenvwrapper.sh and on line 202, add a touch command with the file created. It should look like this:
file="$(virtualenvwrapper_mktemp -t virtualenvwrapper-$suffix-XXXXXXXXXX)"
touch $file # this is the new line
if [ $? -ne 0 ] || [ -z "$file" ] || [ ! -f "$file" ]
FULL ANSWER:
As khampson mentioned, you do have to download mktemp and place it where your Git\bin (C:\Program Files (x86)\Git\bin usually) directory is. After that, running the virtualenvwrapper.sh file would cause an error saying:
path = C:/Users/User/AppData/Local/Temp/virtualenvwrapper-initialize-hook-XXXXXX XXXX
lpPathBuffer = C:\Users\User\AppData\Local\Temp\
szTempName = C:\Users\User\AppData\Local\Temp\tmp23A9.tmp
path = C:\Users\User\AppData\Local\Temp\tmp23A9.tmp
fd = 3
ERROR: virtualenvwrapper could not create a temporary file name.
On line 202(source), you see a function call to virtualenvwrapper_mktemp (which is just a wrapper function to call mktemp) and this is supposed to create the new temp file, but apparently it doesn't on windows.
Going through the manual for mktemp, on the examples section, you see that they are always sending something to that new file handle which forces the file to be created.
So instead of sending an empty string using echo like the manual, just add a touch command to the virtualenvwrapper.sh:
file="$(virtualenvwrapper_mktemp -t virtualenvwrapper-$suffix-XXXXXXXXXX)"
touch $file # new command here
This should force windows to create the temp file. I can't post the rest of the links due to low rep but I hope this still helps someone.
EDIT
I created a pull request on the virtualenvwrapper repo and it got approved. You can see the touch command I suggested added here.