python rely on database management and migration

python rely on database management and migration

Why

python package particularly large, this is handy for us also caused unchanged, the main questions are as follows:

  1. When developing environmental transport, we want all of the existing installation packages to install it again on the new machine;
  2. Changes in the larger package has been installed in the subsequent updates that may affect existing code. Hope can be performed in a different environment.

What

There are currently three python dependencies management:

  1. Conda , I believe we no stranger to anaconda;
  2. PIP , management of third-party libraries;
  3. Docker , containerization is now a program very fire. docker container collapse will not affect the host, and portability is very strong environmental image can be easily transplanted to up to a different host environment without the need to reconfigure the installation. (First dig a hole here, after the new East etc. God to teach again supplement)
  4. virtualenv is a tool to build custom virtual environment for python, python versions can be specified in a virtual environment and use pip install to activate the virtual environment;

How

Use conda and problems

Pack away his own environment, to note that conda need exactly the same environment.
For example, I built a virtual environment python2.7 in the local, the address in

/Users/shang/anaconda3/envs/py27

You can look at bin/pipwhat is in the file

#!/Users/shang/anaconda3/envs/py27/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from pip._internal import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

Notes that the first line, is designated pythonpath, but also the absolute path , if done environments migrating between servers, should be able to do the same to ensure the path, such as are

/home/work/software/anaconda3/envs/py27/bin/python

Use pip

This method is relatively simple table use is to first know what the package was originally installed, and then install it again in a new environment. This is good, better than run again .pygood document to report a wrong way to install a package ==

pip freeze > requirements.txt  #获得依赖包
pip install -r requirements.txt #安装依赖包

Note: pip freeze output is that all three parties packet information in the local environment, but will be less than a few packages pip list, because the pip, wheel, setuptools package, etc., are built-in and can not be (un) install, if you want to display all package can add parameters -all, i.e. pip freeze -all

Use docker

to be continued

Published 120 original articles · won praise 35 · views 170 000 +

Guess you like

Origin blog.csdn.net/u012328476/article/details/83653166