Python Forum
problem with sphinx and file directory in script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with sphinx and file directory in script
#1
Hi, I am trying to use sphinx to document some of my code but I'm having problems getting my files directories. I dont want to write down the full path of the script. when I run my script in the terminal I get the directory of my script, but when the same commands are run with sphinx, it gets my virtual environments folder. this is what my file structure looks like:
projectDir
  • test.py
  • folder
    • file.log
  • venv
    • venv's files

this is the part of the code I'm having problems with:
##########################
if __name__ == "__main__":
    print(f"{os.path.dirname(os.path.abspath(sys.modules['__main__'].__file__))}/folder/file.log")
    print(os.path.abspath(sys.modules['__main__'].__file__))
    print(pathlib.Path(__file__).parent.absolute())
    fileHandler = logging.FileHandler(f"{pathlib.Path(__file__).parent.absolute()}/folder/file.log")
when I run in a terminal, from any directory, this works. However when I use sphinx to make html I get this error, the path upto and including the project directory is correct but for some reason it looks in venv/bin:
Quote:FileNotFoundError: [Errno 2] No such file or directory: 'projectDir/venv/bin/folder/file.log'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,300 Jun-27-2023, 01:17 PM
Last Post: diver999
  Extract file only (without a directory it is in) from ZIPIP tester_V 1 981 Jan-23-2023, 04:56 AM
Last Post: deanhystad
  Running script with subprocess in another directory paul18fr 1 3,696 Jan-20-2023, 02:33 PM
Last Post: paul18fr
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,111 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  no such file or directory in SFTP saisankalpj 2 1,539 Nov-25-2022, 11:07 AM
Last Post: DeaD_EyE
Photo Making Zip file of a file and Directory Nasir 2 1,016 Oct-07-2022, 02:01 PM
Last Post: Nasir
  Failed to execute child process (No such file or directory) uriel 1 1,650 Sep-15-2022, 03:48 PM
Last Post: Gribouillis
  Need Help: FileNotFoundError:[Errno 2] No such file or directory python202209 5 2,629 Sep-12-2022, 04:50 AM
Last Post: python202209
  importing functions from a separate python file in a separate directory Scordomaniac 3 1,365 May-17-2022, 07:49 AM
Last Post: Pedroski55
  How to read python shortcut target profile directory of Chrome Ink file sunny9495 1 1,656 Apr-12-2022, 06:12 PM
Last Post: sunny9495

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020