- Install pipenv
pip install pipenv
- Create a directory say
hello
where you are going to create your python project. - Go inside the directory
cd hello
- Create a virtual env using command
pipenv --python 3.7
(Specify which version of python you need) - Alternative to 4 enter command
pipenv shell
. This case pipenv will use whatever default virtualenv finds.
This will create Pipfile and Pipfile.lock
- Install packages you need, say numpy
pipenv install numpy
After every required pakage installed and the python project functions as required and you’re ready to push it to production. Then, you need to lock your environment so you can ensure you have the same one in production
- Enter
pipenv lock
After you et your code and Pipfile.lock in your production environment, you should install the last successful environment recorded
- Enter
pipenv install --ignore-pipfile
- Note if dependency is only for development (not for production) then install with the --dev argument, say pytest
pipenv install pytest --dev
- Pipfile looks like
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"
[dev-packages]
pytest = "*"
[packages]
numpy = "*"
[requires]
python_version = "3.7"
- Pipfile.lock
{
"_meta": {
...
},
"default": {
"numpy": {
"hashes": [
"sha256:6c3130c8927109a08225993e4e503de4ac4f2678678ae211b33b519c622a7242",
"sha256:9dce4b6bfbb5b062181d3f7da8f727ff70c1156cbb4024351eafd426deb5fb88"
],
"version": "==0.12.1"
},
...
},
"develop": {
"pytest": {
"hashes": [
"sha256:8970e25181e15ab14ae895599a0a0e0ade7d1f1c4c8ca1072ce16f25526a184d",
"sha256:9ddcb879c8cc859d2540204b5399011f842e5e8823674bf429f70ada281b3cc6"
],
"version": "==3.4.1"
},
...
}
}
- Uninstall a package
pipenv uninstall numpy
- Find your virtual environment
pipenv --venv
- Find more pipenv commands
pipenv --help
- More detail info go pipenv-introduction
- Check Pipenv