Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use anaconda environment without activate? (e.g. in Crontab)

Being reading this

http://conda.pydata.org/docs/using/envs.html

Is it possible to run a conda python directly without having to source activate xxx?

In VirtualEnv, you can find the exact location of the python executable and run something like this

./path/to/my/venv/bin/python xxx.py

Then xxx.py will be executed with environment on. It's handy to write one-linders in Crontab.

Could I do the same with anaconda/miniconda environments?

I've been trying this on Centos 6.5, system has python 2.5 which is too old.

I installed python 2.7 with miniconda, now I pip installed uWSGI, when executing it directly says

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site

But when execute it under conda env it works as expected.

like image 326
est Avatar asked Mar 14 '16 08:03

est


People also ask

How can I activate conda environment automatically?

Reload Window from Command Palette, select base:conda as python interpreter then press Ctrl+Shift+` to open a new integrated Terminal, conda environment should be activated automatically in it.

Do you have to activate conda environment every time?

No, you do not have to activate conda every time you open CMD. This is simply a matter of choice for the developer.

How do you activate and deactivate Anaconda environment?

To activate your Conda environment, type source activate <yourenvironmentname> . Note that conda activate will not work on Discovery with this version. To install a specific package, type conda install -n <yourenvironmentname> [package] . To deactivate the current, active Conda environment, type conda deactivate .


1 Answers

If conda is on your path:

source activate <env name> && python xxx.py && source deactivate

If conda isn't on your path but is installed:

source /path/to/conda/bin/activate /path/to/desired/env_name/ && python xxx.py && source deactivate

like image 97
Eric Dill Avatar answered Oct 04 '22 04:10

Eric Dill