0

I have a code in python that I use

import requests

It´s works if I run the code on command line.

But when I put in systemd It didn't work.

In log I see error:

Aug  2 15:08:19 beaglebone python3[2140]:     import requests
Aug  2 15:08:19 beaglebone python3[2140]: ImportError: No module named 'requests'

I´m using debian in BeagleBone

Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49

1 Answers1

1

You've asked a variation of the FAQ Why do things behave differently under systemd?.

This may have to do with the current working directory or environment variables that provide Python library paths.

At top of your python code before your import line, immediately dump out the current working directory and all environment variables. Review the differences under systemd vs manual use.

I think you'll find the issue there. For example, if requests was found relative to your current working directory and systemd is using a different directory.

See the answer to above linked FAQ for more possibilities.

Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49
  • Sorry, I'm just starting with Linux. I understood and think that the problem is with environment variables, but I´m confuse with the FAQ. How can I "At top of your python code before your import line, immediately dump out the current working directory and all environment variables"? – Antonio Rafael da Silva Filho Aug 02 '18 at 20:22
  • See the answers for [finding the current directory in Python](https://stackoverflow.com/questions/3718657/how-to-properly-determine-current-script-directory) and [printing the environment from Python](https://stackoverflow.com/questions/4906977/how-do-i-access-environment-variables-from-python). Handle those tasks as the first lines in your script. – Mark Stosberg Aug 03 '18 at 14:39