PS C:\Users\gwill\OneDrive\Documents\new luno\Luno10> pip install dotenv Fatal error in launcher: Unable to create process using '"C:\Users\gwill\AppData\Local\Programs\Python\Python310\python.exe" "C:\Users\gwill\AppData\Local\Programs\Python\Python310\Scripts\pip.exe" install dotenv': The system cannot find the file specified.
CodePudding user response:
It should be pip install python-dotenv
.
CodePudding user response:
TL;DR;
Step by step
In the project folder type:
Step | Command-Line Linux/macOS | Command-Line Windows | Description |
---|---|---|---|
1. | python3 -m venv .venv |
python -m venv .venv |
Creates the virtual env (in this case the .venv folder) |
2. | . ./.venv/bin/activate (bash/zsh) . ./.venv/bin/activate.fish (fish shell) |
.venv\Scripts\activate.bat (cmd.exe) .venv\Scripts\Activate.ps1 (Powershell) |
Activates it |
3. | pip install dotenv |
pip install dotenv |
Installs a 3rd party package (in this case dotenv ) |
4. | python script.py |
python script.py |
Runs the script (in this case script.py ) |
3. | deactivate |
deactivate |
Deactivates it |
What is a Virtual Environment?
By default, Python installs 3rd-party packages on the System Site Directories. And in most cases, this even requires admin privileges like sudo
(Linux/macOS) or Run as Administrator
(Windows).
The System Site Directories is the default environment for the installed Python. It's global for all the projects being worked on on the same system.
So, installing the requirements/3rd-party packages from each project on the System Site Directories is going to pollute it. And worse, it could clash versions of the same module dependency between different projects. And could make projects completely unrunnable.
That's why Virtual Environments exist in the first place. The Virtual Environment is a completely separate Site Directories from the System Site Directories and is (should be) exclusive to the project being developed at the moment. The project itself is going to be totally isolated from other Virtual Environments. And even the Python binaries are going to be copied/sym-linked into the Virtual Environment.
Creating Virtual Environments
Adapted from the official documentation:
Since Python 3.3 it's possible to create a Virtual Environment with the standard venv
module that comes preinstalled with Python already (Before, the standard way was to use the virtualenv
package).
The creation of Virtual Environments is done by executing the command venv
:
Linux/macOS
python3 -m venv .venv
Windows
python -m venv .venv
Running this command creates:
- The target directory (
.venv
in this case); - The
.venv/bin
folder (or.venv\Scripts
on Windows) containing a copy/sym-link of the Python binary/binaries; - The Virtual Site Directories (initially empty):
.venv/lib/pythonX.Y/site-packages
folder (on Windows, this is.venv\Lib\site-packages
).
Activating a Virtual Environment
Once a virtual environment has been created, it can be “activated” using a script in the virtual environment’s binary directory. The invocation of the script is platform-specific:
Platform | Shell | Command to activate the Virtual Environment |
---|---|---|
POSIX | bash/zsh | source .venv/bin/activate |
fish | source <venv>/bin/activate.fish |
|
csh/tcsh | source <venv>/bin/activate.csh |
|
PowerShell Core | .venv/bin/Activate.ps1 |
|
Windows | cmd.exe | .venv\Scripts\activate.bat |
PowerShell | .venv\Scripts\Activate.ps1 |
As soon as the Virtual Environment is active, every install with pip
is going to install on the Virtual Environment, safe from every other Virtual Environment.
Deactivate a Virtual Environment
You can deactivate a virtual environment by typing
deactivate
in your shell.