79407484

Date: 2025-02-02 22:44:10
Score: 1.5
Natty:
Report link

Different people would suggest different solutions as there are multiple ways to solve this problem.

Method 1

Add the path of the subdirectory from you want to run the script in sys.path. In fact you can add as many paths as you can to let compiler find the script from the given locations.

Method 2

You can write a separate python file called setup.py and call it in your main script. This file should work as follows:

Say your file structure looks like

app/
  __init__.py
  mymodule.py
  inner_folder/
  myscript.py
setup.py

Your setup.py should look somewhat like this

from setuptools import setup

setup(
   name='my-app',
   version='0.1',
   packages=['app'],
   install_requires=[
       # a list of required packages if needed
    ],
 )

Original Source : Why does my python not add current working directory to the path?

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: Naveed Ahmed