[Python]安裝pip、虛擬環境、Git指令

pip安裝:
指令: python get-pip.py

虛擬環境安裝: 
指令: pip install virtualenv

建立虛擬環境:
指令: virtualenv VENV
指令: virtualenv --python=python3.5 VENV

啟動虛擬環境:
指令: VENV\Scripts\activate
指令: source VENV/bin/activate

查看套件清單
指令: pip freeze > xxx.txt(存到文件檔)

建立專案
(VENV) django-admin startproject xxxx

建立app
(VENV) python manage.py startapp

安裝套件
指令:  pip install -r 'xxx.txt'

bash更改
echo alias python=python3 >> ~/.bashrc
source ~/.bashrc

靜態文件配置:
#python manage.py collectstatic
這一句話就會把以前放在app下static中的靜態文件全部拷貝到 settings.py 中設置的 STATIC_ROOT 文件夾中
apache2配置文件 
Alias /static/ /path/to/collected_static/
<Directory /path/to/collected_static>
    Require all granted
</Directory>
nginx
location /media  {
    alias /path/to/project/media;
}
location /static {
    alias /path/to/project/collected_static;
}
 

Git:


  • origin(remote) 是 Repository 的版本
  • master(branch) 是 local 端, 正在修改的版本
指令: git config --global user.name "xxx"
指令: git config --global user.email "xxx@xxx.xxx"
指令:  git init
指令:  git remote add origin https://xxxx
指令:  git add .
指令:  git commit -m xxxxx
指令: git push origin master
指令: git clone https://xxxx
指令: git pull

遠端連到heroku git
heroku git:remote -a xxxxxx(專案名)

取得heroku git
git pulll heroku master


MySQL DB is not allowed to connect to this MySQL server
如果你想連接你的mysql的時候發生這個錯誤:
ERROR 1130: Host '192.168.1.2' is not allowed to connect to this MySQL server

1。 改表法。可能是你的帳號不允許從遠端登陸,只能在localhost。這個時候只要在localhost的那台電腦,登入mysql後,更改 "mysql" 資料庫裡的 "user" 表裡的 "host" 項,從"localhost"改稱"%"
mysql -u root -pvmwaremysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
2. 授權法。例如,你想myuser使用mypassword從任何主機連接到mysql伺服器的話。
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允許使用者myuser從ip為192.168.1.2的主機連接到mysql伺服器,並使用mypassword作為密碼
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.2' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.2' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql>flush privileges; 這句一定要加上。