Install Django in a pipenv virtual environment

Overview

This article walks you through the steps of a beginner developing a coupon distribution service for the iPhone with a RESTful API and swift. It is a very detour implementation because it was implemented while examining the technical elements one by one.

Nowadays, development using framework is commonplace. In the case of Python, a framework called "Django" is often used. The framework makes programming easier, as you can use Django to implement what would normally be done in a complex line program in one line.

There are many ways to install Django, but this time I'll summarize how to use a tool called pipenv. pipenv is a tool to create and manage a virtual environment (called a project) in which python runs. By creating a virtual environment instead of building an environment directly on a computer, one computer can use multiple environments properly.

reference

https://qiita.com/anvinon/items/5d9c128ef8b65b866dfe https://qiita.com/nochifuchi/items/4fe0164f0d8949cf11b7

environment

MacOS 10.15 Homebrew 2.1.15 Fixed internet connection

Work procedure

install pipenv

Just in case, check if pipenv is already installed by running the command to display the version of pipenv.

$ pipenv --version

If you see the message "-bash: pipenv: command not found", pipenv is not installed.

From here, use Homebrew to install pipenv. If you have not installed Homebrew, please install it first.

$ brew install pipenv

Installation is complete when a display like this appears. The installation was completed in a minute or two in my environment. pipenv-installed-m.png

Execute the version check command earlier to check the version of pipenv installed. I have installed version 2018.11.26 in my environment.

Create a python virtual environment with pipenv

First, create a directory to create a virtual environment. You will create and execute programs under that directory. If you want to use various types of environments, you can do it by using different directories.

To create a directory, use the following command. You can create it in Finder.

$ mkdir [Directory path]

Move to the directory created in the terminal and build the pipenv virtual environment (project) with the following command. I built the environment in a directory called "amiApp".

$ pipenv install
pipenv-install-m.png

Let's check the contents of the directory here. Here is the command to display the files and directories in the directory.

$ ls

Then, the files "Pipfile" and "Pipfile.lock" are created. Pipfile is

Pipenv A dedicated file used by the virtual environment to manage project dependencies

... apparently ... Looking at the contents of the Pipfile, it looks like this. It seems to be a file that manages the configuration of packages and the like. And in the place of [requires], there is a notation of python_version = "3.7". It seems that python will be installed at the same time when the virtual environment of pipenv is created.

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]

[requires]
python_version = "3.7"

By the way, to create a virtual environment with the specified python version, execute the command as follows.

$ pipenv --python [Version number]

Now that you have a virtual environment to run python and Django, install Django. Django is a package, so installing it should add Django to the [packages] section of your Pipfile.

Install Django in a pipenv virtual environment

You can install django with the following command.

$ pipenv install django

If you check the contents of the Pipfile again, you will find Django in [packages].

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
django = "*"

[requires]
python_version = "3.7"

This completes the installation of Django in the pipenv virtual environment.

Next time, I'll run the Django code in the environment I created this time

Recommended Posts

Install Django in a pipenv virtual environment
Start Django in a virtual environment with Pipenv
Try running python in a Django environment created with pipenv
[Django3] Display a web page in Django3 + WSL + Python virtual environment
Creating a virtual environment in an Anaconda environment
Install CaboCha in a non-Anaconda environment (Win)
I started Node.js in a virtual environment
python virtual environment Pipenv
virtual environment in python
Ubuntu18.04.05 Creating a python virtual environment in LTS
Create a virtual environment with conda in Python
Build a Django environment with Vagrant in 5 minutes
Work in a virtual environment with Python virtualenv.
A memo to create a virtual environment (venv) before Django
Collaborate in a remote environment
Pip install in proxy environment
Create a Django project and application in a Python virtual environment and start the server
Build a Python virtual environment using venv (Django + MySQL ①)
Building a Python virtual environment
(Note) Django in Vagrant environment
Building a Python virtual environment
Build a Django environment for Win10 (with virtual space)
A note on how to load a virtual environment in PyCharm
How to develop in a virtual environment of Python [Memo]
Install scrapy in python anaconda environment
Create a virtual environment with Python!
Building a virtual environment with Python 3
install tensorflow in anaconda + python3.5 environment
Create a LINE Bot in Django
Django cannot be installed in the development environment of pipenv + pyenv
[Understanding in the figure] Management of Python virtual environment by Pipenv
From installing Ansible to building a Python environment in Vagrant's virtual environment
Install Django
Debug settings in virtual environment when using Pipenv with VS Code
CSS environment created in 10 minutes using Django
Building a virtual environment using homebrew + pyenv-virtualenv
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
[Mac] Building a virtual environment for Python
Creating a python virtual environment on Windows
Create a virtual environment with Python_Mac version
Set up Pipenv in Pycharm in Windows environment
Dynamically specify a ModelChoiceField queryset in Django
Build a python virtual environment with pyenv
Install rJava on Linux in R3.6 environment.
Implement a Custom User Model in Django
[mac] Install R in pyenv + Jupyter-Lab environment
Install the package in an offline environment
Add a Python virtual environment to VSCode
Use WebDAV in a Portable Docker environment
Steps to install CentOS 8.1 in Virtual Box
(For myself) Flask_AWS_1 (Install PHP, MySQL, phpMyAdmin, Python in AWS virtual environment)
How about creating a virtual environment with Anaconda and doing pip install?
When you make a mistake in the directory where you execute `pipenv install`
How to install python package in local environment as a general user
Until you can step in PyCharm + Django + virtual environment (pyvenv + Python3) (mac)
A story when a directory is buggy with the django-admin start project command in a virtual environment using Pipenv
Django environment construction
Build a LAMP environment in a very short time
Create a Vim + Python test environment in 1 minute
How to share a virtual environment [About requirements.txt]