bash - python uses incorrect path -


i have bash script runs python program. use virtualenv.

firs include env bash:

source ./env/bin/activate 

then see (env) prefix in bash prompt.

$ echo $path /project/env/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl 

when try run python program bash script, runs wrong version of python. env uses python 2.6, while system has 3.2 default.

i print python version python script, , prints 3.

but why?

ls -la -rw-r--r-- 1 wnc wnc 2219 sep 27 01:42 activate -rw-r--r-- 1 wnc wnc 1275 sep 27 01:42 activate.csh -rw-r--r-- 1 wnc wnc 2414 sep 27 01:42 activate.fish -rw-r--r-- 1 wnc wnc 1129 sep 27 01:42 activate_this.py -rwxr-xr-x 1 wnc wnc 357 sep 27 01:42 easy_install -rwxr-xr-x 1 wnc wnc 365 sep 27 01:42 easy_install-2.6 -rwxr-xr-x 1 wnc wnc 318 sep 27 01:42 pip -rwxr-xr-x 1 wnc wnc 326 sep 27 01:42 pip-2.6 lrwxrwxrwx 1 wnc wnc 9 sep 27 01:42 python -> python2.6  lrwxrwxrwx 1 wnc wnc 9 sep 27 01:42 python2 -> python2.6 -rwxr-xr-x 1 wnc wnc 6240 sep 27 01:42 python2.6 

sanity check:

source /path/to/env/bin/activate python -v deactivate python -v 

the first python -v should show print python 2.6 , second python 3.2, right?

when run python script, 1 want use above virtualenv, make sure source /path/to/env/bin/activate first, example if run inside bash script:

#!/bin/bash source /path/to/env/bin/activate python /path/to/script.py 

tell me step doesn't work , error messages get.

if python program needs run in different way, not shell script, example wsgi, i'll have more tips you. bottom line is: don't forget source virtualenv activate script before using python script needs it.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -