In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use pyenv to build Django environment on CentOS7, which is very detailed and has certain reference value. Friends who are interested must read it!
What is pyenv? What can I do? Pyenv is a simple, low-key, UNIX-based forked environment management tool from the ruby community. It can easily switch between global interpreter versions and manage corresponding package sources with vitualenv plug-ins.
Pyenv can easily download the specified python version, and you can easily switch to the required python environment in the current directory, global environment, and current shell. Let's take a look at the introduction to pyenv on GitHub. Pyenv is also recommended for python's virtual environment. Switching is very convenient and does not have to be as troublesome as virtualenv or other virtual environments.
2. How to install and use pyenv 2.1.This is actually installed on CentOS7.3. It is recommended to use the official recommended Automatic installer method to install it. It is very easy to install and the way is relatively fast.
Yum install gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-develcurl-L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
Add the following to / etc/bash_profile
Export PATH= "/ home/python/.pyenv/bin:$PATH" eval "(pyenv init -)" eval "(pyenv virtualenv-init -)" source / etc/bash_profile2.2 We can use the command to check which versions pyenv supports downloading and installing.
Pyenv install-l
According to the version we need, we can install the python version. This time, take installing python 3.9.2 as an example.
Pyenv install 3.9.2 (a network is required. The process will download the python version from the python official website and then compile and install it by itself, so the actual time of the process depends on the network time and host CPU performance)
After the installation is complete, you can use pyenv versions to view the python version on the current system
Next, we begin to set the pythen version. Setting the python version has a total of three environments to choose from
Pyenv global 3.9.2 / system overall switch to python3.9.2 version pyenv shell 3.9.2 / current shell session switches to python3.9.2 version pyenv local 3.9.2 / / switch to python3.9.2 version within the current directory path We install using django, of course, to create a separate directory, using this directory to store projects So we create a project directory, use pyenv local 3.9.2, and set the version of the current directory to python3.9.2
Third, what is DjangoDjango there are too many documents and blogs to explain, here is less nonsense, a general introduction, specific words to see other people's blog or official website. Django is a popular and fully functional server-side website framework written in the Python language, built by experienced developers, and Django handles the troublesome parts of website development, so you can focus on writing applications without having to redevelop them. It is free and open source, with an active and prosperous community, rich documentation, and many free and paid solutions.
According to the content on the official website, we can see that the iterative speed of Django is relatively fast, so it is recommended to choose a long-term and stable version. This installation uses version 3.2.8, which has a relatively long maintenance cycle and is relatively stable and reliable.
4. Django installation and setup 4.1 We have already installed pyenv before installation, so it will be much easier to install django, just use the pip command to install it (note that you need to use pip3 installation in the project directory above, otherwise there will be problems with the pip2 installation of the system by default)
After the installation is complete, we need to update the database in the pyenv environment, and then we can use the relevant commands of django
After the completion of pyenv rehash, we use django-related commands to find errors and do not expect sqlite3-related modules. This is because django has a version requirement for sqlite (the lower version of django may not be available), because we also need to update the version of sqlite on CentOS7.3.
Cd / tmp/projectdjango startproject HelloDjangopython manager.py startapp App
Therefore, we need to update the sqlite of the system to a higher version 3.9, and this time to version 3.36. First, go to the sqlite official website to download the corresponding version compilation and installation. CentOS selects the autoconf version to compile and install. The compilation time depends on the CPU performance of the system.
Tar zxvf sqlite-autoconf-3360000.tar.gz
After successful installation, you need to change the default version of sqlite on the system to the version we compiled, so you need to do the following
Mv / usr/bin/sqlite3 / usr/bin/sqlite3_oldln-sv / usr/local/bin/sqlite3 / usr/bin/sqlite3sqlite3-- version export LD_LIBRARY_PATH= "/ usr/local/lib" sets the environment variable
4.2 We can see that sqlite3 has been updated to our higher version, so there will be no problem running the django command again.
Django-admin startproject HelloDjango creates a project called HelloDjango. In the cd HelloDjango python manage.py startapp App HelloDjango project, create an App application and enter it into HelloDjango. We modify the host allowed to be accessed in the settings.py file. If we do not modify it, only 127.0.0.1 local loopback address is allowed by default, which is meaningless for our web application. Therefore, we need to change the host allowed by ALLOWED_HOSTS by default to "*".
Then we start the first django service.
Python manage.py. Runserver. 0.0.0.0 8000 opens port 8000 of all addresses on this machine
Then use the browser, enter our local address plus port number 8000 in the browser to complete the access, and the installation ends here.
Http://xxx.xxx.xxx.xxx:8000
These are all the contents of the article "how to use pyenv to build a Django environment on CentOS7". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.