crontab importerror:no module named XXX occurs when calling Python

Source: Internet
Author: User

In the http://chenx1242.blog.51cto.com/10430133/1884415 wrote a monitoring MQ script, the script into the crontab to monitor the time, so #crontab- e, To add a statement:

* * * * * CD/directory && python MQ script name. PY >/root/mq.log 2>&1


Send the results of the execution to the/root/mq.log, and open a look inside to see that the error has occurred:

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/94/AE/wKiom1kMKxnz8iaZAACRhozHUls666.png "title=" 1.png "alt=" Wkiom1kmkxnz8iazaacrhozhuls666.png "/>


But in the shell alone execution is OK, so add source/etc/profile or error, visible is not the problem of environment variables, how to do?


First,#which pythonto determine the path to Python:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/94/AE/wKiom1kMLEfQAQ5OAAAPfClEhe0780.png "title=" 1.png "alt=" Wkiom1kmlefqaq5oaaapfclehe0780.png "/>


The entire Python path is copied into the crontab, the whole #crontab-l effect is like this:

* * * * * * source/etc/profile && CD/directory && nohup/usr/local/bin/python MQ script name. PY >/root/mq.log 2>& ; 1


If more than one version of Python is installed on a machine, it is more about specifying the path to Python, or crontab will be foolish enough to find the default path.


This article is from "Life is waiting for Gordo" blog, please make sure to keep this source http://chenx1242.blog.51cto.com/10430133/1922450

crontab importerror:no module named XXX occurs when calling Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.