I'm trying to build a website maker in Python, and it works - up until I decided to put sound effects, which requires playsound
. After searching StackOverflow for autoinstalling libraries I found my answer and popped it into setup.py
. I then ran the code in Windows to check it worked - it did, but then I remembered that macOS and Linux (in my experience) can't use pip
, they only use pip3
. So I wrote an except into the setup file so whenever ModuleNotFoundError
popped up during the pip
sequence it would use pip3
instead. However, all I got (in Ubuntu) was this:
bye@DESKTOP-L5UUI0C:/mnt/f/pythonexperements/webmaker$ python3 1.py
__ __ _ _ _ __ __ _
\ \......../ / | |.......(_| |.......| \/ |.....| |..............
.\ \../\../ _..| |__ ___ _| |_ ___..| \ / |.__ _| |._____ _ __ ..
..\ \/ \/ / _ | '_ \/ __| | __/ _ \.| |\/| |/ _` | |/ / _ | '__|..
...\ /\ | __| |_) \__ | | || __/.| |..| | (_| | | __| |.....
....\/..\/.\___|_.__/|___|_|\__\___|.|_|..|_|\__,_|_|\_\___|_|.....
by ByeMC; v1.0
Installing required libraries, installing "playsound"
Traceback (most recent call last):
File "1.py", line 13, in <module>
from playsound import playsound
ModuleNotFoundError: No module named 'playsound'
During handling of the above exception, another exception occurred: # this is exactly what the terminal produced, please don't edit this line
Traceback (most recent call last):
File "1.py", line 16, in <module>
import setup
File "/mnt/f/pythonexperements/webmaker/setup.py", line 3, in <module>
import pip
ModuleNotFoundError: No module named 'pip'
The main script for the program:
[...]
print(asciiart)
try:
from playsound import playsound
except ModuleNotFoundError:
print('Installing required libraries, installing "playsound"')
import setup
install('playsound')
print('Install done')
playsound('notif')
[...]
The code that autoinstalls the libraries:
# Setup files
import pip
depend = ['playsound']
def install(package):
import importlib
try:
importlib.import_module(package)
except ImportError:
try:
import pip
pip.main(['install', package])
except ModuleNotFoundError:
import pip3
pip3.main(['install', package])
finally:
globals()[package] = importlib.import_module(package)
for x in depend:
install(x)
I would love if you could help me.