Python Forum
Python 3.12 cannot import local python files as modules
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 3.12 cannot import local python files as modules
#10
(Jul-26-2024, 05:11 PM)sunflowerdog Wrote: Yeah, I'm not sure why Python 3.11 is adding my project folder to sys.path but 3.12 isn't?
I don't understand it either. It may be a Windows-specific issue but I never use the Windows OS.

It is not very satisfactory but you could add the following lines in your sitecustomize or your usercustomize module to force the inclusion of the main script's directory in sys.path

from pathlib import Path
import sys

if sys.argv:
    sys.path.insert(0, str(Path(sys.argv[0]).resolve().parent))
« We can solve any problem by introducing an extra level of indirection »
Reply


Messages In This Thread
RE: Python 3.12 cannot import local python files as modules - by Gribouillis - Jul-26-2024, 10:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Inserting Python Buttons into KV Files edand19941 3 695 Feb-19-2025, 07:44 PM
Last Post: buran
  How to write variable in a python file then import it in another python file? tatahuft 4 1,083 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  python 3.13 : import whois HansieB 1 757 Nov-30-2024, 02:58 PM
Last Post: snippsat
  Conversion of Oracle PL/SQL(packages, functions, procedures) to python modules. DivyaKumar 3 8,464 Oct-01-2024, 03:32 PM
Last Post: Alex_Kirpichny
  Trying to generating multiple json files using python script dzgn989 4 2,693 May-10-2024, 03:09 PM
Last Post: deanhystad
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 1,490 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  Different Ways to Import Modules RockBlok 2 1,489 Dec-11-2023, 04:29 PM
Last Post: deanhystad
  Newbie question about switching between files - Python/Pycharm Busby222 3 1,537 Oct-15-2023, 03:16 PM
Last Post: deanhystad
  open python files in other drive akbarza 1 1,575 Aug-24-2023, 01:23 PM
Last Post: deanhystad
  change directory of save of python files akbarza 3 3,833 Jul-23-2023, 08:30 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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