It harnesses Pipfile, pip, and virtualenv into one single toolchain.
pipenv can be installed with pip. Install by executing the following command as usual.
$ pip install pipenv
$ 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
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"
$ 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()
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
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
The'python3' command exists in these Python versions
appearsI 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