MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    PM2 auto start and python virtual environment not playing together

    Scheduled Pinned Locked Moved Solved Troubleshooting
    4 Posts 2 Posters 1.5k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      Brown19
      last edited by

      Hi, I use Tom Hirschberger’s MMM-Temperature to display temp and humidity from an adafruit sht31d. It has a dependency of the Adafruit CircuitPython Library. I’ve upgrade my pi to Bookworm. Python now runs in a virtual environment. I can activate the virtual environment and get everything to work if I launch MM2 in the virtual environment using npm start. It doesn’t work using PM2 start MagicMirror.
      I know you call call python without explicitly activating the environment but I’m not sure what changes need to be made to module.
      Maybe create a systemd unit file to run the the library at startup?
      Ideally, I want the same functionality back; my MM starts on boot and python works normally.
      Has anyone seen this or has a fix?

      Thanks!

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @Brown19
        last edited by sdetweil

        @Brown19 in the script launched by pm2, connect to the virtual environment with the venv command , before launching mm

        if you setup MagicMirror from my script, then the bash script used is
        ~/MagicMirror/installers/mm.sh

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        B 1 Reply Last reply Reply Quote 0
        • B Offline
          Brown19 @sdetweil
          last edited by

          @sdetweil Thanks! That worked. I added a line in mm.sh to connect to the virtual environment before launching mm.

          S 1 Reply Last reply Reply Quote 0
          • B Brown19 has marked this topic as solved on
          • S Offline
            sdetweil @Brown19
            last edited by sdetweil

            @Brown19 from an educational perspective

            the command pm2 info MagicMirror
            would have shown you what program. or script was being launched

            and then, when you open a terminal window, the .profile and .bashrc scripts are run to setup the user environment.
            the .bashrc has the venv command in it

            when pm2 launches a pgm at startup, it is not using a terminal window, so those script are NOT run
            you can also use the source command to load them at any time

            so you could have done
            source .bashrc
            instead of
            venv…

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Enjoying MagicMirror? Please consider a donation!
            MagicMirror created by Michael Teeuw.
            Forum managed by Sam, technical setup by Karsten.
            This forum is using NodeBB as its core | Contributors
            Contact | Privacy Policy