We are going to use Docker Compose, but if you want to test your code locally without containers, you can create a virtual environment.
The app we are creating here is an API to read and store quotes in a Mysql database.
pip install virtualenvwrapper
export WORKON_HOME=~/Envs
mkdir -p $WORKON_HOME
source ~/.local/bin/virtualenvwrapper.sh
which python3
mkvirtualenv --python=/usr/bin/python3 learnkubernetes
To test if our API is responding run:
curl -X Get -i http://0.0.0.0:3000/api/v1/get-quote
To test the POST request and insert a quote to the database, use:
curl -i -H "Content-Type: application/json" -X POST -d '{"quote":"To find a fault is easy; to do better may be difficult. -- Plutarch"}' http://0.0.0.0:3000/api/v1/set-quote
Health check
curl -X Get -i http://0.0.0.0:3000/healthz
If you get an error regarding about Unresolved reference 'flask_sqlalchemy'
, delete stubs from the following
directory:
grep -R 'sqlalchemy' # this will help you locate the python stub folder in which you will need to delete the stub
cd ~/.PyCharm2019.3/system/python_stubs/618138258
- https://intellij-support.jetbrains.com/hc/en-us/community/posts/360006965380-PyTorch-debugging-inside-local-Docker-container-with-PyCharm
- https://pypi.org/project/pydevd-pycharm/
- https://vinta.ws/code/remotely-debug-a-python-app-inside-a-docker-container-in-visual-studio-code.html
- https://stackoverflow.com/questions/51575598/how-to-make-docker-compose-run-all-services-when-debuging-with-pycharm
- https://wiki.datavisyn.io/phovea/development/workspace/pycharm-debugging
- https://intellij-support.jetbrains.com/hc/en-us/community/posts/360006874159-Pycharm-Remote-Debugger-for-Docker-Debug-inside-container-launched-from-3rd-party-library
- https://stackoverflow.com/questions/41314328/rich-editors-in-a-docker-development-environment/41317770#41317770
- https://stackoverflow.com/questions/41484074/pycharm-remote-debug-in-a-docker-container
If this doesn't work try removing and adding back the project interpreter, see the below links for more information.
And easier solution was to just set the project interpreter as the Docker one.
- https://stackoverflow.com/questions/11725519/pycharm-shows-unresolved-references-error-for-valid-code (Unresolved reference)
- https://www.jetbrains.com/help/pycharm/using-docker-as-a-remote-interpreter.htm
- https://www.jetbrains.com/help/pycharm/resolving-references.html
- https://stackoverflow.com/questions/24266114/pycharm-what-is-python-stubs