Ubuntu Cronjob can't execute conda environment

Iakovos Belonias

Whenever I login to my ec2 Ubuntu instance my terminal is like this

(base) ubuntu@ip-xx-xx-xx

When I run my Python script which is converted from a Jupyter notebook with the default conda environment the script runs perfect. The problem starts when I try to make a cronjob.

When the instance starts(I will try to explain as best I can), the ipython that runs the script can't find the packages. Because it's the default conda environment. I thought all I have to do is somehow activate the source bash, but everything failed. What I've tried so far

  • I've tried to exec bash
  • I've tried to add to SHELL the bash
  • I've tried to source bash
  • I've tried to run ipython directly from conda environment

At this point I don't know what I am missing. All I want, is when the instance start to "activate" the conda environment and with ipython run the script.

Jacopo

I'd take a guess that the virtualenv is being activated in .profile, which doesn't affect cron.

I'd suggest activating the venv in the crontab line:

SHELL=/bin/bash
[crontab stuff]  . /path/to/the/virtualenv/bin/activate && your.py

Setting SHELL=/bin/bash is not really mandatory, but will get you closer to the "usual" environment. If necessary, also set the PATH, cd into the right directory, etc.

A decent way to test is to ssh you@yourserver 'the command above' If you're having trouble getting the error, try appending &>/tmp/debug.log to the crontab command.

If you're not sure what the virtualenv path is, try: type activate (echo $PATH, print(sys.path), etc.)

More info: https://stackoverflow.com/questions/3287038/cron-and-virtualenv#answer-7031758

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

The command can't execute in vim environment

From Dev

Can't pip install pyAudio in conda environment (MAC)

From Dev

Can't execute commands in Swift on Ubuntu 14.04

From Dev

Why doesn't this bash script execute on Ubuntu, but does on an online environment?

From Java

How can I rename a conda environment?

From Dev

Error: 'conda' can only be installed into the root environment

From Dev

How can I rename a conda environment?

From Dev

PyCharm terminal doesn't activate conda environment

From Dev

How to execute python from conda environment by dvc run

From Dev

Node Server on Ubuntu can't access environment variables as sudo

From Dev

Can't login to Ubuntu 17.04 after editing environment variables for java

From Dev

Can't open Android Studio in Ubuntu 20.04 in XMonad desktop environment

From Dev

How can you "clone" a conda environment into the root environment?

From Dev

What can be reason for getting "execute permission denied" in cronjob in UNIX?

From Dev

I can't backup mongo with mongodump and cronjob

From Dev

change default environment from (base) to (env) in conda/anaconda in Ubuntu

From Dev

Can't execute this file

From Dev

Can't Execute ReactiveCommand

From Java

Unable to compile R packages in Ubuntu Conda environment: x86_64-conda-linux-gnu-c++: not found

From Dev

Can I choose where my conda environment is stored?

From Dev

How can you run QtConsole in a specific Conda environment?

From Dev

How can you activate a conda environment through a Jenkinsfile?

From Dev

How can you run QtConsole in a specific Conda environment?

From Dev

How can you activate a conda environment through a Jenkinsfile?

From Dev

Why doesn't a new Conda environment come with packages like numpy?

From Dev

Cronjob doesn't run Python script even though it has execute permissions and a hashbang to full path of python. Works normally outside of the cronjob

From Dev

Can't get PHP-script running as a cronjob

From Dev

Can't display the date correctly in a file generated by a cronjob

From Dev

can't delete files older then x days through cronjob

Related Related

  1. 1

    The command can't execute in vim environment

  2. 2

    Can't pip install pyAudio in conda environment (MAC)

  3. 3

    Can't execute commands in Swift on Ubuntu 14.04

  4. 4

    Why doesn't this bash script execute on Ubuntu, but does on an online environment?

  5. 5

    How can I rename a conda environment?

  6. 6

    Error: 'conda' can only be installed into the root environment

  7. 7

    How can I rename a conda environment?

  8. 8

    PyCharm terminal doesn't activate conda environment

  9. 9

    How to execute python from conda environment by dvc run

  10. 10

    Node Server on Ubuntu can't access environment variables as sudo

  11. 11

    Can't login to Ubuntu 17.04 after editing environment variables for java

  12. 12

    Can't open Android Studio in Ubuntu 20.04 in XMonad desktop environment

  13. 13

    How can you "clone" a conda environment into the root environment?

  14. 14

    What can be reason for getting "execute permission denied" in cronjob in UNIX?

  15. 15

    I can't backup mongo with mongodump and cronjob

  16. 16

    change default environment from (base) to (env) in conda/anaconda in Ubuntu

  17. 17

    Can't execute this file

  18. 18

    Can't Execute ReactiveCommand

  19. 19

    Unable to compile R packages in Ubuntu Conda environment: x86_64-conda-linux-gnu-c++: not found

  20. 20

    Can I choose where my conda environment is stored?

  21. 21

    How can you run QtConsole in a specific Conda environment?

  22. 22

    How can you activate a conda environment through a Jenkinsfile?

  23. 23

    How can you run QtConsole in a specific Conda environment?

  24. 24

    How can you activate a conda environment through a Jenkinsfile?

  25. 25

    Why doesn't a new Conda environment come with packages like numpy?

  26. 26

    Cronjob doesn't run Python script even though it has execute permissions and a hashbang to full path of python. Works normally outside of the cronjob

  27. 27

    Can't get PHP-script running as a cronjob

  28. 28

    Can't display the date correctly in a file generated by a cronjob

  29. 29

    can't delete files older then x days through cronjob

HotTag

Archive