forked from xXG0DLessXx/poe-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.py
40 lines (33 loc) · 1.36 KB
/
start.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import platform
import subprocess
import sys
from setuptools import find_packages, setup
def create_virtual_env():
"""Create a virtual environment in a subdirectory of the project."""
venv_dir = os.path.join(os.getcwd(), 'env')
if not os.path.exists(venv_dir):
try:
subprocess.check_call([sys.executable, '-m', 'venv', venv_dir])
except subprocess.CalledProcessError as e:
print('Error creating virtual environment:', e)
sys.exit(1)
def install_dependencies():
"""Install the required packages from the requirements.txt file."""
try:
subprocess.check_call([os.path.join('env', 'bin', 'python'), '-m', 'pip', 'install', '-r', 'requirements.txt'])
except subprocess.CalledProcessError as e:
print('Error installing dependencies:', e)
sys.exit(1)
if __name__ == '__main__':
# Create the virtual environment
create_virtual_env()
# Install the required packages
install_dependencies()
# Determine the Python executable based on the current platform
if platform.system() == 'Windows':
python_executable = os.path.join('env', 'Scripts', 'python')
else:
python_executable = os.path.join('env', 'bin', 'python')
# Run PoeTelegramBot.py within the virtual environment
subprocess.check_call([python_executable, 'PoeTelegramBot.py'])