Hello,
I tried many things (including searching here) which is why I finally ask even though I feel a bit dumb.
How to add your code to $PATH and $PYTHONPATH?
Sub-optimal solution
import inspect
import os
import sys
from pathlib import Path
print("path={}".format(os.environ['PATH']))
def add_do_path(path_to_add):
print("Adding to path: {}".format(path_to_add))
sys.path.insert(0, path_to_add)
add_do_path(str(Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))).parent.parent.parent.parent))
(probably could be improved but I would rather do the correct way than improve this)
Configuration
/code/my_project/ python files and packages
/code/setup.py
etc.
Basically I call a script:
floyd run --cpu --env tensorflow-1.3 "bash ./my_project/.../script.sh"
from my_project import X
It fails with:
ModuleNotFoundError: No module named 'my_project'
Unsuccessful attempts
Here are my attemps:
floyd run --cpu --env tensorflow-1.3 "PATH=$PATH:/code && bash ./my_project/.../script.sh"
floyd run --cpu --env tensorflow-1.3 "PYTHONPATH=$PYTHONPATH:/code && bash ./my_project/.../script.sh"
And also in script.sh:
#!/usr/bin/env bash
echo 'export PYTHONPATH=/code:$PYTHONPATH' >> ~/.bashrc
echo 'export PATH=/code:$PATH' >> ~/.bashrc
cat ~/.bashrc
source ~/.bashrc
echo "pythonpath=$PYTHONPATH"
echo "path=$PATH"
python3 my_project/.../main.py
Attempts were quite combined...
I am probably missing something obvious...
Thanks for your help.