Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto install modules #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

1404er
Copy link

@1404er 1404er commented Dec 18, 2021

Simple script to automatically install the requirements.txt

Simple script to automatically install the requirements.
@bolshoytoster
Copy link
Contributor

bolshoytoster commented Dec 19, 2021

I could argue that this isn't needed since it's just one command, but to someone less technically inclined, making it easier could be the difference between using the bot and not, so this is actually a good idea in that regard.

One addition I'd like to suggest though, we could also check to make sure the other dependencies are installed as well (poppler, ffmpeg and LaTeX) and maybe offer the user to to install them. I can probably implement that if you want.

For poppler:

import io
import pdf2image
import requests
import sys
import zipfile

try:
    pdf2image.convert_from_path('')
except pdf2image.exceptions.PDFInfoNotInstalledError:
    if input('Poppler is not installed, would you like to install it now? [y/N] ')[0] in ('Y', 'y'):
        if sys.platform == 'linux':
            print('Install the `poppler-utils` package and rerun this script')
            sys.exit()
        elif sys.platform == 'win32':
            zipfile.ZipFile(io.BytesIO(requests.get('https://github.com/oschwartz10612/poppler-windows/releases/download/v21.11.0-0/Release-21.11.0-0.zip').content)).extractall(path='C:/Program Files')
            # Need to figure out how to add 'C:/Program Files/poppler-21.11.0/Library/bin' to PATH in windows
        elif sys.platform == 'darwin':
            os.system('brew install poppler')
        try:
            pdf2image.convert_from_path('')
        except pdf2image.exceptions.PDFInfoNotInstalledError:
            print('Installing poppler failed, refer to https://pdf2image.readthedocs.io/en/latest/installation.html#windows to install it manually')
            sys.exit()
        except:
            print('Poppler installed successfully')
    else:
        print('Aborting')
        sys.exit()
except:
    pass

Not complete (I couldn't find out how to add to windows PATH, but it's a start)

edit: added mac support

@bolshoytoster
Copy link
Contributor

bolshoytoster commented Dec 19, 2021

Come to think of it, we don't need ffmpeg anymore since they removed the captcha, so we can remove it as a dependency.

I've added a commit to my pr to address this.

@1404er
Copy link
Author

1404er commented Dec 19, 2021

Come to think of it, we don't need ffmpeg anymore since they removed the captcha, so we can remove it as a dependency.

I've added a commit to my pr to address this.

I edited this and made a rough draft of adding it to path. I also replaced print statements with input since some might run the file directly and not from cmd

import os
import io
import pdf2image
import requests
import sys
import zipfile

os.chdir(os.getcwd())
os.system("pip install -r requirements.txt")

try:
    pdf2image.convert_from_path('')
except pdf2image.exceptions.PDFInfoNotInstalledError:
    prompt = input('Poppler is not installed, would you like to install it now? [y/N] ')
    prompt.lower()
    if prompt == "y":
        if sys.platform == 'linux':
            input('Install the `poppler-utils` package and rerun this script. ')
            sys.exit()
        elif sys.platform == 'win32':
            zipfile.ZipFile(io.BytesIO(requests.get(
                'https://github.com/oschwartz10612/poppler-windows/releases/download/v21.11.0-0/Release-21.11.0-0.zip').content)).extractall(
            path='C:/Program Files')
            path_backup = os.getcwd() + r"\path_backup.txt"
            os.system(f"echo %PATH% > {path_backup}")
            os.system('set PATH="%PATH%,C:/Program Files/poppler-21.11.0/Library/bin"')
        elif sys.platform == 'darwin':
            os.system('brew install poppler')
        try:
            pdf2image.convert_from_path('')
        except pdf2image.exceptions.PDFInfoNotInstalledError:
            input(
                'Installing poppler failed, refer to https://pdf2image.readthedocs.io/en/latest/installation.html#windows to install it manually')
            sys.exit()
        else:
            sys.exit()

this creates a backup of the path cause you never know, then temporarily adds poppler to path. this is as close you can really get without admin privileges.

@bolshoytoster
Copy link
Contributor

bolshoytoster commented Dec 19, 2021

@Dogey11 nice

    prompt = input('Poppler is not installed, would you like to install it now? [y/N] ')
    prompt.lower()

The prompt.lower() doesn't affect the value of prompt. It just returns prompt in lowercase, you should use prompt = prompt.lower() instead.

@bolshoytoster
Copy link
Contributor

For LaTeX, I have no clue about windows, but on linux you need to install the texlive-latex-base package and on mac you can os.system('brew install --cask basictex').

You can check if it's installed by running subprocess.call('pdflatex') and catching FileNotFoundError.

@1404er
Copy link
Author

1404er commented Dec 19, 2021

@Dogey11 nice

    prompt = input('Poppler is not installed, would you like to install it now? [y/N] ')
    prompt.lower()

The prompt.lower() doesn't affect the value of prompt. It just returns prompt in lowercase, you should use prompt = prompt.lower() instead.

mb. ive done this before but it's been a while

@1404er
Copy link
Author

1404er commented Dec 19, 2021

For LaTeX, I have no clue about windows, but on linux you need to install the texlive-latex-base package and on mac you can os.system('brew install --cask basictex').

You can check if it's installed by running subprocess.call('pdflatex') and catching FileNotFoundError.

i think you get it from here on windows

@bolshoytoster
Copy link
Contributor

@Dogey11

For LaTeX, I have no clue about windows, but on linux you need to install the texlive-latex-base package and on mac you can os.system('brew install --cask basictex').
You can check if it's installed by running subprocess.call('pdflatex') and catching FileNotFoundError.

i think you get it from here on windows

You can probably use that, but the size is 1.1 GB. And that's just the zip file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants