current position:Home>Easy to use scaffold in Python
Easy to use scaffold in Python
2022-02-01 11:20:42 【A nine barrel spring】
This is my participation 11 The fourth of the yuegengwen challenge 7 God , Check out the activity details :2021 One last more challenge
1 virtualenv Multi-environment management
# install virtualenv
pip install virtualenv
# Virtual environment Directory
/var/.venv
# Creating a virtual environment
virtualenv test_venv
# Use
/var/.venv/test_venv/Scripts/activate
# sign out
deactivate
Copy code
2 pyenv
2.1 pyenv install
macOS Use homebrew install
- Mac Under the installation of homebrew Then use homebrew install pyenv.
brew update
brew install pyenv
brew upgrade pyenv # Later, if you need to update pyenv
Copy code
- After successful installation, you need to .bashrc perhaps .bash_profile Add three lines to start automatic completion .
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Copy code
- Update environment variables
source .bash_profile
Copy code
CentOS install
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc
$ exec $SHELL -l
Copy code
Ubuntu install
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc
$ exec $SHELL -l
Copy code
2.2 Use pyenv management Python Many versions
The installation process
- View installed Python edition :
pyenv versions
- View the current Python edition :
pyenv version
- View installable Python edition :
pyenv install -l
- install Python:
pyenv install <version> # version Version number
- to update pyenv database :
pyenv rehash
- View the current Python edition :
which python
orpython --version
- uninstall Python edition :
pyenv uninstall <version> # The uninstall version number is <version> Of Python
- Python version management
pyenv global <version> # Global settings python The version is the specified version , Set global Python edition , By writing the version number to ~/.pyenv/version How to file . pyenv local <version> # Set the current path python The version is the specified version , Set up Python Local version , Write the version number to the in the current directory .python-version How to file . Set in this way Python Version has priority over global high . pyenv shell <version> # Set up current shell Windows use python The version is the specified version , Set orientation shell Of Python edition , By setting the current shell Of PYENV_VERSION The way of environment variables . This version takes precedence over local and global All high .–unset Parameter can be used to cancel the current shell Set version . Copy code
2.3 Install exception handling
macOS
Installation failed
macOS If installed Python Failure : `brew install zlib` and `brew install xz` and restart
Copy code
Linux
Installation failed ( If pyenv install 3.6.6
times BUILD FAILED
error )
- Install dependency library
-- CentOS Install dependency library
yum install readline readline-devel readline-static -y
yum install openssl openssl-devel openssl-static -y
yum install sqlite-devel -y
yum install bzip2-devel bzip2-libs -y
-- Ubuntu Install dependency library :
sudo apt-get install libbz2-dev
sudo apt-get install libssl-dev
sudo apt-get install libreadline6 libreadline6-dev
sudo apt-get install libsqlite3-dev
Copy code
- If the above has not been repaired
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev
Copy code
2.4 Use pyenv-virtualenv management Python A virtual environment
- install
$ git clone https://github.com/pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
$ source ~/.bashrc
Copy code
- Creating a virtual environment :
pyenv virtualenv 3.6.6 py3_flask
- Activate the virtual environment :
pyenv activate py3_flask
- Exit virtual environment :
pyenv deactivate
- Delete virtual environment :
pyenv uninstall py3_flask
2.5 Python uninstall
macOS Installation package installed Python Uninstall method
- As the beginning said ,Mac Self contained Python Has been able to meet our needs , So many students are after the installation Python after , Want to delete it again , Or uninstall . For deletion Python, First of all, we need to know what is installed , actually , In the installation Python when , Its automatic generation :
- Python framework, namely Python frame ;
- Python Application directory ;
- Point to Python The connection of .
- about Mac Self contained Python, Its framework directory is :
System/Library/Frameworks/Python.framework
- And we installed Python, Its ( Default ) The framework directory is :
/Library/Frameworks/Python.framework
- Next , Let's separate ( stay Mac The terminal carries out ) Delete the three parts mentioned above .
- The first 1 Step , Delete frame :
sudo rm -rf /Library/Frameworks/Python.framework/Versions/x.x
- The first 2 Step , Delete application directory :
sudo rm -rf "/Applications/Python x.x"
- The first 3 Step , Delete pointing to Python The connection of :
cd /usr/local/bin/
ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/x.x' | awk '{print $9}' | tr -d @ | xargs rm
3 cookiecutter
# Download and install
pip install cookiecutter
cookiecutter https://github.com/mtooooo/cookiecutter-flask.git
# Install dependency packages
pip install -r myflaskapp\requirements\dev.txt
pip install -r myflaskapp\requirements\prod.txt
# Start mode 1
if __name == '__main__':
app.run()
# Start mode 2
cd myflaskapp
flask run
# After starting , visit http://127.0.0.1:5000
# Database configuration README.rst file
set FLASK_APP=/path/to/autoapp.py
set FLASK_DEBUG=1
flask db init
flask db migrate
flask db upgrade
flask run
# Restart and try to register the service
Copy code
4 Virtual environment management poetry
# install
pip install poetry
# Use poetry Package management
poetry install
# Start the service
poetry run flask run
# pack wheel file
poetry build
Copy code
5 fabfile Code push service
fabfile.py
from fabric import task
@task
def upload_and_unpack(c):
if c.run('test -f /opt/mydata/myfile', warn=True).failed:
c.put('myfiles.tgz', '/opt/mydata')
c.run('tar -C /opt/mydata -xzvf /opt/mydata/myfiles.tgz')
Copy code
- Available tasks :
$ fab --list
Available tasks:
upload_and_unpack
Copy code
- When
fab
When a single server invokes a task :
$ fab -H web1 upload_and_unpack
Copy code
- Multiple hosts , The host runs tasks more than once , Every time
Connection
Submit different instances :
$ fab -H web1,web2,web3 upload_and_unpack
Copy code
copyright notice
author[A nine barrel spring],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202011120402759.html
The sidebar is recommended
- Python from 0 to 1 (day 14) - Python conditional judgment 1
- Several very interesting modules in Python
- How IOS developers learn Python Programming 15 - object oriented programming 1
- Daily python, Chapter 20, exception handling
- Understand the basis of Python collaboration in a few minutes
- [centos7] how to install and use Python under Linux
- leetcode 1130. Minimum Cost Tree From Leaf Values(python)
- leetcode 1433. Check If a String Can Break Another String(python)
- Python Matplotlib drawing 3D graphics
- Talk about deep and shallow copying in Python
guess what you like
-
Python crawler series - network requests
-
Python thread 01 understanding thread
-
Analysis of earthquake distribution in the past 10 years with Python~
-
You need to master these before learning Python crawlers
-
After the old friend (R & D post) was laid off, I wanted to join the snack bar. I collected some data in Python. It's more or less a intention
-
Python uses redis
-
Python crawler - ETF fund acquisition
-
Detailed tutorial on Python operation Tencent object storage (COS)
-
[Python] comparison of list, tuple, array and bidirectional queue methods
-
Go Python 3 usage and pit Prevention Guide
Random recommended
- Python logging log error and exception exception callback method
- Learn Python quickly and take a shortcut~
- Python from 0 to 1 (day 15) - Python conditional judgment 2
- Python crawler actual combat, requests module, python to capture headlines and take beautiful pictures
- The whole activity collected 8 proxy IP sites to pave the way for the python proxy pool, and the 15th of 120 crawlers
- Why can't list be used as dictionary key value in Python
- Python from 0 to 1 (day 16) - Python conditional judgment 3
- What is the python programming language?
- Python crawler reverse webpack, a real estate management platform login password parameter encryption logic
- Python crawler reverse, a college entrance examination volunteer filling platform encrypts the parameter signsafe and decrypts the returned results
- Python simulated Login, selenium module, python identification graphic verification code to realize automatic login
- Python -- datetime (timedelta class)
- Python's five strange skills will bring you a sense of enrichment in mastering efficient programming skills
- [Python] comparison of dictionary dict, defaultdict and orderdict
- Test driven development using Django
- Face recognition practice: face recognition using Python opencv and deep learning
- leetcode 1610. Maximum Number of Visible Points(python)
- Python thread 03 thread synchronization
- Introduction and internal principles of Python's widely used concurrent processing Library Futures
- Python - progress bar artifact tqdm usage
- Python learning notes - the fifth bullet * class & object oriented
- Python learning notes - the fourth bullet IO operation
- Python crawler actual combat: crawl all the pictures in the answer
- Quick reference manual of common regular expressions, necessary for Python text processing
- [Python] the characteristics of dictionaries and collections and the hash table behind them
- Python crawler - fund information storage
- Python crawler actual combat, pyteseract module, python realizes the visualization of boos direct employment & hook post data
- Pit filling summary: Python memory leak troubleshooting tips
- Python code reading (Chapter 61): delaying function calls
- Through the for loop, compare the differences between Python and Ruby Programming ideas
- leetcode 1606. Find Servers That Handled Most Number of Requests(python)
- leetcode 1611. Minimum One Bit Operations to Make Integers Zero(python)
- 06python learning notes - reading external text data
- [Python] functions, higher-order functions, anonymous functions and function attributes
- Python Networkx practice social network visualization
- Data analysis starts from scratch, and pandas reads and writes CSV data
- Python review (format string)
- [pandas learning notes 01] powerful tool set for analyzing structured data
- leetcode 147. Insertion Sort List(python)
- apache2. 4 + windows deployment Django (multi site)