# https://codeahoy.com/learn/tutorials/python-open/
Mode Description File Pointer Position Creates File if Not Exists Truncates Existing File
r Read-only Beginning of the file No No
r+ Read and write (updating) Beginning of the file No No
w Write-only (overwrite or create) Beginning of the file Yes Yes
w+ Write and read (overwrite or create) Beginning of the file Yes Yes
a Append-only (append or create) End of the file Yes No
a+ Append and read (append or create) End of the file Yes No$ pip install -r requirements.txt
$ pip --default-timeout=2000 install -r requirements.txt
$ pip install --no-cache-dir -r requirements.txt
$ pip uninstall -r requirements.txt -y
# if met subprocess error, try to install a lower version of dep first
$ pip install mysqlclient=2.1.1
$ pip install -r requirements.txt
$ docker build -t rest-apis-flask-python .- use -v "$(pwd):/app" otherwise code changes is not reflected in docker container
$ docker run -dp 5000:5000 -w /app -v "$(pwd):/app" --name flask-smorest-api-rick rest-apis-flask-python
# sh -c "flask run"
# above cmd line will tell server not using CMD line from Dockerfile but use flask run to start the server
$ docker run -dp 5000:5000 -w /app -v "$(pwd):/app" --name flask-smorest-api-rick rest-apis-flask-python sh -c "flask run"$ docker images -a$ docker image rm 8ae668a96ce6 aa4ecf532269 72d52a866646 2fa08ed06206 6840131c5619 7fb60d0ea30e 157095baba98$ docker ps -a Ref try to login from terminal
$ docker exec -it <container-id> bash
$ docker exec -it f36a9e11f47e bash##########################
##########################
- create virtualenv
$ pyenv virtualenv 3.10.8 flask-vsc-3.10.8- list existing virtualenvs $ pyenv virtualenvs ➜ python-flask-vsc git:(develop) ✗ pyenv virtualenvs 3.10.8/envs/flask-vsc-3.10.8 (created from /Users/runzhou/.pyenv/versions/3.10.8) flask-vsc-3.10.8 (created from /Users/runzhou/.pyenv/versions/3.10.8)
There are two entries for each virtualenv, and the shorter one is just a symlink.
- activate your virtualenv
$ pyenv activate flask-vsc-3.10.8
$ pyenv deactivate- update pip
$ python3.10 -m pip install --upgrade pip- delete virtualenv
$ pyenv uninstall my-virtual-envhttps://github.com/pyenv/pyenv-virtualenv
##########################
SETUP local venv
##########################
-
create local virtual env $ python3.10 -m venv .venv
-
select interpreter cmd + shift + P
-
activate your virutal env $ source .venv/bin/activate
##########################
check flask
##########################
$ which flask
(.venv) ➜ python-flask-vsc git:(develop) ✗ which flask
/Users/runzhou/git/python-flask-vsc/.venv/bin/flask
- ssh to your gcp machine
$ ssh 10.176.22.192- go to your home folder and create github pub key
$ cd /x/home/runzhou
$ ssh-keygen -t rsa -b 4096 -C "runzhou666@gmail.com"- clone repo to local
git clone git@github.com:RickZhou666/python-flask-vsc.git- check port avaialble to avoid conflict
sudo lsof -i -P -n | grep LISTEN- build docker image local
sudo docker build -t python-flask-vsc .- run in container
sudo docker run -dp 5000:5000 -w /app -v "$(pwd):/app" --restart=always --name python-flask-vsc_container python-flask-vsc