美文网首页
Python-119 cannot open terminal

Python-119 cannot open terminal

作者: RashidinAbdu | 来源:发表于2021-08-30 13:20 被阅读0次
1. 首先,发现pycharm里报错,即:不能打开terminal,这样一来pip安装各种包也无法安装;用以下方法来解决这个问题:
File ---settings---tools ---terminal, 把shell.exe改成cmd.exe然后重启pycharm,再点击terminal,即可正常运行!
image.png
image.png
2. PDF文件进行split,并按页输出:具体代码如下,只需要改一下原始pdf文件路径和输出位置,点击运行即可!
  • 注意:输出文件会存放在制定的output位置!这点务必注意!如果没有设置,则会存在默认工作目录下!
# pdf_splitter.py

import os
from PyPDF2 import PdfFileReader, PdfFileWriter

def pdf_splitter(path):
    fname = os.path.splitext(os.path.basename(path))[0]

    pdf = PdfFileReader(path)
    for page in range(pdf.getNumPages()):
        pdf_writer = PdfFileWriter()
        pdf_writer.addPage(pdf.getPage(page))
#where to output the results 
        output_filename = 'C:\\Users\\Administrator\\Desktop\\split\\毛螺菌科文献{}_page_{}.pdf'.format(
            fname, page+1)

        with open(output_filename, 'wb') as out:
            pdf_writer.write(out)

        print('Created: {}'.format(output_filename))
if __name__ == '__main__':
    #original  PDF file to be splitted
    path = 'C:\\Users\\Administrator\\Desktop\\毛螺菌科文献.pdf'
    pdf_splitter(path)

运行前:

image.png

运行后:

image.png
  • Reference:

https://www.blog.pythonlibrary.org/2018/04/11/splitting-and-merging-pdfs-with-python/

相关文章

网友评论

      本文标题:Python-119 cannot open terminal

      本文链接:https://www.haomeiwen.com/subject/duzniltx.html