1
eric@eric:~/project$ tree -d
.
|-- env
|   |-- bin
|   |-- include
|   |   `-- python3.4m -> /usr/include/python3.4m
|   `-- lib
|       `-- python3.4
|           |-- collections -> /usr/lib/python3.4/collections
|           |-- config-3.4dm-x86_64-linux-gnu -> /usr/lib/python3.4/config-3.4dm-x86_64-linux-gnu
|           |-- config-3.4m-x86_64-linux-gnu -> /usr/lib/python3.4/config-3.4m-x86_64-linux-gnu
|           |-- distutils
|           |   `-- __pycache__
|           |-- encodings -> /usr/lib/python3.4/encodings
|           |-- importlib -> /usr/lib/python3.4/importlib
|           |-- lib-dynload -> /usr/lib/python3.4/lib-dynload
|           |-- plat-x86_64-linux-gnu -> /usr/lib/python3.4/plat-x86_64-linux-gnu
|           |-- __pycache__
|           `-- site-packages
|               ...  # removed thirdparty libraries just to make it more readable
|               |-- pip-1.5.6.dist-info
|               |-- __pycache__
|               |-- setuptools
|               |   |-- command
|               |   |   `-- __pycache__
|               |   |-- __pycache__
|               |   `-- tests
|               |       `-- __pycache__
|               `-- setuptools-3.6.dist-info
`-- myscript.py

so in home directory there is a folder named project. in project folder I have a virtualenv folder and a simple script(let's say hello world in python3)

which python3 gives /usr/bin/python3

Now I'm trying to run this script using crontab -e (ubuntu 14.04). I can run this script manually by activating virtualenv (source env/bin/activate) but I've no idea how should I do this thing in crontab and what would be the shebang for this python3 virtualenv.

PS: I'm able to run a python2 script in crontab by adding this shebang #!/usr/bin/python at top of the file and then this line in crontab -e (run everyday at 2PM )

00 14 * * * /usr/bin/python /home/eric/project/myscript.py >> /var/log/cronjob.log

PPS: I dont want to write setup.py and use setuptools just a natural way (as I did above for python2)

1
  • what is python3 specific about it? have you tried the obvious /path/to/env/bin/python /path/to/script.py ...? Commented Feb 28, 2015 at 21:19

1 Answer 1

1

If I understood right, you want to run your script with python3 from virtualenv.

If so, you should use this path in your crontab -e: /home/eric/project/env/bin/python (figure out the exact path, if this one doesn't work).

I think, shebang has no nothing to do here, once you specify python binary explicitly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.