Run my Python script at login on linux

二次信任 提交于 2019-12-13 03:30:30

问题


I have a Python script, and I want it to be autostarted at every login. It's in a linux system. I followed a guide that explains that is enough to create a .desktop file in ~/.config/autostart/*.desktop and write:

[Desktop Entry]
Name=MyApp
Type=Application
Exec=python3 ~/.myapp/myapp
Terminal=false

I tried several times to reboot but the program doesn't execute, even if it seems to be active in the list of application of startup in my lxde environment.


回答1:


Often things like the ~ (tilde) aren't evaluated when placed in a config file. Try using the complete path instead (/home/user/… instead of ~/…) and see if this works. If this works, you can try to use $HOME instead ($HOME/…) to make this more portable and abstract.




回答2:


If you want to run your script on terminal login, place it to /etc/profile.d/

For KDE (at least, KDE 5) you could add applications to autorun in System Settings > Startup and Shutdown > Autostart (either *.desktop files or scripts), it adds links to ~/.config/autostart.




回答3:


You can achieve this by adding this line python /home/user/program.py in your .bashrc file. It will be invoked each time when you login to your system.



来源:https://stackoverflow.com/questions/45189029/run-my-python-script-at-login-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!