0

Python program generating a file path with

os.path.abspath(os.path.dirname(sys.argv[0]))

after creating variable

BAP_DATA_PATH = os.path.join(scriptdir, "BaptismTiltesTooPictures.xlsx")

when trying to use that as an argument in pandas read_excell

bap_pic_df = pd.read_excel(io=BAP_DATA_PATH)

returning FileNotFoundError

This is the file path generated

C:\\BaptismalSlideShow\\BaptismTiltesTooPictures.xlsx

When I remove the double backslash and paste into file explorer it does bring up the correct excel sheet

from pptx import Presentation
import datetime
import pandas as pd
import os
import sys
from collections import Counter
from pptx.util import Inches, Pt
from pptx.enum.shapes import MSO_SHAPE
from PIL import Image
from pptx.dml.color import RGBColor
import numpy as np

scriptdir = os.path.abspath(os.path.dirname(sys.argv[0]))
now = datetime.datetime.now()

TEST_FILE_PATH = os.path.join(scriptdir, "master.pptx")
BAP_DATA_PATH = os.path.join(scriptdir, "BaptismTiltesTooPictures.xlsx")
test_save = os.path.join(scriptdir, "Generated Baptismal Slide Show (Generated {}).pptx".format(now.strftime("%b %d, %Y at %I %M %S")))
WHEAT = os.path.join(scriptdir, "Wheat.jpg")

print ("test")
print (BAP_DATA_PATH)

bap_pic_df = pd.read_excel(io=BAP_DATA_PATH)

Tried manually putting in a string instead of the BAP_DATA_PATH variable, also did not work

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Use `__file__` to get the path of the current script. See https://stackoverflow.com/questions/3430372/how-do-i-get-the-full-path-of-the-current-files-directory – Barmar Jul 08 '23 at 22:14
  • Where are the double backslashes coming from? None of the code you show should do that. – Barmar Jul 08 '23 at 22:16
  • `scriptdir = os.path.abspath(os.path.dirname(sys.argv[0]))` Show us exactly how this program is executed, including the actual value for `sys.argv[0]`. – John Gordon Jul 08 '23 at 22:20
  • The actual value returns as 'C:\\BaptismalSlideShow\\CreateSlideshowV2.py'. Do you want me to add the rest of the program to the post? – OldHashbrowns1 Jul 08 '23 at 22:30

0 Answers0