Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
122 views
in Technique[技术] by (71.8m points)

python - Git Bash not allowing import of file

I found a question that suggested running the code below to set my PYTHONPATH variable in git bash, which it does fine. However, I am still getting an error on my import statement. Is there something more I need to do to get a file to import? I have been having to use the work around below to add it to the path

Workaround

sys.path.append('../')

What I've tried

  • existing python script file in directory x
  • existing python \__init\__.py file in x
  • C:Repositoriesops_tools added to PYTHONPATH variable available to the user

Set Path

winpath=$(echo $MSYS2_WINPATH | tr ";" "
" | sed -e 's/\/\\/g' | xargs -I {} cygpath -u {})
unixpath=''

# Set delimiter to new line
IFS=$'
'

for pth in $winpath; do unixpath+=$(echo $pth)":"; done

export PYTHONPATH$(echo $PYTHONPATH$unixpath | sed -e 's/:$//g')
unset IFS
unset unixpath
unset winpath

Output

The output of $PYTHONPATH now shows the path. But it still doesn't recognize the import statement.

bash: /c/Repositories/ops_tools:
question from:https://stackoverflow.com/questions/65599944/git-bash-not-allowing-import-of-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...