简体   繁体   中英

Python os.startfile is not working in ubuntu

I am using python 3.6 on ubuntu. I wrote a python script to play songs. I have imported os module but it shows an error: AttributeError: module 'os' has no attribute 'startfile'

            elif 'play songs' in query:
            songs_dir = '/home/mjiabir/Music/mp3'
            songs = os.listdir(songs_dir)
            os.startfile(os.path.join(songs_dir, songs[0]))

what is the problem with this startfile attribute? Is there any equivalent of os.startfile()?

os.startfile is available for windows only.

See here in docs.

You can use os.open for that. Visit docs .

I solved this problem on Ubuntu 20.04 using os.system():

import os

os.system('mpg123 sound_file.mp3')

But you should first install the package mpg123 :

sudo apt install mpg321

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM