Offline deploy Django project to migrate to non-network environment

 

Existing environments

  • CentOS 7
  • Python 3.7
  • Django 2.1

Mainly used in the following three commands:

# Export dependence 
PIP Freeze> requirements.txt  
 # accordance dependent offline download package 
 PIP downloads -d packagesDir - R & lt requirements.txt     
 # installation package offline 
whl package, tgz package
Single package, the package directory
pip install --no-index --find-links="packages_dir" -r requirements.txt

Prepare in advance

(1) requirements.txt dependencies pip freeeze> requirements.txt

(2) offline download package (pit)
Download Command: pip download -d / dir / of / packagesDir -r requirements.txt

Note that the following two very crucial! ! ! ! :

Must pay attention to the platform, windows offline download offline package only applies to windows, macOS, Linux empathy.
CentOS CentOS 6 and 7 are not the same. The former offline download package is not applicable to the latter, otherwise offline when installation error.
Corresponding to the above two points, then the offline download package, and then transferred to a machine within the network.

Offline host installation Python3

Because the system comes with a Python2.6, but to install Python3 applicable, and can not cover the installation Python2.

Has been tested, and then install Python3 applicable command python3 manage.py runserver, there will be a series of problems. Thus using the tool mounting pyenv different Python interpreter, where the installation Python3 ..

Here tripped installation steps pyenv, assuming that already use pyenv installed on Python3.

Offline installation package

Offline package directory: offlinePackages
install command: pip install --no-index --find- links = "offlinePackages" -r requirements.txt

To complete the offline installation package needs of the project, followed by normal use of similar django-admin commands.
Finally, the need to modify the django configuration files, database password server ip and so on.

other

  • Venv virtual directory tried to pass a package, then  source /venv/bin/active it does not work, or the above method to solve the problem.
  • There must be a Python interpreter exists, otherwise after the virtual directory is also used to activate accomplished.

Annex: offline installation method pyenv

There are a host on the network to download
1, using this command is mainly lazy, easy to use: curl https://pyenv.sh | bash, This afforded .pyenv directory, which is directory pyenv tools, the follow-up needs to be packaged directory, and transferred to a non-network host.

2, there are still a host on the network, write pyenv environment variables:

    Echo $ ' Export PYENV_ROOT = "$ the HOME / .pyenv" ' >> ~ / .bashrc      # then need to modify the environment variable, using the input Bash Shell 
    $ echo ' Export the PATH = "$ PYENV_ROOT / bin: the PATH $" ' >> ~ / .bashrc
    $ echo 'eval "$(pyenv init -)"' >> ~/.bashrc

3, want to install the Python version, such as 3.6.5:

pyenv install 3.6.5

4, if the error, and that is not dependent on a number of system-level installed, you can try these (in fact, is to install Python dependencies):

yum -y install zlib zlib-devel
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install readline readline-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel
yum -y install gcc

 

5, the installation is successful, the package directory pyenv: tar -czf pyenv.tgz .pyenv, and then uploaded to the free web host installation. Note that with a good pyenv environment variable.

(I write to you, I can find another idea to use offline installation: After pyenv installed, you want to switch directly to the Python version, this time also corresponds to switch pip, then use pip installed directly inside requiremans.txt package, because these packages are installed in .pyenv directory and then directly upload package to install non-network machine but the disadvantage is: pre-installed package is global, if follow-up is also installed new, other version of the package, can lead to confusion, so you have to ensure that the current pyenv is to use a fixed version of the package case.

No troubles practice:
1, using pyenv switch Python version;
2, create a virtual directory;
3, activation virtual directory;
4, install the offline package - this time, off-line package is installed to isolate the environment inside, but also local of the package.


----------------
Disclaimer: This article is the original article CSDN bloggers "GeezKe", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/Kohang/article/details/95631208



Guess you like

Origin www.cnblogs.com/wangcongxing/p/12362881.html