[PYTHON] I tried using pipenv, so a memo

Overview

Try various things with pipenv

1. Install.

pipenv can be installed with pip. Install by executing the following command as usual.

$ pip install pipenv

2. Try using pipenv for the time being

$ mkdir test1      #Creating a verification directory
$ cd test1         #Move to verification directory
$ pipenv install   #Create virtual environment and Pipfile
$ ls -a
.		..		.venv		Pipfile		Pipfile.lock

After executing pipenv, you can see that Pipfile, Pipfile.lock and .venv that stores the virtual environment settings are created. When you install the package as described below, that information is written to the Pipfile.

To switch the Python version, execute the following command

$ pipenv shell

3. Install the package for the created environment.

You can install the package in the virtual environment you created with pipenv install [package]. You can specify the version of the package or omit it. If omitted, the latest version will be retrieved as with pip.

$ pipenv install nose==1.3.7  #Install packages for virtual environment
$ pipenv shell
$ (test1)(test1) python
>>> import nose
>>> exit()
$ python
>>> import nose     #Make sure it is installed only in the virtual environment
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named nose
>>> exit()
$ (test1)(test1) exit  #Get out of the virtual environment
$cat Pipfile        #Check the Pipfile
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true

[packages]          # new!!!
nose = "==1.3.7"

4. Try building a virtual environment and installing packages using the predefined Pipfile

$ cd .. && mkdir test2 && cd test2  #Create directory for verification&Move
$ ls -a
.	.. 
$ pipenv run python      #Synonymous with entering a virtual environment and running python
>>> import nose
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named nose
>>> exit()

$ cp ../test1/Pipfile .  #Bring in a predefined Pipfile
$ pipenv install         #Create virtual environment and install packages
$ ls -a
.		..		.venv		Pipfile		Pipfile.lock
$ pipenv run python
>>> import nose
>>> exit()

Remarks: Run pipenv by version

Specify the version in detail

You can now specify the Python version directly. If you do not specify anything, it seems that the latest stable version will be included.

$ pipenv --python <Python version>

If you want to enter in 3.6.2, you can write as follows. You can also specify 3.6. In that case, the x.y.z part will be up-to-date.

$ pipenv --python 3.6.2

Specify whether it is 2 system or 3 system

You can specify the version with the following command and execute it. If you want to create a 2nd or 3rd system environment for the time being, this specification may be sufficient.

$ pipenv --two #Create a 2 system environment
$ pipenv --three #Create a 3 system environment

When The'python3' command exists in these Python versions appears

I encountered it at the time of release. Since I had installed multiple versions of 2 and 3 with pyenv, the following message was displayed and the process was interrupted. There are multiple versions of the 3 series, and they provide information that the target cannot be narrowed down to one. The same applies to the 2nd system.

$ pipenv --three
Creating a virtualenv for this project...
pyenv: python3: command not found
The `python3' command exists in these Python versions:
  3.4.2
  3.4.3

In this case, you can solve it by specifying the version with pyenv local [version] etc., but is this really all right? If you initialize it with pyenv install, it seems that it refers to the version of system (unrelated to pyenv), and in that case, of course, the above error does not occur.

Recommended Posts

I tried using pipenv, so a memo
I tried using Pipenv
I tried drawing a line using turtle
I tried using parameterized
I tried using argparse
I tried using mimesis
I tried using anytree
I tried using aiomysql
I tried using Summpy
I tried using coturn
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using openpyxl
I tried using Ipython
I tried using PyCaret
I tried using cron
I tried using ngrok
I tried using face_recognition
I tried using PyCaret
I tried using Heapq
I tried using doctest
I tried using folium
I tried using jinja2
I tried using folium
I tried using time-window
I tried using Pythonect, a dataflow programming language.
I tried reading a CSV file using Python
I tried using a database (sqlite3) with kivy
I tried to make a ○ ✕ game using TensorFlow
When I tried to scrape using requests in python, I was addicted to SSLError, so a workaround memo
[I tried using Pythonista 3] Introduction
I tried using Random Forest
I tried using BigQuery ML
I tried hosting a Pytorch sample model using TorchServe
I tried using Amazon Glacier
I stumbled upon using MoviePy, so make a note
I tried using git inspector
[Python] I tried using OpenPose
[Python] I tried running a local server using flask
I tried drawing a pseudo fractal figure using Python
I tried using magenta / TensorFlow
I tried reading data from a file using Node.js.
I tried using Python (3) instead of a scientific calculator
PyTorch Learning Note 2 (I tried using a pre-trained model)
I tried using AWS Chalice
I tried to draw a configuration diagram using Diagrams
I tried using Slack emojinator
I want to collect a lot of images, so I tried using "google image download"
I tried hosting a TensorFlow deep learning model using TensorFlow Serving
I tried using Tensorboard, a visualization tool for machine learning
I tried to automate [a certain task] using Raspberry Pi
I tried to make a stopwatch using tkinter in python
I tried to make a simple text editor using PyQt
I tried using Rotrics Dex Arm # 2
I made a Line-bot using Python!
I tried using Rotrics Dex Arm
I tried using GrabCut of OpenCV
I tried using Thonny (Python / IDE)
I tried server-client communication using tmux
I tried reinforcement learning using PyBrain