I am trying to process an uploaded file to Django server. When I receive it I launch a python script that processes the file (I need to do it this way instead of with classes, so please do not tell me to do it from a class).
My Django structure is the following:
Project
- web_server:
- settings ...
- url.py ...
- S2T: this is my app where I have my views
- views.py
- apps.py ...
- src: here I have my custom modules, I will focus on 2:
- pipeline
- master.py
- classes
- misc.py
- pipeline
From the views I launch a python script:
sb_info = subprocess.run(['python', 'src/pipeline/master.py', '/tmp'], stdout=subprocess.PIPE, universal_newlines=True)
This works nicely, but when the script is launched I get the following error:
File "src/pipeline/master.py", line 10, in from src.classes.misc import path_to_dest ModuleNotFoundError: No module named 'src'
The problem is that that file does exits. I have checked using os.listdir()
and the master.py does see the src module, this is the output that I get:
[temp.txt, db.sqlite3, pycache, S2T, .idea, manage.py, src, wdir.txt, .git, web_server]
I have tried a lot of things that I have seen in stackoverflow, for example:
- declaring the package in INSTALLED_APPS
- using import .src
- moving src inside S2T
I want to state again that from the views.py the src module is detected, I can import its functions, the problem comes when I launch a python script, then it stats complaining about module not found, but the os.listdir()
does see it, so I am confused about what is happening.
Thanks a lot for your help!