Configure a Pipenv environment
Pipenv is a tool that provides all necessary means to create a virtual environment for your Python project. It automatically manages project packages through the Pipfile file as you install or uninstall packages.
Pipenv also generates the Pipfile.lock file, which is used to produce deterministic builds and create a snapshot of your working environment. This might be particularly helpful for security sensitive deployment, when project requirements and packages versions are critical. For more details about pipenv, see project documentation at pipenv.pypa.io.
To use Pipenv with DataSpell, you need to implement several preparation steps.
Install Pipenv
Run the following command to ensure you have pip installed in your system:
$ pip --version
You should expect to receive a system response indicating the pip version. If no pip is discovered, install it as described in the Installation Instructions. Alternatively, you can download and install Python from http://python.org.
Install
pipenv
by running the following command:$ pip install --user pipenv
When installation completes, you will see the following message:
For your convenience, you might add the user base’s binary directory to your
PATH
environmental variable. If you skip this procedure, DataSpell will prompt you to specify the path to the pipenv executable when adding a pipenv environment.Run the following command:
$ py -m site --user-site
A sample output can be:
C:\Users\jetbrains\AppData\Roaming\Python\Python37\site-packages
Replace
site-packages
withScripts
in this path to receive a string for adding to thePATH
variable, for example:$ setx PATH "%PATH%;C:\Users\jetbrains\AppData\Roaming\Python\Python37\Scripts"
Run the following command to find the user base's binary directory:
$ python -m site --user-base
An example of output can be
/Users/jetbrains/.local (macOS) or /home/jetbrains/.local (Linux)
Add bin to this path to receive a string for adding to the ~/.bashrc file, for example:
$ export PATH="$PATH:/Users/jetbrains/.local/bin"
Run the following command to make the changes effective:
$ source ~/.bashrc
Ensure you have enabled bashrc in your bash_profile.
At any time you can alter the specified path to the pipenv executable in the project settings. In the Settings dialog (Control+Alt+S), navigate to , and type the target path in the Path ot Pipenv executable field.
After the preparation steps are done, you can use pipenv to create a virtual environment for new or existing projects.
You can also set up pipenv for any of your earlier created projects.
Configure pipenv for an existing Python project
Do one of the following:
Press Control+Alt+S to open Settings and go to . Click the Add Interpreter link next to the list of the available interpreters.
Click the Python Interpreter selector and choose Interpreter Settings. Click the Add Interpreter link next to the list of the available interpreters.
In the context menu of an attached directory, select Interpreter.
Select Add Local Interpreter.
In the left-hand pane of the Add Python Interpreter dialog, select Pipenv Environment.
Choose the base interpreter from the list, or click and find the desired Python executable in your file system.
If you have added the base binary directory to your
PATH
environmental variable, you don't need to set any additional options: the path to the pipenv executable will be autodetected.If the pipenv executable is not found, follow the pipenv installation procedure to discover the executable path, and then paste it in the Pipenv executable field.
Click OK to complete the task.
Once all the steps are done, the new pipenv environment is set for your project and the packages listed in the Pipfile are installed.
If you open a project with a Pipfile file added but no any interpreter configured, DataSpell offers you to use Pipenv environment.
If you select this option, DataSpell sets pipenv for you automatically. Alternatively, you can click Configure Python interpreter to follow the standard workflow.
Similarly, when you open a project with a Pipfile file in DataSpell for the very first time, for example, by checking it out from the Version Control, the Pipenv virtual environment will be configured automatically.
When you have set the Pipenv virtual environment as a Python interpreter, all available packages are added from the source defined in Pipfile . The packages are installed, removed, and updated in the list of the packages through pipenv rather than through pip.