pipenv. highly recommended! ! !
At present, when creating a project, it is bound to install a virtual environment to avoid conflicts of dependent packages. The four types of virtualenv, conda, python -m venv, and pipenv find pipenv the most convenient.
- Installation, we default to the installed python3 version
pip install pipenv
2. Create a virtual environment in the specified directory, will use the local default version of python
mkdir venv001
cd venv001
pipenv install
If you want to specify the version creation environment, you can use the following command, of course, the premise is that the local startup directory can find the version of python
pipenv --python 3.6
- Activate the virtual environment
pipenv shell
- Install a third-party module, and it will generate Pipfile and Pipfile.lock files after running
pipenv install django==2.2
Of course, you can not specify the version:
pipenv install django
If you want to install only the packages used in the development environment, do this:
pipenv install pytest --dev
Both the production environment and development environment packages will be written into a Pipfile, and if the traditional method is used, two files are required: dev-requirements.txt and test-requirements.txt
Next, if the development environment has been completed, how to build the production environment? At this time, it is necessary to use Pipfile.lock. Run the following command to lock the current environment module. It will update the Pipfile.lock file. This file is for production environment. You should never edit it.
pipenv lock
Then you only need to put the code and Pipfile.lock into the production environment, and run the following code to create the same environment as the development environment. Pipfile.lock records the exact versions of all packages and sub-dependent packages, so it is determined to build:
pipenv install --ignore-pipfile
If you want to do development in another development environment, copy the code and Pipfile and run the following command:
pipenv install --dev
Use the following command to view the dependencies:
pipenv graph
- Pipenv's other instructions to
uninstall the package
pipenv uninstall numpy
Current virtual environment directory
pipenv --venv
Current project root directory
pipenv --where