Environment configuration

Install pyenv:

Execute the following command in the terminal to install pyenv and its plugins:

 

curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash

 After the installation is complete, follow the prompts and add the following statements to  ~/.bashrc it:

 

 

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

 Then restart the terminal.  

 

 

 install python

 

View Installable Versions

 

pyenv install --list

 Install Python dependencies

 

 

sudo apt-get update
sudo apt-get install make build-essential libssl-dev zlib1g-dev
sudo apt-get install libbz2-dev libreadline-dev libsqlite3-dev wget curl
sudo apt-get install llvm libncurses5-dev libncursesw5-dev

 Install the specified version

 

Users can use to  pyenv install install the specified version of python. If you don't know which one to use, it is recommended that you install the latest version of anaconda3, a distribution designed for scientific computing.

 

$pyenv install anaconda3-4.1.0 -v
/tmp/python-build.20170108123450.2752 ~
Downloading Anaconda3-4.1.0-Linux-x86_64.sh...
-> https://repo.continuum.io/archive/Anaconda3-4.1.0-Linux-x86_64.sh

 After executing the command, the installation file will be downloaded from the given URL  Anaconda3-4.1.0-Linux-x86_64.sh. But due to the size of the file, it usually takes a long time to download. The recommended practice is to execute the above command first and then abort the installation immediately, so that you know the link to the file that pyenv wants to download. Then the user downloads the installation file from the link in other faster ways (such as wget, Thunder, etc.), and moves the installation file to the  ~/.pyenv/cache directory (this directory does not exist by default, and the user must create it by himself).

 

Take the situation mentioned in this article as an example:

  1. Execute  pyenv install anaconda3-4.1.0 -v to get download link
  2. Get file from download link with wget Anaconda3-4.1.0-Linux-x86_64.sh
  3. Move the installation package to ~/.pyenv/cache/Anaconda3-4.1.0-Linux-x86_64.sh
  4. Re-execute the  pyenv install anaconda3-4.1.0 -v command. This command will check the integrity of the existing files in the cache directory. If it is confirmed to be correct, the installation file will be used directly for installation.
  5. During the installation process, if a compilation error occurs, it is usually because the dependency package is not satisfied. You need to re-execute the command after installing the dependency package.

update database

After installing Python or other modules with executables, the database needs to be updated:

pyenv rehash

 

View currently installed python version

 

$ pyenv versions
* system (set by /home/seisman/.pyenv/version)
anaconda3-4.1.0

 

 

use python

  • Enter  python to use the new version of python;
  • The script that comes with  /usr/bin/python the system will directly call the old version of python in this way, so it will not affect the system script;
  • When using  pip and installing third-party modules, it will automatically follow the current python version and will not conflict with system modules.
  • After using the  pip installation module, it may be necessary to perform an  pyenv rehash update database;

Install Django under ubuntu

1. Install pip first

sudo apt-get install python-pip

 install django

sudo pip install Django==1.8.16

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326292918&siteId=291194637